예제 #1
0
    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))
예제 #2
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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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]))
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
    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)