public void ParsingTest()
        {
            Dictionary <String, Command> testData = new Dictionary <string, Command>();

            testData.Add("MOVE", new Command_Move());
            testData.Add("LEFT", new Command_Left());
            testData.Add("RIGHT", new Command_Right());
            testData.Add("REPORT", new Command_Report());
            testData.Add("PLACE 1,1,NORTH", new Command_Place(new Position(1, 1), Facing.NORTH));
            testData.Add("Move", null);
            testData.Add("invalid command", null);
            testData.Add("  MOVE     ", new Command_Move());
            testData.Add("   PLACE  1    ,    1  ,   NORTH   ", new Command_Place(new Position(1, 1), Facing.NORTH));

            testData.Add("   PLACE  1  1  ,       NORTH   ", null);
            testData.Add("MOVE Something", null);

            RobotSimulatorCommandLineParser parser = new RobotSimulatorCommandLineParser();

            foreach (var data in testData)
            {
                Command result = parser.Parsing(data.Key);
                if (data.Value == null)
                {
                    Assert.IsNull(result);
                }
                else
                {
                    Assert.IsInstanceOfType(result, data.Value.GetType());
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Robot                  robot            = new Robot();
            TableTop               table            = new SquareTableTop(5);
            IRobotMovingService    movingService    = new ToyRobotMovingService();
            IRobotReportingService reportingService = new ToyRobotReportingService();
            IRobotTurningService   turningService   = new ToyRobotTurningService();

            RobotSimulator simulator = new RobotSimulator(robot, table, movingService, turningService, reportingService);

            RobotSimulatorCommandLineParser parser    = new RobotSimulatorCommandLineParser();
            RobotSimulatorCommandController controler = new RobotSimulatorCommandController(simulator);

            while (true)
            {
                string  input   = Console.ReadLine();
                Command command = parser.Parsing(input);
                if (command != null)
                {
                    controler.Run(command);
                }
            }
        }