コード例 #1
0
def test_create_race_car_object_instance_multiple_times_with_valid_details(
        color, max_speed, acceleration, tyre_friction):

    # Arrange

    # Act
    race_car_1 = RaceCar(color=color,
                         max_speed=max_speed,
                         acceleration=acceleration,
                         tyre_friction=tyre_friction)

    race_car_2 = RaceCar(color=color,
                         max_speed=max_speed,
                         acceleration=acceleration,
                         tyre_friction=tyre_friction)

    # Assert
    assert race_car_1.color == color
    assert race_car_1.max_speed == max_speed
    assert race_car_1.acceleration == acceleration
    assert race_car_1.tyre_friction == tyre_friction

    assert race_car_2.color == color
    assert race_car_2.max_speed == max_speed
    assert race_car_2.acceleration == acceleration
    assert race_car_2.tyre_friction == tyre_friction
コード例 #2
0
def test_accelerate_racecar_more_than_max_limit_with_nitro_returns_current_speed():
    # Arrange
    racecar = RaceCar(color="Red", max_speed=25, acceleration=10, tyre_friction=7)
    racecar.start_engine()
    racecar.accelerate()
    racecar.accelerate()
    racecar.apply_brakes()

    # Act
    racecar.accelerate()

    # Assert
    assert racecar.current_speed == 25
コード例 #3
0
def test_sound_horn_when_race_car_engine_stoped_and_return_start_engine_to_sound_horn(
        capfd):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=130,
                       acceleration=10,
                       tyre_friction=3)
    start_engine_to_sound = "Start the engine to sound_horn\n"

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

    # Assert
    assert output.out == start_engine_to_sound
コード例 #4
0
def car2():  # Our Fixture function
    from race_car import RaceCar
    car_obj = RaceCar(color="blue",
                      max_speed=50,
                      acceleration=20,
                      tyre_friction=4)
    return car_obj
コード例 #5
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
コード例 #6
0
def car():  # Our Fixture function
    from race_car import RaceCar
    car_obj = RaceCar(color="Red",
                      max_speed=30,
                      acceleration=10,
                      tyre_friction=3)
    return car_obj
コード例 #7
0
def test_invalid_max_speed_attr_for_race_car(color, max_speed,
                                             acceleration, tyre_friction):
    #arrange
    #act
    with pytest.raises(Exception) as err:
        assert RaceCar(color=color, max_speed=max_speed,
                       acceleration=acceleration, tyre_friction=tyre_friction)
    assert str(err.value) == "Invalid value for max_speed"
コード例 #8
0
def race_car():

    race_car_obj = RaceCar(color='Red',
                           max_speed=30,
                           acceleration=10,
                           tyre_friction=3)

    return race_car_obj
コード例 #9
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
コード例 #10
0
def test_apply_brakes_to_race_car_when_current_speed_more_than_half_the_max_speed_and_update_nitro(
):

    # 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()
    race_car.accelerate()
    nitro_value = 10

    # Act
    race_car.apply_brakes()

    # Assert
    assert race_car.nitro == nitro_value
コード例 #11
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
コード例 #12
0
def test_race_car_object_instance_create_and_engine_status():

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=130,
                       acceleration=10,
                       tyre_friction=3)
    engine_started = False

    # Act

    # Assert
    assert race_car.is_engine_started == engine_started
コード例 #13
0
def test_race_car_object_instance_create_and_nitro_status():

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=130,
                       acceleration=10,
                       tyre_friction=3)
    nitro_value = 0

    # Act

    # Assert
    assert race_car.nitro == nitro_value
コード例 #14
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
コード例 #15
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
コード例 #16
0
def test_create_race_car_object_with_invalid_acceleration_value_raise_error(
        color, max_speed, acceleration, tyre_friction):

    # Arrange
    invalid_acceleration = 'Invalid value for acceleration'

    # Act
    with pytest.raises(ValueError) as race_car:
        assert RaceCar(color=color,
                       max_speed=max_speed,
                       acceleration=acceleration,
                       tyre_friction=tyre_friction)

    # Assert
    assert str(race_car.value) == invalid_acceleration
コード例 #17
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
コード例 #18
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
コード例 #19
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
コード例 #20
0
def test_accelerate_race_car_multiple_times_when_nitro_not_available_and_update_current_speed(
):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=100,
                       acceleration=10,
                       tyre_friction=5)
    current_speed_value = 40
    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
コード例 #21
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
コード例 #22
0
def test_create_race_car_object_instance_with_valid_details():

    # Arrange
    color = 'Blue'
    max_speed = 30
    acceleration = 10
    tyre_friction = 5

    # Act
    race_car = RaceCar(color=color,
                       max_speed=max_speed,
                       acceleration=acceleration,
                       tyre_friction=tyre_friction)

    # Assert
    assert race_car.color == color
    assert race_car.max_speed == max_speed
    assert race_car.acceleration == acceleration
    assert race_car.tyre_friction == tyre_friction
コード例 #23
0
def test_sound_horn_when_race_car_engine_started_and_return_race_car_sound(
        capfd):

    # Arrange
    race_car = RaceCar(color='Red',
                       max_speed=130,
                       acceleration=10,
                       tyre_friction=3)
    sound = "Peep Peep\nBeep Beep\n"
    race_car.start_engine()

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

    # Assert
    assert output.out == sound
コード例 #24
0
def racecar2():
    racecar_obj2 = RaceCar(color='Red', max_speed=700, acceleration=80, tyre_friction=30)
    return racecar_obj2
コード例 #25
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
コード例 #26
0
def race_car2():
    race_car_obj = RaceCar(color="blue",
                           max_speed=50,
                           acceleration=20,
                           tyre_friction=4)
    return race_car_obj
コード例 #27
0
def race_car3():
    car_obj = RaceCar(color="blue",
                      max_speed=10,
                      acceleration=3,
                      tyre_friction=3)
    return car_obj
コード例 #28
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
コード例 #29
0
def racecar1():
    racecar_obj1 = RaceCar(color='Red', max_speed=300, acceleration=30, tyre_friction=10)
    return racecar_obj1