Esempio n. 1
0
        public void DemoTest_InputGrid5_3_Robot0_3_W_LLFFFLFLFL_ScentAt3_3_N_Expected2_3_S_NotLost()
        {
            // Arrange
            var grid = new MarsGrid(5, 3);

            // create scent
            var robot        = new MarsRobot(3, 2, RobotDirection.North);
            var instructions = Parsers.ParseInstructions("FRRFLLFFRRFLL").ToArray();

            robot.PerformInstructions(grid, instructions);

            var robot2        = new MarsRobot(0, 3, RobotDirection.West);
            var instructions2 = Parsers.ParseInstructions("LLFFFLFLFL").ToArray();

            // Act
            var result = robot2.PerformInstructions(grid, instructions2);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual((2, 3), (result.endX, result.endY));
                Assert.AreEqual(RobotDirection.South, result.direction);
                Assert.IsFalse(result.lost);
            });
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Waiting for input.");
                var(rightLimit, topLimit) = ParseGridSize();
                var grid = new MarsGrid(rightLimit, topLimit);

                while (true)
                {
                    (int startX, int startY, RobotDirection direction) = ParseRobotPosition();
                    var robot = new MarsRobot(startX, startY, direction);

                    var instructions = ParseInstructions();
                    (int endX, int endY, RobotDirection endDirection, bool lost) = robot.PerformInstructions(grid, instructions);
                    var lostText = lost ? "LOST" : "";
                    Console.WriteLine($"{endX} {endY} {endDirection.ToString()[0]} {lostText}");
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Bad input: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unexpected error: " + ex.Message);
            }
        }
Esempio n. 3
0
        public void LostTest_InputGrid2_2_Robot2_2_N_Perform_F_Expected2_2_N_Lost()
        {
            // Arrange
            var grid         = new MarsGrid(2, 2);
            var robot        = new MarsRobot(2, 2, RobotDirection.North);
            var instructions = new RobotInstruction[] { RobotInstruction.Forward };

            // Act
            var result = robot.PerformInstructions(grid, instructions);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual((2, 2), (result.endX, result.endY));
                Assert.AreEqual(RobotDirection.North, result.direction);
                Assert.IsTrue(result.lost);
            });
        }
Esempio n. 4
0
        public void NotLostTest_InputGrid2_2_Robot1_0_W_Perform_F_Expected0_0_W_NotLost()
        {
            // Arrange
            var grid         = new MarsGrid(2, 2);
            var robot        = new MarsRobot(1, 0, RobotDirection.West);
            var instructions = new RobotInstruction[] { RobotInstruction.Forward };

            // Act
            var result = robot.PerformInstructions(grid, instructions);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual((0, 0), (result.endX, result.endY));
                Assert.AreEqual(RobotDirection.West, result.direction);
                Assert.IsFalse(result.lost);
            });
        }
Esempio n. 5
0
        public void LapOfHonorTest_InputGrid2_2_Robot0_0_N_Perform_FFRFFRFFRFFRRFFLFFLFFLFF_Expected0_0_S_NotLost()
        {
            // Arrange
            var grid         = new MarsGrid(2, 2);
            var robot        = new MarsRobot(0, 0, RobotDirection.North);
            var instructions = Parsers.ParseInstructions("FFRFFRFFRFFRRFFLFFLFFLFF").ToArray();

            // Act
            var result = robot.PerformInstructions(grid, instructions);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual((0, 0), (result.endX, result.endY));
                Assert.AreEqual(RobotDirection.South, result.direction);
                Assert.IsFalse(result.lost);
            });
        }
Esempio n. 6
0
        public void DemoTest_InputGrid5_3_Robot3_2_N_FRRFLLFFRRFLL_Expected3_3_N_Lost()
        {
            // Arrange
            var grid         = new MarsGrid(5, 3);
            var robot        = new MarsRobot(3, 2, RobotDirection.North);
            var instructions = Parsers.ParseInstructions("FRRFLLFFRRFLL").ToArray();

            // Act
            var result = robot.PerformInstructions(grid, instructions);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual((3, 3), (result.endX, result.endY));
                Assert.AreEqual(RobotDirection.North, result.direction);
                Assert.IsTrue(result.lost);
            });
        }
Esempio n. 7
0
        public void DemoTest_InputGrid5_3_Robot1_1_E_RFRFRFRF_Expected1_1_E_NotLost()
        {
            // Arrange
            var grid         = new MarsGrid(5, 3);
            var robot        = new MarsRobot(1, 1, RobotDirection.East);
            var instructions = Parsers.ParseInstructions("RFRFRFRF").ToArray();

            // Act
            var result = robot.PerformInstructions(grid, instructions);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual((1, 1), (result.endX, result.endY));
                Assert.AreEqual(RobotDirection.East, result.direction);
                Assert.IsFalse(result.lost);
            });
        }
Esempio n. 8
0
        public void ScentTest_InputFirstRobotLostSecondRepeatsRouteButHasDifferentLastDirection_ExpectedBothLost()
        {
            // Arrange
            var grid          = new MarsGrid(2, 2);
            var robot         = new MarsRobot(2, 2, RobotDirection.North);
            var robot2        = new MarsRobot(2, 2, RobotDirection.North);
            var instructions  = new RobotInstruction[] { RobotInstruction.Forward };
            var instructions2 = new RobotInstruction[] { RobotInstruction.TurnRight, RobotInstruction.Forward };

            // Act
            var result1 = robot.PerformInstructions(grid, instructions);
            var result2 = robot2.PerformInstructions(grid, instructions2);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual((2, 2), (result1.endX, result1.endY));
                Assert.AreEqual((2, 2), (result2.endX, result2.endY));
                Assert.IsTrue(result1.lost);
                Assert.IsTrue(result2.lost);
            });
        }