Пример #1
0
        public void CanComplete_Various_ReturnsFalseUntilWaitTimeElapsed()
        {
            using (var context = new SimulationContext()){
                long waitPeriods = 10;
                var  instruction = new WaitInstruction(waitPeriods);

                bool canComplete = false;
                long?nextTimePeriodCheck;

                for (int i = 1; i < waitPeriods; i++)
                {
                    context.MoveToTimePeriod(i);

                    canComplete = instruction.CanComplete(context, out nextTimePeriodCheck);
                    Assert.IsFalse(canComplete);
                    Assert.AreEqual(waitPeriods, nextTimePeriodCheck);
                }

                context.MoveToTimePeriod(waitPeriods);
                canComplete = instruction.CanComplete(context, out nextTimePeriodCheck);
                Assert.IsTrue(canComplete);
            }
        }
        public void Process_EndConditionSpecified_EndConditionMetAtExpectedTime()
        {
            using (var context = new SimulationContext()){
                var waitInstruction1 = new WaitInstruction(2);
                var waitInstruction2 = new WaitInstruction(4);
                var waitInstruction3 = new WaitInstruction(4);

                var process = new InstructionListTestProcess(context, new List <InstructionBase>()
                {
                    waitInstruction1, waitInstruction2, waitInstruction3
                });
                var endTrigger = new SimulationEndTrigger(context, () => context.TimePeriod >= 5);

                var simulator = new Simulator(context);

                simulator.Simulate();

                Assert.AreEqual(6, context.TimePeriod);

                // the simulation should have ended at th expected time
                Assert.IsTrue(process.SimulationState.IsActive);
            }
        }
Пример #3
0
 public virtual void VisitWaitInstruction(WaitInstruction instruction)
 {
     DefaultVisitInstruction(instruction);
 }