예제 #1
0
 def handle_gas(
     self, curr_gear: Gear, curr_rpm: EngineRPMS, pressure: GasPressure
 ) -> Gear:
     if curr_rpm.is_above(self._rpsm_range):
         return curr_gear.next()
     if curr_rpm.is_below(self._rpsm_range):
         return curr_gear.previous()
     return curr_gear
예제 #2
0
def test_gear_cannot_exceed_range():
    max_gear = Gear(gear=6)
    gearbox = create_gearbox().with_gear(
        Gear(gear=1)).with_max_gear(max_gear).build()
    gearbox_driver = create_gearbox_driver(gearbox).build()

    for x in range(10):
        gearbox_driver.increase_gear()
    assert_max_gear_is_set(gearbox, max_gear)
예제 #3
0
def test_strategy_sets_next_gear_when_rpms_above_range(mode):
    strategy = DrivingModeStrategy.create(driving_mode=mode,
                                          aggressive_mode=AggressiveMode.Mode1)
    curr_gear = Gear(gear=2)

    gear_to_set = strategy.handle_gas(curr_gear=curr_gear,
                                      curr_rpm=EngineRPMS(value=5000),
                                      pressure=GENTLE_PRESSURE)

    assert gear_to_set == curr_gear.next()
예제 #4
0
def test_strategy_sets_previous_gear_on_kickdown_no_matter_what_are_current_rpms(
        mode, curr_rpms):
    strategy = DrivingModeStrategy.create(driving_mode=mode,
                                          aggressive_mode=AggressiveMode.Mode1)
    curr_gear = Gear(gear=2)

    gear_to_set = strategy.handle_gas(curr_gear=curr_gear,
                                      curr_rpm=EngineRPMS(value=curr_rpms),
                                      pressure=KICKDOWN)

    assert gear_to_set == curr_gear.previous()
예제 #5
0
def test_gear_is_reduced_twice_when_aggressive_kickdown():
    initial_gear = Gear(gear=4)
    gearbox = create_gearbox().with_gear(initial_gear).build()
    gearbox_driver = create_gearbox_driver(gearbox).with_sport_mode().build()

    gearbox_driver.handle_gas(pressure=AGGRESIVE_KICKDOWN)

    assert_gear_was_reduced_twice(gearbox, initial_gear)
예제 #6
0
def test_gear_is_not_reduced_when_kickdown_on_lowest_gear():
    initial_gear = Gear(gear=1)
    gearbox = create_gearbox().with_gear(initial_gear).build()
    gearbox_driver = create_gearbox_driver(gearbox).with_sport_mode().build()

    gearbox_driver.handle_gas(pressure=KICKDOWN)

    assert_gear_was_not_changed(gearbox, initial_gear)
예제 #7
0
def test_gear_is_changed_when_threshold_is_exceeded():
    initial_gear = Gear(gear=1)
    gearbox = create_gearbox().with_gear(initial_gear).build()
    gearbox_driver = (create_gearbox_driver(gearbox).with_engine_at(
        RPMS_ABOVE_SPORT_MODE_THRESHOLD).build())

    gearbox_driver.handle_gas(pressure=GENTLE_PRESSURE)

    assert_gear_was_increased(gearbox, initial_gear)
예제 #8
0
def test_strategy_does_not_change_gear_when_proper_rpms(mode):
    strategy = DrivingModeStrategy.create(driving_mode=mode,
                                          aggressive_mode=AggressiveMode.Mode1)
    curr_gear = Gear(gear=2)

    gear_to_set = strategy.handle_gas(curr_gear=curr_gear,
                                      curr_rpm=EngineRPMS(value=2000),
                                      pressure=GENTLE_PRESSURE)

    assert gear_to_set == curr_gear
예제 #9
0
def assert_gear_was_reduced_twice(gearbox, initial_gear: Gear):
    assert gearbox.current_gear == initial_gear.previous().previous()
예제 #10
0
def assert_gear_was_increased(gearbox, initial_gear: Gear):
    assert gearbox.current_gear == initial_gear.next()
예제 #11
0
 def __init__(self):
     self._curr_gear = Gear(gear=1)
     self._max_gear = Gear(gear=5)
     self._mode = DrivingMode.ECO