def test_method_add_sector_time_invalidate_earlier_lap(self): instance = Driver(sentinel.index, sentinel.name) sectors = [ (sentinel.time_l1s1, 1, False), (sentinel.time_l1s2, 2, False), (sentinel.time_l1s2, 2, True), (sentinel.time_l1s3, 3, True), (sentinel.time_l2s1, 1, False), (sentinel.time_l2s2, 2, False), (sentinel.time_l2s3, 3, False) ] for time, sector, invalid in sectors: with patch('replayenhancer.RaceData.SectorTime', autospec=True) as SectorTime: sector_time = SectorTime(time, sector, invalid) sector_time.sector = sector sector_time.time = time sector_time.invalid = invalid instance.add_sector_time(sector_time) # First lap should be invalid. result = [ sector_time.invalid for sector_time in instance.sector_times[:3] ] self.assertTrue(any(result)) # Second lap should be invalid. result = [ sector_time.invalid for sector_time in instance.sector_times[3:] ] self.assertTrue(not all(result))
def test_method_add_sector_time_first(self, sector_time): instance = Driver(sentinel.index, sentinel.name) sector_time.time = sentinel.time sector_time.sector = 1 sector_time.invalid = False instance.add_sector_time(sector_time) self.assertEqual(len(instance.sector_times), 1)
def test_method_add_sector_time_no_previous(self, sector_time): instance = Driver(sentinel.index, sentinel.name) sector_time.time = -123.0 sector_time.sector = 1 sector_time.invalid = False instance.add_sector_time(sector_time) self.assertEqual(len(instance.sector_times), 0)
def test_property_best_lap_all_invalid(self): instance = Driver(sentinel.index, sentinel.name) test_data = [(30.000, 1, False), (45.000, 2, False), (40.000, 3, True), (35.000, 1, True), (43.000, 2, False), (39.000, 3, False)] for data in test_data: with patch('replayenhancer.RaceData.SectorTime', autospec=True) as SectorTime: sector_time = SectorTime(*data) sector_time.time = data[0] sector_time.sector = data[1] sector_time.invalid = data[2] instance.add_sector_time(sector_time) self.assertIsNone(instance.best_lap)
def test_property_race_time(self): instance = Driver(sentinel.index, sentinel.name) times = [5, 5, 5, 10, 10, 10] for sector, time in enumerate(times, 1): with patch('replayenhancer.RaceData.SectorTime', autospec=True) as SectorTime: sector_time = SectorTime(time, sector % 3, False) sector_time.sector = sector % 3 sector_time.time = time sector_time.invalid = False instance.add_sector_time(sector_time) expected_result = 45 self.assertEqual(instance.race_time, expected_result)
def test_property_laps_complete(self): instance = Driver(sentinel.index, sentinel.name) times = [ sentinel.time_1, sentinel.time_2, sentinel.time_3, sentinel.time_4, sentinel.time_5, sentinel.time_6 ] for sector, time in enumerate(times, 1): with patch('replayenhancer.RaceData.SectorTime', autospec=True) as SectorTime: sector_time = SectorTime(time, sector % 3, False) sector_time.sector = sector % 3 sector_time.time = time sector_time.invalid = False instance.add_sector_time(sector_time) expected_result = 2 self.assertEqual(instance.laps_complete, expected_result)
def test_property_last_lap_invalid_previous_invalid(self): instance = Driver(sentinel.index, sentinel.name) sectors = [ (sentinel.time_l1s1, 1, False), (sentinel.time_l1s2, 2, False), (sentinel.time_l1s2, 2, True), (sentinel.time_l1s3, 3, True), (sentinel.time_l2s1, 1, False), (sentinel.time_l2s2, 2, False), (sentinel.time_l2s3, 3, False) ] for time, sector, invalid in sectors: with patch('replayenhancer.RaceData.SectorTime', autospec=True) as SectorTime: sector_time = SectorTime(time, sector, invalid) sector_time.sector = sector sector_time.time = time sector_time.invalid = invalid instance.add_sector_time(sector_time) self.assertFalse(instance.last_lap_invalid)
def test_property_sector_times_values(self): instance = Driver(sentinel.index, sentinel.name) times = [ sentinel.time_1, sentinel.time_2, sentinel.time_3, sentinel.time_4, sentinel.time_5, sentinel.time_6 ] expected_value = list() for sector, time in enumerate(times, 1): with patch('replayenhancer.RaceData.SectorTime', autospec=True) as SectorTime: sector_time = SectorTime(time, sector % 3, False) sector_time.sector = sector % 3 sector_time.time = time sector_time.invalid = False instance.add_sector_time(sector_time) expected_value.append(sector_time) self.assertListEqual(instance.sector_times, expected_value)
def test_method_add_sector_time_invalidate_first_lap(self): instance = Driver(sentinel.index, sentinel.name) sectors = [(sentinel.time_s1, 1, False), (sentinel.time_s2, 2, False), (sentinel.time_s2, 2, True), (sentinel.time_s3, 3, True)] for time, sector, invalid in sectors: with patch('replayenhancer.RaceData.SectorTime', autospec=True) as SectorTime: sector_time = SectorTime(time, sector, invalid) sector_time.sector = sector sector_time.time = time sector_time.invalid = invalid instance.add_sector_time(sector_time) self.assertEqual(len(instance.sector_times), 3) self.assertTrue( all([sector_time.invalid for sector_time in instance.sector_times]))
def test_property_best_lap_bad_first_sector(self): instance = Driver(sentinel.index, sentinel.name) test_data = [ (16.000, 3, False), (30.000, 1, False), (45.000, 2, False), (40.000, 3, False), (35.000, 1, False), (43.000, 2, False), (39.000, 3, False) ] expected_value = 115.000 for data in test_data: with patch('replayenhancer.RaceData.SectorTime', autospec=True) as SectorTime: sector_time = SectorTime(*data) sector_time.time = data[0] sector_time.sector = data[1] sector_time.invalid = data[2] instance.add_sector_time(sector_time) self.assertEqual(instance.best_lap, expected_value)
def test_property_sector_times(self): instance = Driver(sentinel.index, sentinel.name) expected_result = list self.assertIsInstance(instance.sector_times, expected_result)
def test_property_race_time_no_laps(self): instance = Driver(sentinel.index, sentinel.name) expected_result = 0.0 self.assertEqual(instance.race_time, expected_result)
def test_property_name_setter(self): instance = Driver(sentinel.index, sentinel.name) instance.name = sentinel.new_name expected_result = sentinel.new_name self.assertEqual(instance.name, expected_result)
def test_property_lap_times_empty(self): instance = Driver(sentinel.index, sentinel.name) expected_result = list() self.assertListEqual(instance.lap_times, expected_result)
def test_property_laps_complete_empty(self): instance = Driver(sentinel.index, sentinel.name) expected_result = 0 self.assertEqual(instance.laps_complete, expected_result)
def test_property_index_setter(self): instance = Driver(sentinel.index, sentinel.name) instance.index = sentinel.new_index expected_result = sentinel.new_index self.assertEqual(instance.index, expected_result)
def test_property_best_sector_3_default(self): instance = Driver(sentinel.index, sentinel.name) self.assertIsNone(instance.best_sector_3)
def test_property_last_lap_time_no_laps(self): instance = Driver(sentinel.index, sentinel.name) self.assertIsNone(instance.last_lap_time)
def test_init(self): instance = Driver(sentinel.index, sentinel.name) expected_result = Driver self.assertIsInstance(instance, expected_result)