def test_travel_down(self): travelcalculator = TravelCalculator(64, 128) travelcalculator.set_position(120) travelcalculator.time_set_from_outside = 1000 travelcalculator.start_travel(100) # time not changed, still at beginning self.assertEqual(travelcalculator.current_position(), 120) self.assertFalse(travelcalculator.position_reached()) travelcalculator.time_set_from_outside = 1000 + 2 self.assertEqual(travelcalculator.current_position(), 116) self.assertFalse(travelcalculator.position_reached()) travelcalculator.time_set_from_outside = 1000 + 4 self.assertEqual(travelcalculator.current_position(), 112) self.assertFalse(travelcalculator.position_reached()) travelcalculator.time_set_from_outside = 1000 + 8 self.assertEqual(travelcalculator.current_position(), 104) self.assertFalse(travelcalculator.position_reached()) travelcalculator.time_set_from_outside = 1000 + 10 # position reached self.assertEqual(travelcalculator.current_position(), 100) self.assertTrue(travelcalculator.position_reached()) travelcalculator.time_set_from_outside = 1000 + 20 self.assertEqual(travelcalculator.current_position(), 100) self.assertTrue(travelcalculator.position_reached())
def test_stop(self): travelcalculator = TravelCalculator(64, 128) travelcalculator.set_position(120) travelcalculator.time_set_from_outside = 1000 travelcalculator.start_travel(100) # stop aftert two seconds travelcalculator.time_set_from_outside = 1000 + 2 travelcalculator.stop() travelcalculator.time_set_from_outside = 1000 + 4 self.assertEqual(travelcalculator.current_position(), 116) self.assertTrue(travelcalculator.position_reached()) # restart after 1 second travelcalculator.time_set_from_outside = 1000 + 3 travelcalculator.start_travel(130) # running up for 3 seconds travelcalculator.time_set_from_outside = 1000 + 6 self.assertEqual(travelcalculator.current_position(), 128) self.assertFalse(travelcalculator.position_reached()) travelcalculator.time_set_from_outside = 1000 + 7 self.assertEqual(travelcalculator.current_position(), 130) self.assertTrue(travelcalculator.position_reached())
def test_change_direction(self): travelcalculator = TravelCalculator(64, 128) travelcalculator.set_position(120) travelcalculator.time_set_from_outside = 1000 travelcalculator.start_travel(100) # change direction after two seconds travelcalculator.time_set_from_outside = 1000 + 2 travelcalculator.start_travel(130) self.assertEqual(travelcalculator.current_position(), 116) self.assertFalse(travelcalculator.position_reached()) travelcalculator.time_set_from_outside = 1000 + 4 self.assertEqual(travelcalculator.current_position(), 124) self.assertFalse(travelcalculator.position_reached()) travelcalculator.time_set_from_outside = 1000 + 6 self.assertEqual(travelcalculator.current_position(), 130) self.assertTrue(travelcalculator.position_reached())
def test_set_position_after_travel(self): travelcalculator = TravelCalculator(64, 128) travelcalculator.start_travel(100) travelcalculator.set_position(128) self.assertTrue(travelcalculator.position_reached()) self.assertEqual(travelcalculator.current_position(), 128)