def test_tick_with_arbitrary_increment(self): stime.reset() stime.tick(5.9) stime.tick(6.1) self.assertEqual( stime.time(), 12.0, "expected time to be sum of increments after multiple ticks")
def test_timer_does_not_ring_before_set_time(self): # create a new timer using stime as a time source cooking_timer = Timer(time_source=stime) cooking_timer.set_alarm( 1561120200) # Unix timestamp for 21 June 2019 around noon stime.reset(1561120199) # a second before alarm time is_ringing = cooking_timer.is_ringing( ) # calls stime.time() because it is the timer time_source self.assertEqual(is_ringing, False, "expected the timer NOT to ring before alarm time")
def test_timer_rings_at_set_time(self): # create a new timer using stime as a time source cooking_timer = Timer(time_source=stime) cooking_timer.set_alarm( 1561120200) # Unix timestamp for 21 June 2019 around noon stime.reset(1561120200) # exactly alarm time is_ringing = cooking_timer.is_ringing( ) # calls stime.time() because it is the timer time_source self.assertEqual(is_ringing, True, "expected the timer to ring at alarm time")
def test_timer_rings_for_five_seconds(self): # create a new timer using stime as a time source cooking_timer = Timer(time_source=stime) cooking_timer.set_alarm( 1561120200) # Unix timestamp for 21 June 2019 around noon stime.reset(1561120205) # 5 seconds after alarm time is_ringing = cooking_timer.is_ringing( ) # calls stime.time() because it is the timer time_source self.assertEqual( is_ringing, True, "expected the timer to be ringing 5 seconds after alarm time") stime.tick() # add 1 more second is_ringing = cooking_timer.is_ringing( ) # calls stime.time() because it is the timer time_source self.assertEqual( is_ringing, False, "expected the timer NOT to be ringing 6 seconds after alarm time")
def test_reset_defaults_to_zero(self): stime.reset() self.assertEqual(stime.time(), 0.0, "expected time to be 0.0 after being reset")
def test_monotonic_is_alias_of_time(self): stime.reset(0.1) stime.tick() stime.tick(4) self.assertEqual(stime.monotonic(), stime.time(), "expected monotonic() to be an alias of time()")
def test_tick_with_arbitrary_increment(self): stime.reset() stime.tick(6.3) self.assertEqual( stime.time(), 6.3, "expected time to be 6.3 after ticking with 6.3 increment")
def test_tick_defaults_to_one_second(self): stime.reset() stime.tick() self.assertEqual(stime.time(), 1.0, "expected time to be 1.0 after one tick")
def test_reset_to_arbitrary_value(self): stime.reset(4.7) self.assertEqual( stime.time(), 4.7, "expected time to be 4.7 after being reset to that value")