NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+88 views

Проверьте через сценарии команд работу `SafeElevator` в безопасном и небезопасном режимах: в безопасном режиме открыть двери и попытаться поехать, а затем создать лифт в небезопасном режиме и убедиться, что движение с открытыми дверями разрешено.

Practice

AI answer

You can test this with two scenarios. The methods open_doors() and move() are assumed below; substitute the actual command names and the way the mode is passed in the class API.

import pytest

# Safe mode: moving with the doors open is prohibited.
lift = SafeElevator(safe_mode=True)
lift.open_doors()
with pytest.raises(Exception):  # preferably specify the concrete exception type from the implementation
    lift.move()

# Unsafe mode: this restriction does not apply.
lift = SafeElevator(safe_mode=False)
lift.open_doors()
lift.move()

In the first scenario, it is also worth checking that after the operation is rejected, the elevator remains on the same floor and the doors remain open. In the second, check that the move command actually changed the elevator's state.