Exemplo n.º 1
0
 public Robot(int x, int y, Orientation orientation, Mars mars)
 {
     X           = x;
     Y           = y;
     Orientation = orientation;
     _mars       = mars;
 }
Exemplo n.º 2
0
 public Robot(int x, int y, Orientation orientation, Mars mars)
 {
     X = x;
     Y = y;
     Orientation = orientation;
     _mars = mars;
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }