Проверьте через сценарии команд работу `SafeElevator` в безопасном и небезопасном режимах: в безопасном режиме открыть двери и попытаться поехать, а затем создать лифт в небезопасном режиме и убедиться, что движение с открытыми дверями разрешено.
Asked at
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.
Also asked at Касперский
Similar questions
- How is a test environment created and maintained?
- Review the code for bugs, security vulnerabilities, and other issues, and explain them from top to bottom. Then suggest how to fix them.
- What would your test plan be for an authentication form (username/password/Log in button)? What would you clarify with the analyst and developers?
- How and where would you document any concerns or risks when releasing functionality?
- Can you explain the concept of a safe point in the context of memory management or multithreading?