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 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_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_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_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_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_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_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_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_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_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