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
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
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
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
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"
def race_car(): race_car_obj = RaceCar(color='Red', max_speed=30, acceleration=10, tyre_friction=3) return race_car_obj
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
def racecar2(): racecar_obj2 = RaceCar(color='Red', max_speed=700, acceleration=80, tyre_friction=30) return racecar_obj2
def race_car2(): race_car_obj = RaceCar(color="blue", max_speed=50, acceleration=20, tyre_friction=4) return race_car_obj
def race_car3(): car_obj = RaceCar(color="blue", max_speed=10, acceleration=3, tyre_friction=3) return car_obj
def racecar1(): racecar_obj1 = RaceCar(color='Red', max_speed=300, acceleration=30, tyre_friction=10) return racecar_obj1