Пример #1
0
def test_accelerate_race_car_multiple_times_when_nitro_available_and_update_current_speed(
):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=100,
                       acceleration=15,
                       tyre_friction=15)
    current_speed_value = 85
    race_car.start_engine()
    race_car.accelerate()
    race_car.accelerate()
    race_car.accelerate()
    race_car.accelerate()
    race_car.accelerate()
    race_car.apply_brakes()
    race_car.apply_brakes()
    race_car.apply_brakes()

    # Act
    race_car.accelerate()
    race_car.accelerate()
    race_car.accelerate()

    # Assert
    assert race_car.current_speed == current_speed_value
Пример #2
0
def test_accelerate_racecar_with_minimal_values_returns_current_speed():
    # Arrange
    racecar = RaceCar(color="Red", max_speed=1, acceleration=1, tyre_friction=1)
    racecar.start_engine()

    # Act
    racecar.accelerate()

    # Assert
    assert racecar.current_speed == 1
Пример #3
0
def test_apply_breake_racecar_current_equals_to_half_max_speed_returns_nitro_zero():
    # Arrange
    racecar = RaceCar(color="Red", max_speed=30, acceleration=15, tyre_friction=7)
    racecar.start_engine()
    racecar.accelerate()

    # Act
    racecar.apply_brakes()

    # Assert
    assert racecar.nitro == 0
Пример #4
0
def test_accelerate_racecar_returns_current_speed(
        max_speed, acceleration, tyre_friction, current_speed):
    # Arrange
    racecar = RaceCar(color="Red", max_speed=max_speed,
                      acceleration=acceleration, tyre_friction=tyre_friction)
    racecar.start_engine()

    # Act
    racecar.accelerate()

    # Assert
    assert racecar.current_speed == current_speed
Пример #5
0
def test_accelerate_racecar_more_than_max_limit_without_nitro_returns_current_speed():
    # Arrange
    racecar = RaceCar(color="Red", max_speed=25, acceleration=10, tyre_friction=7)
    racecar.start_engine()
    racecar.accelerate()
    racecar.accelerate()

    # Act
    racecar.accelerate()

    # Assert
    assert racecar.current_speed == 25
Пример #6
0
def test_accelerate_racecar_with_different_acceleration():
    # Arrange
    racecar = RaceCar(color="Red", max_speed=50, acceleration=10,
                      tyre_friction=3)
    current_speed = 30
    racecar.start_engine()

    # Act
    racecar.accelerate()
    racecar.accelerate()
    racecar.accelerate()

    # Assert
    assert racecar.current_speed == current_speed
Пример #7
0
def test_apply_brakes_to_race_car_and_update_current_speed():

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=100,
                       acceleration=10,
                       tyre_friction=10)
    current_speed_value = 0
    race_car.start_engine()
    race_car.accelerate()

    # Act
    race_car.apply_brakes()

    # Assert
    assert race_car.current_speed == current_speed_value
Пример #8
0
def test_accelerate_race_car_when_engine_stoped_and_return_start_engine_to_accelerate(
        capfd):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=20,
                       acceleration=10,
                       tyre_friction=5)
    start_engine_to_accelerate = "Start the engine to accelerate\n"

    # Act
    race_car.accelerate()
    output = capfd.readouterr()

    # Assert
    assert output.out == start_engine_to_accelerate
Пример #9
0
def test_accelerate_race_car_when_nitro_not_available_and_update_current_speed(
):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=20,
                       acceleration=10,
                       tyre_friction=5)
    current_speed_value = 10
    race_car.start_engine()

    # Act
    race_car.accelerate()

    # Assert
    assert race_car.current_speed == current_speed_value
Пример #10
0
def test_apply_brakes_when_race_car_current_speed_is_more_than_tyre_friction_and_update_current_speed(
):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=4,
                       acceleration=4,
                       tyre_friction=3)
    current_speed_value = 1
    race_car.start_engine()
    race_car.accelerate()

    # Act
    race_car.apply_brakes()

    # Assert
    assert race_car.current_speed == current_speed_value
Пример #11
0
def test_apply_brakes_to_race_car_when_current_speed_not_more_than_half_the_max_speed_and_nitro_value(
):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=100,
                       acceleration=20,
                       tyre_friction=10)
    current_speed_value = 0
    race_car.start_engine()
    race_car.accelerate()
    race_car.accelerate()
    nitro_value = 0

    # Act
    race_car.apply_brakes()

    # Assert
    assert race_car.nitro == nitro_value
Пример #12
0
def test_accelerate_race_car_when_current_speed_reaches_maximum_and_update_current_speed(
):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=30,
                       acceleration=10,
                       tyre_friction=5)
    current_speed_value = 30
    race_car.start_engine()

    # Act
    race_car.accelerate()
    race_car.accelerate()
    race_car.accelerate()
    race_car.accelerate()

    # Assert
    assert race_car.current_speed == current_speed_value
Пример #13
0
def test_apply_break_when_current_speed_is_less_than_max_speed_returns_current_speed():
    # Arrange
    racecar1 = RaceCar(color="None", max_speed=100, acceleration=10, tyre_friction=1)
    racecar1.start_engine()
    racecar1.accelerate()
    racecar1.accelerate()
    racecar1.accelerate()
    racecar1.accelerate()
    racecar1.accelerate()
    racecar1.accelerate()
    racecar1.accelerate()
    racecar1.accelerate()
    racecar1.apply_brakes()

    # Act
    racecar1.accelerate()

    # Assert
    assert racecar1.current_speed == 92
Пример #14
0
def test_accelerate_race_car_when_nitro_available_and_update_current_speed():
    import math
    # Arrange
    color = 'Red'
    max_speed = 20
    acceleration = 6
    tyre_friction = 3
    race_car = RaceCar(color=color,
                       max_speed=max_speed,
                       acceleration=acceleration,
                       tyre_friction=tyre_friction)
    current_speed_value = math.ceil((2 * acceleration - tyre_friction) +
                                    (0.3) * acceleration + acceleration)
    race_car.start_engine()
    race_car.accelerate()
    race_car.accelerate()
    race_car.apply_brakes()

    # Act
    race_car.accelerate()

    # Assert
    assert race_car.current_speed == current_speed_value
Пример #15
0
def test_accelerate_racecar_more_than_max_speed_returns_current_speed_equal_to_max_speed():
    # Arrange
    racecar = RaceCar(color="Red", max_speed=50, acceleration=10,
                      tyre_friction=3)
    current_speed = 50
    racecar.start_engine()

    # Act
    racecar.accelerate()
    racecar.accelerate()
    racecar.accelerate()
    racecar.accelerate()
    racecar.accelerate()
    racecar.accelerate()
    racecar.accelerate()

    # Assert
    assert racecar.current_speed == current_speed