def test_constructor(self): """ Test default value in constructor """ zr = roadbook.Zr() # pylint: disable=invalid-name now = datetime.datetime.now() self.assertEqual(0, len(zr._speeds)) self.assertLess(zr.start_time - now, datetime.timedelta(0, 1)) self.assertEqual(0, zr._number) zr = roadbook.Zr(5) # pylint: disable=invalid-name self.assertEqual(5, zr._number)
def test_get_distance(self): """ Test method to get distance """ cad = cadenceur.Cadenceur() zr = roadbook.Zr() # pylint: disable=invalid-name zr.start_time = datetime.datetime(2020, 1, 11, 14, 00, 00) zr.add_speed(roadbook.Speed(0, 10)) zr.add_speed(roadbook.Speed(1000, 20)) zr.add_speed(roadbook.Speed(2000, 30)) # After 50s -> d = 500 # After 100s -> d = 1000 # After 125s -> d = 1500 # After 150s -> d = 2000 # After 250s -> d = 5000 cad.enter_zr(zr) self.assertEqual( 0, cad.get_distance(datetime.datetime(2020, 1, 11, 13, 59, 59))) self.assertEqual( 0, cad.get_distance(datetime.datetime(2020, 1, 11, 14, 00, 00))) self.assertEqual( 500, cad.get_distance(datetime.datetime(2020, 1, 11, 14, 00, 50))) self.assertEqual( 1000, cad.get_distance(datetime.datetime(2020, 1, 11, 14, 1, 40))) self.assertEqual( 1500, cad.get_distance(datetime.datetime(2020, 1, 11, 14, 2, 5))) self.assertEqual( 2000, cad.get_distance(datetime.datetime(2020, 1, 11, 14, 2, 30))) self.assertEqual( 5000, cad.get_distance(datetime.datetime(2020, 1, 11, 14, 4, 10)))
def test_enter_zr(self): """ Test to enter zr in cadenceur """ cad = cadenceur.Cadenceur() zr = roadbook.Zr() # pylint: disable=invalid-name zr.start_time = datetime.datetime(2020, 1, 11, 13, 37, 42) zr.add_speed(roadbook.Speed(0, 10)) zr.add_speed(roadbook.Speed(1000, 20)) zr.add_speed(roadbook.Speed(2000, 30)) cad.enter_zr(zr) self.assertEqual(zr, cad._zr) self.assertEqual(zr.start_time, cad._start_time)
def test_zr_start_time(self): """ Test zr set start time """ zr = roadbook.Zr() # pylint: disable=invalid-name with self.assertRaises(ValueError): zr.start_time = "test" with self.assertRaises(ValueError): zr.start_time = 3 now = datetime.datetime.now() zr.start_time = now self.assertEqual(now, zr.start_time)
def test_zr_number(self): """ Test zr number """ zr = roadbook.Zr() # pylint: disable=invalid-name with self.assertRaises(ValueError): zr.number = "test" with self.assertRaises(ValueError): zr.number = 3.5 with self.assertRaises(ValueError): zr.number = -5 zr.number = 12 self.assertEqual(zr.number, 12)
def test_zr_manage_speed(self): """ Test to add, delete, get speed """ zr = roadbook.Zr() # pylint: disable=invalid-name self.assertEqual(0, len(zr._speeds)) with self.assertRaises(ValueError): zr.add_speed("test") speed1 = roadbook.Speed(0.5, 42.5) zr.add_speed(speed1) self.assertEqual(1, len(zr._speeds)) self.assertTrue(speed1 in zr._speeds) with self.assertRaises(ValueError): zr.add_speed(speed1) zr.add_speed(1.42, 43.8) self.assertEqual(2, len(zr._speeds)) speed3 = roadbook.Speed(2.254, 12.953) zr.add_speed(speed3) self.assertEqual(3, len(zr._speeds)) self.assertTrue(speed3 in zr._speeds) self.assertEqual(speed1, zr.get_speed(0.5)) self.assertEqual(speed1, zr.get_speed(0.49999, roadbook.ZrGetter.NEXT)) self.assertEqual(speed1, zr.get_speed(0.50001, roadbook.ZrGetter.PREV)) self.assertEqual(speed3, zr.get_speed(2.254)) self.assertEqual(speed3, zr.get_speed(2.253, roadbook.ZrGetter.NEXT)) self.assertEqual(speed3, zr.get_speed(2.255, roadbook.ZrGetter.PREV)) zr.delete_speed(1.42) self.assertEqual(2, len(zr._speeds)) self.assertEqual(speed3, zr.get_speed(1, roadbook.ZrGetter.NEXT)) self.assertEqual(speed1, zr.get_speed(2, roadbook.ZrGetter.PREV)) zr.delete_speed(roadbook.Speed(2.254)) self.assertEqual(1, len(zr._speeds)) self.assertEqual(None, zr.get_speed(1, roadbook.ZrGetter.NEXT)) self.assertEqual(speed1, zr.get_speed(5, roadbook.ZrGetter.PREV))