Beispiel #1
0
 public void ShouldBeDescending()
 {
     using(var machine = new Machine())
     {
         var timer = new LimitTimer(machine, 100, 100000, Direction.Descending, true);
         var manualClockSource = new ManualClockSource();
         machine.SetClockSource(manualClockSource);
         machine.Start();
         var oldValue = timer.Limit;
         for(var i = 0; i < 100; i++)
         {
             manualClockSource.AdvanceBySeconds(1);
             var value = timer.Value;
             Assert.Less(value, oldValue, "Timer is not monotonic.");
             oldValue = value;
         }
         machine.Pause();
     }
 }
Beispiel #2
0
 public void ShouldNotExceedLimitAscending()
 {
     var limit = 100;
     using(var machine = new Machine())
     {
         var timer = new LimitTimer(machine, 1, limit, Direction.Ascending, true);
         var manualClockSource = new ManualClockSource();
         machine.SetClockSource(manualClockSource);
         machine.Start();
         manualClockSource.AdvanceBySeconds(limit - 1);
         for(var i = 0; i < 3; ++i)
         {
             var value = timer.Value;
             Assert.LessOrEqual(value, limit, "Timer exceeded given limit.");
             Assert.GreaterOrEqual(value, 0, "Timer returned negative value.");
             manualClockSource.AdvanceBySeconds(1);
         }
         Thread.Sleep(7);
         machine.Pause();
     }
 }
Beispiel #3
0
 public void ShouldFireAlarmWhenInterruptsAreEnabled()
 {
     using(var machine = new Machine())
     {
         var timer = new LimitTimer(machine, 1, 10, Direction.Descending, true);
         var manualClockSource = new ManualClockSource();
         machine.SetClockSource(manualClockSource);
         timer.EventEnabled = true;
         var ticked = false;
         timer.LimitReached += () => ticked = true;
         machine.Start();
         // var val =timer.Value;
         manualClockSource.AdvanceBySeconds(110);
         Assert.IsTrue(ticked);
     }
 }
Beispiel #4
0
 public void ShouldSwitchDirectionProperly()
 {
     using(var machine = new Machine())
     {
         var timer = new LimitTimer(machine, 100, 100000, Direction.Ascending, true);
         var manualClockSource = new ManualClockSource();
         machine.SetClockSource(manualClockSource);
         timer.EventEnabled = true;
         var ticked = false;
         timer.LimitReached += () => ticked = true;
         machine.Start();
         manualClockSource.AdvanceBySeconds(2);
         timer.Direction = Direction.Descending; // and then change the direction
         manualClockSource.AdvanceBySeconds(2);
         Assert.IsTrue(ticked);
       
     }
 }