Beispiel #1
0
def test_add_correct_lap_info():
    """
    If all lap infos are fine, our pilot's `lap` list should increase.
    """

    lap_1 = l.Lap(1, datetime.time(0, 1, 49, 209), 44.10)
    lap_2 = l.Lap(2, datetime.time(0, 2, 49, 209), 42.79)

    pilot = p.Pilot('011', 'G.MORAIS')
    pilot.add_lap_info(lap_1)

    assert len(pilot.lap) == 1

    pilot.add_lap_info(lap_2)

    assert len(pilot.lap) == 2
Beispiel #2
0
def test_lap_speed_type():
    """
    A lap speed should be a float, otherwise a TypeError should be raised
    """

    with pytest.raises(TypeError):
        l.Lap(1, datetime.time(0, 1, 0, 0), "44.4")
Beispiel #3
0
def test_lap_time_type():
    """
    A lap time should be a datetime.time, otherwise a TypeError should be raised
    """

    with pytest.raises(TypeError):
        l.Lap(1, "1:11:11", 44.4)
Beispiel #4
0
def test_lap_number_type():
    """
    A lap number should be a int, otherwise a TypeError should be raised
    """

    with pytest.raises(TypeError):
        l.Lap("number", datetime.time(0, 1, 0, 0), 44.4)
Beispiel #5
0
def test_lap_speed():
    """
    A lap speed can't be 0 or less. If this happens, a ValueError should be
    raised
    """

    with pytest.raises(ValueError):
        l.Lap(1, datetime.time(0, 1, 0, 0), -10.09)
Beispiel #6
0
def test_lap_number():
    """
    A lap number can't be 0 or less. If this happens, a ValueError should be
    raised
    """

    with pytest.raises(ValueError):
        l.Lap(-1, datetime.time(0, 1, 0, 0), 44.4)
Beispiel #7
0
def test_avg_speed():
    """
    Given n laps, the method should return the correct average speed.
    """

    lap_1 = l.Lap(1, datetime.time(0, 1, 49, 209), 44.10)
    lap_2 = l.Lap(2, datetime.time(0, 2, 26, 10), 42.79)
    lap_3 = l.Lap(3, datetime.time(0, 1, 20, 959), 47.12)
    lap_4 = l.Lap(4, datetime.time(0, 1, 34, 236), 46.99)

    pilot = p.Pilot('011', 'G.MORAIS')
    pilot.add_lap_info(lap_1)
    pilot.add_lap_info(lap_2)
    pilot.add_lap_info(lap_3)
    pilot.add_lap_info(lap_4)

    avg_speed = pilot.get_avg_speed()

    assert avg_speed == 45.25
Beispiel #8
0
def test_pilots_best_lap():
    """
    Given n laps, pilot.get_best_lap() should return the one finished in less
    time
    """
    lap_1 = l.Lap(1, datetime.time(0, 1, 49, 209), 44.10)
    lap_2 = l.Lap(2, datetime.time(0, 2, 26, 10), 42.79)
    lap_3 = l.Lap(3, datetime.time(0, 1, 20, 959), 47.12)
    lap_4 = l.Lap(4, datetime.time(0, 1, 34, 236), 46.99)

    pilot = p.Pilot('011', 'G.MORAIS')
    pilot.add_lap_info(lap_1)
    pilot.add_lap_info(lap_2)
    pilot.add_lap_info(lap_3)
    pilot.add_lap_info(lap_4)

    best_lap_idx, best_lap_time = pilot.get_best_lap()

    assert best_lap_time == lap_3.time
Beispiel #9
0
    def init_race(self):
        pilots = {}

        for lap_info in self.data:
            pilot_id, pilot_name = lap_info[1], lap_info[2]
            lap_hour, lap_number, lap_time, lap_speed = lap_info[0], lap_info[
                3], lap_info[4], lap_info[5]

            lap = l.Lap(lap_number, lap_time, lap_speed)

            if pilot_id in pilots:
                pilots[pilot_id].add_lap_info(lap)
            else:
                pilot = p.Pilot(pilot_id, pilot_name)
                pilot.add_lap_info(lap)

                pilots[pilot_id] = pilot

        self.update_podium(pilots)
        self.print_stats(pilots)

        return self.podium
Beispiel #10
0
def test_lap_creation():
    """
    With the correct parameters, no error should be raised
    """

    l.Lap(1, datetime.time(0, 1, 0, 0), 40.09)