public void Process_EndConditionSpecified_EndConditionMetAtExpectedTime()
        {
            using(var context = new SimulationContext(isDefaultContextForProcess: true)){

                var waitInstruction1 = new WaitInstruction(2);
                var waitInstruction2 = new WaitInstruction(4);
                var waitInstruction3 = new WaitInstruction(4);

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

                var simulator = new Simulator();

                simulator.Simulate();

                Assert.AreEqual(6, context.TimePeriod);

                // the simulation should have ended at th expected time
                Assert.IsTrue(process.SimulationState.IsActive);
            }
        }
Ejemplo n.º 2
0
        public void CanComplete_Various_ReturnsFalseUntilWaitTimeElapsed()
        {
            using (var context = new SimulationContext(isDefaultContextForProcess:true)){

                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);
            }
        }