コード例 #1
0
ファイル: main.py プロジェクト: shaj/otus.python.base
def test_drive(vh: Vehicle):
    if not isinstance(vh, Vehicle):
        raise ValueError("vh must be derived from Vehicle")
    print('Test drive of a', vh)
    try:
        vh.beep()
        if vh.current_speed != 0:
            vh.slow_down(abs(vh.current_speed))
        vh.accelerate(60)
        vh.accelerate(60)
        print(f'After acceleration by 120 speed is {vh.current_speed}')
        vh.slow_down(60)
        vh.slow_down(60)
        print(f'After slow down by 120 speed is {vh.current_speed}')
        vh.accelerate(-60)
        vh.accelerate(-60)
        print(f'After acceleration by -120 speed is {vh.current_speed}')
        vh.slow_down(60)
        vh.slow_down(60)
        print(f'After slow down by 120 speed is {vh.current_speed}')
        vh.beep()
    except Exception as e:
        print(f'Error in test_drive <{vh}> : "{e.args[0]}"')