示例#1
0
        public void move_robot_to_out_of_boundries_throws_exception()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(4, 5, 'E');

             IRobotService robotService = new RobotService(table, robotState);

            string command = "MML";
            var ex = Assert.Throws<InvalidOperationException>(() => robotService.Proceed(command));
            Assert.That(ex.Message, Is.EqualTo("Out of boundaries"));
        }
示例#2
0
        public void move_robot_from_12n_goes_to_13n()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(1, 2, 'N');
             IRobotService robotService = new RobotService(table, robotState);

            string command = "LMLMLMLMM";
            var pos = robotService.Proceed(command);
            var expectedState = new RobotState(1, 3, 'N');
            Assert.AreEqual(expectedState.RobotCoordinate, pos.RobotCoordinate);
            Assert.AreEqual(expectedState.Heading, pos.Heading);
        }
示例#3
0
        public void move_robot_from_33e_goes_to_51e()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(3, 3, 'e');

             IRobotService robotService = new RobotService(table, robotState);

            string command = "MMRMMRMRRM";
            var pos = robotService.Proceed(command);
            var expectedState = new RobotState(5, 1, 'E');
            Assert.AreEqual(expectedState.RobotCoordinate, pos.RobotCoordinate);
            Assert.AreEqual(expectedState.Heading, pos.Heading);
        }
示例#4
0
        /// <summary>
        /// Checks if the movement is valid
        /// </summary>
        /// <param name="robotCurrentState"></param>
        /// <returns></returns>
        private bool CanMove(RobotState robotCurrentState)
        {
            int x = robotCurrentState.RobotCoordinate.Item1;
            int y = robotCurrentState.RobotCoordinate.Item2;

            int tableX = _table.TableCoordinate.Item1;
            int tableY = _table.TableCoordinate.Item2;

            switch (robotCurrentState.Heading)
            {
                //Facing north shouldn't Y of the table
                case 'N':
                    if (y + 1 > tableY)
                        return false;
                    break;
                //Facing east shouldn't X of the table
                case 'E':
                    if  (x + 1 > tableX)
                        return false;
                    break;
                //Facing south shouldn't go bellow 0
                case 'S':
                    if (y - 1 < 0)
                        return false;
                    break;
                //Facing west shouldn't go bellow 0
                case 'W':
                    if (x - 1 < 0)
                        return false;
                    break;
            }
            return true;
        }
示例#5
0
 /// <summary>
 /// Initialize the robot
 /// </summary>
 /// <param name="table"></param>
 /// <param name="robotCurrentState"></param>
 public RobotService(ITable table, RobotState robotCurrentState)
 {
     _table = table;
     _robot = new Robot(robotCurrentState);
 }
示例#6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="state"></param>
 public Robot(RobotState state)
 {
     RobotState = state;
 }
示例#7
0
        public void move_robot_with_invalid_command_throws_exception()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(3, 3, 'E');

             IRobotService robotService = new RobotService(table, robotState);

            string command = "ABCD1234";
            var pos = robotService.Proceed(command);
            var expectedState = new RobotState(3, 3, 'E');
            Assert.AreEqual(expectedState.RobotCoordinate, pos.RobotCoordinate);
            Assert.AreEqual(expectedState.Heading, pos.Heading);
        }
示例#8
0
        public void turn_robot_to_left_from_00n_goes_to_00w()
        {
            var coord = new Tuple<int, int>(5, 5);
            ITable table = new Table(coord);

            var robotState = new RobotState(0, 0, 'N');
             IRobotService robotService = new RobotService(table, robotState);

            string command = "L";
            var pos = robotService.Proceed(command);
            var expectedState = new RobotState(0, 0, 'W');
            Assert.AreEqual(expectedState.RobotCoordinate, pos.RobotCoordinate);
            Assert.AreEqual(expectedState.Heading, pos.Heading);
        }