public void TestAndConditionBlocked() { var env = new Environment(); env.Process(TestAndConditionBlockedProcess(env)); env.RunD(5); Assert.AreEqual(5, env.NowD); }
public void TestEventQueueEmptyDApi() { /*The simulation should stop if there are no more events, that means, no more active process.*/ var log = new List<string>(); var env = new Environment(defaultStep: TimeSpan.FromMinutes(1)); env.Process(AProcess(env, log)); env.RunD(10); Assert.IsTrue(log.SequenceEqual(new[] { "00", "01" })); }
public void TestRunNegativeUntilDApi() { /*Test passing a negative time to run.*/ var env = new Environment(defaultStep: TimeSpan.FromMinutes(1)); var errorThrown = false; try { env.RunD(-1); } catch (InvalidOperationException) { errorThrown = true; } Assert.IsTrue(errorThrown); }
public void TestRunResumeDApi() { /* Stopped simulation can be resumed. */ var env = new Environment(defaultStep: TimeSpan.FromMinutes(1)); var events = new List<Event>() { env.TimeoutD(5), env.TimeoutD(10), env.TimeoutD(15), env.TimeoutD(20) }; Assert.AreEqual(env.NowD, 0); Assert.AreEqual(env.PeekD(), 5); Assert.IsFalse(events.Any(x => x.IsProcessed)); env.RunD(10); Assert.AreEqual(env.NowD, 10); Assert.AreEqual(env.PeekD(), 10); Assert.IsTrue(events[0].IsProcessed); Assert.IsFalse(events[1].IsProcessed); Assert.IsFalse(events[2].IsProcessed); env.RunD(5); Assert.AreEqual(env.NowD, 15); Assert.AreEqual(env.PeekD(), 15); Assert.IsTrue(events[0].IsProcessed); Assert.IsTrue(events[1].IsProcessed); Assert.IsFalse(events[2].IsProcessed); env.RunD(1); Assert.AreEqual(env.NowD, 16); Assert.AreEqual(env.PeekD(), 20); Assert.IsTrue(events[0].IsProcessed); Assert.IsTrue(events[1].IsProcessed); Assert.IsTrue(events[2].IsProcessed); env.RunD(); Assert.AreEqual(env.NowD, 20); Assert.AreEqual(env.PeekD(), double.MaxValue); }
public void TestContinuousStatisticsSimple() { var env = new Environment(); var times = new double[] { 0, 1, 1, 1, 1, 1 }; var values = new double[] { 6, 2, 3, 5, -1, -4 }; var stat = new ContinuousStatistics(env); foreach (var v in times.Zip(values, Tuple.Create)) { if (v.Item1 > 0) env.RunD(v.Item1); stat.Update(v.Item2); } Assert.AreEqual(-4, stat.Min); Assert.AreEqual(6, stat.Max); Assert.AreEqual(3, stat.Mean, 1e-12); Assert.AreEqual(6, stat.Variance, 1e-12); Assert.AreEqual(15, stat.Area); }
public void TestContinuousStatisticsComplex2() { var env = new Environment(); var times = new double[] { 1, 1, 1, 2, 0, 0, 4, 7, 4 }; var values = new double[] { 3, -2, 5, 6, -4, 1, 0, -2, 3 }; var stat = new ContinuousStatistics(env); foreach (var v in times.Zip(values, Tuple.Create)) { if (v.Item1 > 0) env.RunD(v.Item1); stat.Update(v.Item2); } Assert.AreEqual(-4, stat.Min); Assert.AreEqual(6, stat.Max); Assert.AreEqual(0.3684210526315789, stat.Mean, 1e-12); Assert.AreEqual(4.232686980609418, stat.Variance, 1e-12); Assert.AreEqual(7, stat.Area); }
public void TestRunUntilValueDApi() { /* Anything that can be converted to a float is a valid until value. */ var env = new Environment(defaultStep: TimeSpan.FromMinutes(1)); env.RunD(100); Assert.AreEqual(env.NowD, 100); }