Exemple #1
0
def test_accelerate_truck_returns_current_speed(max_speed, acceleration,
                                                tyre_friction, current_speed):
    # Arrange
    truck = Truck(color="Red",
                  max_speed=max_speed,
                  acceleration=acceleration,
                  tyre_friction=tyre_friction,
                  max_cargo_weight=100)
    truck.start_engine()

    # Act
    truck.accelerate()

    # Assert
    assert truck.current_speed == current_speed
def test_accelerate_truck_when_engine_started_and_update_current_speed():
    # Arrange
    truck = Truck(color='Blue',
                  max_speed=1,
                  acceleration=1,
                  tyre_friction=1,
                  max_cargo_weight=1)
    truck.start_engine()
    current_speed_value = 1

    # Act
    truck.accelerate()

    # Assert
    assert truck.current_speed == current_speed_value
Exemple #3
0
def test_apply_break_when_current_speed_with_different_acceleration_more_than_tyre_friction_returns_current_speed():
    # Arrange
    truck = Truck(color="Red", max_speed=50, acceleration=10,
                  tyre_friction=3, max_cargo_weight=100)
    current_speed = 27
    truck.start_engine()
    truck.accelerate()
    truck.accelerate()
    truck.accelerate()

    # Act
    truck.apply_brakes()

    # Assert
    assert truck.current_speed == current_speed
def test_load_when_truck_not_in_motion_with_invalid_load_values_raise_error():
    # Arrange
    truck = Truck(color='Blue',
                  max_speed=5,
                  acceleration=4,
                  tyre_friction=3,
                  max_cargo_weight=100)
    truck.start_engine()
    invalid_cargo_weight = "Invalid value for cargo_weight"

    # Act
    with pytest.raises(ValueError) as error:
        truck.load(-1)

    # Assert
    assert str(error.value) == invalid_cargo_weight
def test_sound_horn_when_truck_engine_started_and_return_car_sound(capfd):
    # Arrange
    truck = Truck(color='Blue',
                  max_speed=5,
                  acceleration=4,
                  tyre_friction=3,
                  max_cargo_weight=1)
    truck.start_engine()
    sound = "Honk Honk\n"

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

    # Assert
    assert output.out == sound
Exemple #6
0
def test_apply_break_when_current_speed_is_less_than_tyre_friction():
    # Arrange
    truck = Truck(color="Red",
                  max_speed=50,
                  acceleration=10,
                  tyre_friction=30,
                  max_cargo_weight=100)
    current_speed = 0
    truck.start_engine()
    truck.accelerate()

    # Act
    truck.apply_brakes()

    # Assert
    assert truck.current_speed == current_speed
def test_load_when_truck_in_motion_and_print_string(capfd):
    # Arrange
    truck = Truck(color='Blue',
                  max_speed=5,
                  acceleration=4,
                  tyre_friction=3,
                  max_cargo_weight=100)
    truck.start_engine()
    truck.accelerate()
    cannot_load = "Cannot load cargo during motion\n"

    # Act
    truck.load(1)
    output = capfd.readouterr()

    # Assert
    assert output.out == cannot_load
def test_apply_brakes_when_truck_current_speed_is_more_than_tyre_friction_and_update_current_speed(
):
    # Arrange
    truck = Truck(color='Blue',
                  max_speed=5,
                  acceleration=4,
                  tyre_friction=3,
                  max_cargo_weight=1)
    truck.start_engine()
    truck.accelerate()

    # Act
    truck.apply_brakes()
    current_speed_value = 1

    # Assert
    assert truck.current_speed == current_speed_value
Exemple #9
0
def test_load_cargo_when_truck_is_stopped_and_current_speed_is_zero_returns_current_cargo_weight(
):
    # Arrange
    truck = Truck(color="Red",
                  max_speed=50,
                  acceleration=10,
                  tyre_friction=30,
                  max_cargo_weight=100)
    truck.start_engine()
    current_cargo_weight = 50

    # Act
    truck.stop_engine()
    truck.load(50)

    # Assert
    assert truck.current_cargo_weight == current_cargo_weight
Exemple #10
0
def test_accelerate_truck_with_different_acceleration():
    # Arrange
    truck = Truck(color="Red",
                  max_speed=50,
                  acceleration=10,
                  tyre_friction=3,
                  max_cargo_weight=100)
    current_speed = 30
    truck.start_engine()

    # Act
    truck.accelerate()
    truck.accelerate()
    truck.accelerate()

    # Assert
    assert truck.current_speed == current_speed
Exemple #11
0
def test_load_cargo_when_truck_is_stopped_and_current_speed_is_not_zero_returns_statement(
        capsys):
    # Arrange
    truck = Truck(color="Red",
                  max_speed=50,
                  acceleration=10,
                  tyre_friction=30,
                  max_cargo_weight=100)
    truck.start_engine()
    truck.accelerate()
    statement = "Cannot load cargo during motion\n"

    # Act
    truck.stop_engine()
    truck.load(50)
    captured = capsys.readouterr()

    # Assert
    assert captured.out == statement
Exemple #12
0
def test_accelerate_truck_more_than_max_speed_returns_current_speed_equal_to_max_speed(
):
    # Arrange
    truck = Truck(color="Red",
                  max_speed=50,
                  acceleration=10,
                  tyre_friction=3,
                  max_cargo_weight=100)
    current_speed = 50
    truck.start_engine()

    # Act
    truck.accelerate()
    truck.accelerate()
    truck.accelerate()
    truck.accelerate()
    truck.accelerate()
    truck.accelerate()
    truck.accelerate()

    # Assert
    assert truck.current_speed == current_speed
Exemple #13
0
# -*- coding: utf-8 -*-
'''
The truckstop engine. This engine runs a loop that updates a variety of values
this truck.
'''

# Import python libs
import logging
import os
from truck import Truck

log = logging.getLogger(__name__)

if __name__ == '__main__':
    truck_id = os.getenv('TRUCK_ID')
    if truck_id:
        truck = Truck(truck_id=truck_id)
        truck.turn_on()
        if truck.run_diagnostics()[0]:
            truck.start_engine()
            truck.run(frequency=2)
    else:
        raise Exception('Truck ID [{}] invalid'.format(truck_id))