public void TestRunResume() { /* Stopped simulation can be resumed. */ var env = new Environment(); var events = new List<Event>() { env.Timeout(TimeSpan.FromMinutes(5)), env.Timeout(TimeSpan.FromMinutes(10)), env.Timeout(TimeSpan.FromMinutes(15)), env.Timeout(TimeSpan.FromMinutes(20)) }; Assert.AreEqual(env.Now, new DateTime(1970, 1, 1)); Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 5, 0)); Assert.IsFalse(events.Any(x => x.IsProcessed)); env.Run(TimeSpan.FromMinutes(10)); Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 10, 0)); Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 10, 0)); Assert.IsTrue(events[0].IsProcessed); Assert.IsFalse(events[1].IsProcessed); Assert.IsFalse(events[2].IsProcessed); env.Run(TimeSpan.FromMinutes(5)); Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 15, 0)); Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 15, 0)); Assert.IsTrue(events[0].IsProcessed); Assert.IsTrue(events[1].IsProcessed); Assert.IsFalse(events[2].IsProcessed); env.Run(TimeSpan.FromMinutes(1)); Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 16, 0)); Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 20, 0)); Assert.IsTrue(events[0].IsProcessed); Assert.IsTrue(events[1].IsProcessed); Assert.IsTrue(events[2].IsProcessed); env.Run(); Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 20, 0)); Assert.AreEqual(env.Peek(), DateTime.MaxValue); }
public void TestTarget() { var start = new DateTime(1970, 1, 1, 0, 0, 0); var delay = TimeSpan.FromSeconds(5); var env = new Environment(start); var @event = env.Timeout(delay); var proc = env.Process(TargetPem(env, @event)); while (env.Peek() < start + delay) { env.Step(); } Assert.AreEqual(proc.Target, @event); proc.Interrupt(); }