public void RobotCommander_RecognisedCommand_ReportsValid()
        {
            var commander = new RobotCommander(new Mock <ILogger>().Object, new RobotAction(new Mock <ILogger>().Object));
            var response  = commander.Command("MOVE");

            Assert.AreEqual("Robot cannot move until it has been placed on the table.", response);
        }
示例#2
0
        public void Robot_TestMultipleMovement_RobotReportsCorrectLocation()
        {
            Robot          robot     = new Robot();
            Tabletop       table     = new Tabletop(5, 5);
            RobotCommander commander = new RobotCommander();

            PlaceCommand place = new PlaceCommand(robot, table);

            place.Direction = "North";
            MoveCommand  move  = new MoveCommand(robot, table);
            RightCommand right = new RightCommand(robot);
            LeftCommand  left  = new LeftCommand(robot);


            commander.Commands.Enqueue(place);
            commander.Commands.Enqueue(move);
            commander.Commands.Enqueue(move);
            commander.Commands.Enqueue(right);
            commander.Commands.Enqueue(move);
            commander.Commands.Enqueue(left);
            commander.Commands.Enqueue(left);

            commander.ExecuteCommands();

            Assert.Equal(Facing.West, robot.Direction);
            Assert.Equal(2, robot.Position.Y);
            Assert.Equal(1, robot.Position.X);
        }
示例#3
0
        public void Robot_TestUndoWhenWhenRobotIsStuckAgainstSouthWall_RobotReportsOrignalPosition()
        {
            Robot          robot     = new Robot();
            Tabletop       table     = new Tabletop(5, 5);
            RobotCommander commander = new RobotCommander();

            PlaceCommand place = new PlaceCommand(robot, table);

            place.Direction = "North";
            MoveCommand  move  = new MoveCommand(robot, table);
            RightCommand right = new RightCommand(robot);
            LeftCommand  left  = new LeftCommand(robot);


            commander.Commands.Enqueue(place);
            commander.Commands.Enqueue(right);
            commander.Commands.Enqueue(right);
            commander.Commands.Enqueue(move);

            commander.ExecuteCommands();
            commander.UndoCommands(1);

            Assert.Equal(0, robot.Position.Y);
            Assert.Equal(0, robot.Position.X);
        }
        public void RobotCommander_PlacedAndMoved_ReportsCorrectPosition()
        {
            var commander = new RobotCommander(new Mock <ILogger>().Object, new RobotAction(new Mock <ILogger>().Object));

            commander.Command("PLACE 1,1,NORTH");
            commander.Command("MOVE");
            Assert.AreEqual("1,2,NORTH", commander.Command("REPORT"));
        }
        public void RobotCommander_PlacedAndMovedOffTable_CannotBeMoved()
        {
            var commander = new RobotCommander(new Mock <ILogger>().Object, new RobotAction(new Mock <ILogger>().Object));

            commander.Command("PLACE 5,5,NORTH");
            commander.Command("MOVE");
            Assert.AreEqual("5,5,NORTH", commander.Command("REPORT"));
        }
        public void RobotCommander_PlacedAndTurnedRight_ReportsCorrectPosition()
        {
            var commander = new RobotCommander(new Mock <ILogger>().Object, new RobotAction(new Mock <ILogger>().Object));

            commander.Command("PLACE 1,1,NORTH");
            commander.Command("RIGHT");
            Assert.AreEqual("1,1,EAST", commander.Command("REPORT"));
        }
示例#7
0
        private static void InitializeRobot(out Robot robot, out RobotCommander commander, out string response)
        {
            Table table = new Table(5, 5);

            robot     = new Robot();
            commander = new RobotCommander(robot, table);
            response  = "";
        }
示例#8
0
        public void CreateInitialArenaTests(string commandInput, int expectedWidth, int expectedHeight)
        {
            IRobotCommander robotCommander = new RobotCommander(commandInput);

            robotCommander.ExecuteCommands();


            Assert.AreEqual(expectedWidth, robotCommander.Arena.Dimensions.Width);
            Assert.AreEqual(expectedHeight, robotCommander.Arena.Dimensions.Height);
        }
示例#9
0
        public void FullInputTest()
        {
            string          commandInput   = BuildTestInput();
            string          expectedOutput = "1 3 N\n5 1 E";
            IRobotCommander robotCommander = new RobotCommander(commandInput);

            robotCommander.ExecuteCommands();

            string result = robotCommander.GetRobotPositionOutput();

            Assert.AreEqual(expectedOutput, result);
        }
示例#10
0
        public void PlaceRobotCorrectlyTests(string commandInput, int expectedX, int expectedY, Direction expectedDirection)
        {
            IRobotCommander robotCommander = new RobotCommander(commandInput);

            robotCommander.ExecuteCommands();
            List <IRobot> robots   = robotCommander.GetRobots();
            Position      position = robots[0].GetPosition();

            Assert.AreEqual(expectedX, position.X);
            Assert.AreEqual(expectedY, position.Y);
            Assert.AreEqual(expectedDirection, position.Direction);
        }
示例#11
0
        public void RobotsMoveToCorrectLocationTests(string commandInput, int initialX, int initialY, Direction initialDirection, int expectedX, int expectedY, Direction expectedDirection)
        {
            IRobotCommander robotCommander = new RobotCommander(commandInput);

            robotCommander.AddBattleRobot(new BattleRobot(initialX, initialY, initialDirection));

            robotCommander.ExecuteCommands();
            List <IRobot> robots   = robotCommander.GetRobots();
            Position      position = robots[0].GetPosition();

            Assert.AreEqual(expectedX, position.X);
            Assert.AreEqual(expectedY, position.Y);
            Assert.AreEqual(expectedDirection, position.Direction);
        }
        public void RobotCommander_PlaceCommandWithNoArguments_ReportsInvalid()
        {
            var commander = new RobotCommander(new Mock <ILogger>().Object, new RobotAction(new Mock <ILogger>().Object));
            var response  = commander.Command("PLACE");

            Assert.AreEqual(@"Invalid command. The correct command formats are as follows:
                    PLACE X, Y, DIRECTION
                    MOVE
                    RIGHT
                    LEFT
                    REPORT
                    -------------
                    Please review your input and try again.", response);
        }
示例#13
0
        static void Main(string[] args)
        {
            DisplayWelcome();

            var kernel = new StandardKernel();

            LogHandler.InitialiseLoggingConfig("RobotAction Simulator", true);
            kernel.Load(Assembly.GetExecutingAssembly());

            var robotMover = new RobotCommander(kernel.Get <ILogger>(), kernel.Get <IRobotAction>());

            while (true)
            {
                var command = PromptForCommand();
                if (command.ToUpper() == "EXIT" || command.ToUpper() == "QUIT")
                {
                    Environment.Exit(0);
                }
                Console.WriteLine(robotMover.Command(command));
                Console.WriteLine("");
            }
        }
        public void RobotCommander_InitialisedRobotCommander_ControlsRobot()
        {
            var commander = new RobotCommander(new Mock <ILogger>().Object, new RobotAction(new Mock <ILogger>().Object));

            Assert.IsNotNull("");
        }