Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }