[TestMethod]
public async Task DayVolumeAga3()
{
// test the volume accumulation with constant inputs
TestScript script = GetBaseConfig();
script.RunTime = new TimeSpan(62, 0, 0);
script.StartTime = DateTime.UtcNow;
int secondsOffset = 60 - script.StartTime.Second;
int minuteOffset = 59 - script.StartTime.Minute; // time to the end of the current hour. minute offset may be 0!
// default contract hour is 8 AM tomorrow
DateTime contractTs = new DateTime(script.StartTime.Year, script.StartTime.Month, script.StartTime.Day, 8, 0, 0).AddDays(1.0d);
// totalOffset is the time to the next contract day in seconds
int totalOffset = Convert.ToInt32(Math.Truncate(contractTs.Subtract(script.StartTime).TotalSeconds)) + 1;
if(totalOffset > 86400)
{
totalOffset -= 86400;
}
DateTime contractTs_ = script.StartTime.AddSeconds(totalOffset);
Console.WriteLine($"Time is {script.StartTime}, seconds offset is {secondsOffset}, minute offset is {minuteOffset}, total offset is {totalOffset}, contract Ts {contractTs_}");
// user defined values. These have to happen after the app is initialized
script.Changes.Add(1, new List());
script.Changes[1].Add(new TestChange((int)GasFlow_001_005.ParametersEnum.spTag, 2818.09d)); // kPa
script.Changes[1].Add(new TestChange((int)GasFlow_001_005.ParametersEnum.dpTag, 102.0d)); // millibar
script.Changes[1].Add(new TestChange((int)GasFlow_001_005.ParametersEnum.tempTag, 57.0d)); // C
script.Changes[1].Add(new TestChange((int)AppBase_v1.AppBaseParameterIds.logLevel, (object)2));
// 2.747665757001002
double q = 2.7476657570010006d; // e3m3/day
double volMin = q / 1440.0d; // e3m3/minute
double volSecond = q / 86400.0d; // e3m3/second
double flowTime = 0.0d;
double volBase = 0.0d;
Random r = new Random();
int totalElapsedTime = 0;
int dayCount = 0;
// check flow every so often
while(true)
{
// get a time to check flow at
// make sure that we're at least 3
// seconds in
totalElapsedTime += r.Next(3, 3700);
if (totalElapsedTime < totalOffset)
{
// we are in the initial, partial day
// subtract one second because the inputs are not
// valid to start
flowTime = totalElapsedTime - 1;
volBase = flowTime * volSecond;
// assert that the values from the app match our calculated values
if (script.Asserts.ContainsKey(totalElapsedTime) == false)
{
script.Asserts.Add(totalElapsedTime, new List());
}
script.Asserts[totalElapsedTime].Add(new TestAssert(AssertTypes.areEqual, (int)GasFlow_001_005.ParametersEnum.dyFlowTime, flowTime));
script.Asserts[totalElapsedTime].Add(new TestAssert(AssertTypes.areEqual, (int)GasFlow_001_005.ParametersEnum.dyVolBase, volBase, 0.0001));
}
else
{
// calculate volume and flow time based on elapsed time since start of test
dayCount = (totalElapsedTime - totalOffset) / 86400;
flowTime = (totalElapsedTime - totalOffset) - (dayCount * 86400);
volBase = flowTime * volSecond;
if (script.Asserts.ContainsKey(totalElapsedTime) == false)
{
script.Asserts.Add(totalElapsedTime, new List());
}
// verify that the calculate values line up with the values from the app
script.Asserts[totalElapsedTime].Add(new TestAssert(AssertTypes.areEqual, (int)GasFlow_001_005.ParametersEnum.dyFlowTime, flowTime));
script.Asserts[totalElapsedTime].Add(new TestAssert(AssertTypes.areEqual, (int)GasFlow_001_005.ParametersEnum.dyVolBase, volBase, 0.001));
}
// stop when we've exceeded the script run time
if(totalElapsedTime > script.RunTime.TotalSeconds)
{
break;
}
}
// check volume at after a full contract day. The test runs for at least 1 partial contract day and 1 full contract day.
if (script.Asserts.ContainsKey(totalOffset + 86400) == false)
{
script.Asserts.Add(totalOffset + 86400, new List());
}
script.Asserts[totalOffset + 86400].Add(new TestAssert(AssertTypes.areEqual, (int)GasFlow_001_005.ParametersEnum.dyVolBase, q, 0.000000001));
if (script.Prints.ContainsKey(totalOffset + 86400) == false)
{
script.Prints.Add(totalOffset + 86400, new List());
}
script.Prints[totalOffset + 86400].Add(new TestPrint((int)GasFlow_001_005.ParametersEnum.dyVolBase));
script.Prints[totalOffset + 86400].Add(new TestPrint((int)GasFlow_001_005.ParametersEnum.dyFlowTime));
AppRunBase_ runtime = await AppSpecificTestHelpers.ExecuteScript(script);
}