Пример #1
0
 public Robot(int x, int y, Orientation orientation, Mars mars)
 {
     X           = x;
     Y           = y;
     Orientation = orientation;
     _mars       = mars;
 }
Пример #2
0
 public Robot(int x, int y, Orientation orientation, Mars mars)
 {
     X = x;
     Y = y;
     Orientation = orientation;
     _mars = mars;
 }
Пример #3
0
        private static Robot ParseRobot(String robot, Mars mars)
        {
            string[] inputs      = robot.Split(' ');
            var      x           = int.Parse(inputs[0]);
            var      y           = int.Parse(inputs[1]);
            var      orientation = GetOrientation(inputs[2]);

            return(new Robot(x, y, orientation, mars));
        }
Пример #4
0
        public void DirectionalMovement(Orientation orientation, int x, int y)
        {
            //arrange
            var mars = new Mars(5, 3);
            var robot = new Robot(1, 1, orientation, mars);

            //act
            robot.ExecuteCommand(Command.forward);

            //assert
            Assert.AreEqual(x, robot.X);
            Assert.AreEqual(y, robot.Y);
        }
Пример #5
0
        public void Boundaries(Orientation orientation, int timesForward, bool shouldBeLost)
        {
            //arrange
            var mars = new Mars(5, 3);
            var robot = new Robot(1, 1, orientation, mars);

            //act
            for(int i=0; i<timesForward; i++)
                robot.ExecuteCommand(Command.forward);

            //assert
            Assert.AreEqual(shouldBeLost, robot.IsLost);
        }
Пример #6
0
        public void ReportLastPositionIfFallenOff()
        {
            //arrange
            var mars = new Mars(5, 3);
            var lostRobot = new Robot(5, 3, Orientation.north, mars);

            //act
            lostRobot.ExecuteCommand(Command.forward);
            lostRobot.ExecuteCommand(Command.forward);

            //assert
            //lost robot's position should be the last one if had before falling off
            Assert.AreEqual(5, lostRobot.X);
            Assert.AreEqual(3, lostRobot.Y);
        }
Пример #7
0
        public void Reorientation(Command command, int timesRotate, Orientation orientation)
        {
            //arrange
            var mars = new Mars(5, 3);
            var robot = new Robot(0, 0, Orientation.north, mars);

            //act
            for(int i=0; i<timesRotate; i++)
                robot.ExecuteCommand(command);

            //assert
            Assert.AreEqual(orientation, robot.Orientation);
            Assert.AreEqual(0, robot.X);
            Assert.AreEqual(0, robot.Y);
        }
Пример #8
0
        public void GetMarsRobotsAndCommandSequences()
        {
            //arrange
            var input =
            @"50 30
            13 12 N
            FRRFLLFFRRFLL
            ";
            var mars = new Mars(50, 30);
            var expectedRobots = new List<Robot>() { new Robot(13, 12, Orientation.north, mars) };
            var expectedCommandSequences = new List<List<Command>> { new Mocks().GetCommandSequence() };

            //act
            List<Robot> actualRobots;
            List<List<Command>> actualCommandSequences;
            Input.GetRobotsAndCommandSequences(input, out actualRobots, out actualCommandSequences);

            //assert
            Assert.That(actualRobots, IsDeeplyEqual.To(expectedRobots));
            Assert.That(actualCommandSequences, IsDeeplyEqual.To(expectedCommandSequences));
        }
Пример #9
0
        public void SniffForScentsBeforeFallingOff()
        {
            //arrange
            var mars = new Mars(5, 3);
            var lostRobot = new Robot(5, 3, Orientation.north, mars);
            var savedRobot = new Robot(5, 3, Orientation.north, mars);

            //act
            lostRobot.ExecuteCommand(Command.forward);
            savedRobot.ExecuteCommand(Command.forward);

            //assert
            Assert.AreEqual(true, lostRobot.IsLost);
            Assert.AreEqual(false, savedRobot.IsLost);
        }
Пример #10
0
 private static Robot ParseRobot(String robot, Mars mars)
 {
     //1 1 E
     //33 44 E
     string[] inputs = robot.Split(' ');
     var x = int.Parse(inputs[0]);
     var y = int.Parse(inputs[1]);
     var orientation = GetOrientation(inputs[2]);
     return new Robot(x, y, orientation, mars);
 }