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
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)
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()
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()
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)
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)
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)
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
def assert_gear_was_reduced_twice(gearbox, initial_gear: Gear): assert gearbox.current_gear == initial_gear.previous().previous()
def assert_gear_was_increased(gearbox, initial_gear: Gear): assert gearbox.current_gear == initial_gear.next()
def __init__(self): self._curr_gear = Gear(gear=1) self._max_gear = Gear(gear=5) self._mode = DrivingMode.ECO