Coverage for app/domain/probe/commands/factory.py: 100%
13 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-16 20:06 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-16 20:06 +0000
1from app.domain.probe.commands.command import Command
2from app.domain.probe.commands.move_command import Move
3from app.domain.probe.commands.turn_left_command import TurnLeft
4from app.domain.probe.commands.turn_right_command import TurnRight
5from app.domain.probe.exceptions import InvalidCommandError
8class CommandFactory:
9 @staticmethod
10 def create(command: str) -> Command:
11 commands: dict[str, Command] = {
12 "M": Move(),
13 "L": TurnLeft(),
14 "R": TurnRight(),
15 }
17 command_uppercase = command.upper()
19 if command_uppercase not in commands:
20 raise InvalidCommandError(
21 f"The command '{command}' does not exist. The existent commands are: {', '.join(commands.keys())}."
22 )
24 return commands[command_uppercase]