public void Discard_Left_command_when_the_robot_was_not_placed_on_the_table()
        {
            var toyRobot = new ToyRobot();

            toyRobot.Left();

            toyRobot.X.Should().Be(null);
            toyRobot.Y.Should().Be(null);
            toyRobot.Facing.Should().Be(null);
        }
Example #2
0
        public void Rotate_robot_left_90_degrees(string before, string after)
        {
            var toyRobot = new ToyRobot();

            toyRobot.Place(1, 1, before);

            toyRobot.Left();

            toyRobot.Facing.Should().Be(after);
        }
Example #3
0
        public void TestLeftWhenCorrectlyPlaced()
        {
            // Create an instance to test:
            ToyRobot robot = new ToyRobot();
            // Define a test input and output value:
            int    x      = 0;
            int    y      = 0;
            Facing facing = Facing.North;

            robot.Place(x, y, facing);

            // Run the method under test and verify result
            robot.Left();
            Assert.AreEqual(robot.Facing, Facing.West);
            robot.Left();
            Assert.AreEqual(robot.Facing, Facing.South);
            robot.Left();
            Assert.AreEqual(robot.Facing, Facing.East);
            robot.Left();
            Assert.AreEqual(robot.Facing, Facing.North);
        }
        public void Left_FromNorth_ToWest()
        {
            //Arrange
            var currentPosition   = new Position(0, 0);
            var facingManagerMock = new Mock <ICardinalDirectionManager>();

            facingManagerMock.Setup(facingManager => facingManager.TurnLeft()).Returns(new WestManager());
            var toyRobotManager = new ToyRobot(currentPosition, facingManagerMock.Object, new ReportManager());

            //Act
            CardinalDirection finalFacing = toyRobotManager.Left();

            //Assert
            Assert.AreEqual(CardinalDirection.WEST, finalFacing);
        }
Example #5
0
        public void TestLeftCommand()
        {
            // Arrange

            ToyRobot tRobot = new ToyRobot(5, 5);

            tRobot.Place(0, 0, Directions.North);

            // Act

            tRobot.Left();

            // Assert

            Assert.AreEqual(Directions.West, tRobot.F);
        }
Example #6
0
        public void TestLeftNoValidPlaceCommandExecutedException()
        {
            // Create an instance to test:
            ToyRobot robot = new ToyRobot();

            // Run the method under test:
            try
            {
                robot.Left();
                Assert.Fail("A valid Place command needs to be executed first");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(NoValidPlaceCommandExecutedException), ex.GetType(), ex.Message);
            }
        }
Example #7
0
        private void Window_KeyReleased(object sender, KeyEventArgs e)
        {
            if (e.Code == Keyboard.Key.Right)
            {
                toyRobot.Right();
            }

            if (e.Code == Keyboard.Key.Left)
            {
                toyRobot.Left();
            }

            if (e.Code == Keyboard.Key.Up)
            {
                toyRobot.Move();
            }
        }
        public void XmlTestCases()
        {
            // read data from row in data.xml
            string description    = (string)TestContext.DataRow["Description"];
            string expectedOutput = (string)TestContext.DataRow["Expected"];
            string allCommands    = (string)TestContext.DataRow["Commands"];

            // interpret user input - this avoids duplicating the XML
            // test data in a more explicit form
            foreach (string cmd in allCommands.Split(LineEnds, StringSplitOptions.RemoveEmptyEntries))
            {
                if (!String.IsNullOrWhiteSpace(cmd))
                {
                    string normalisedCmd = cmd.Trim().ToUpperInvariant();
                    if (normalisedCmd.StartsWith("PLACE"))
                    {
                        string   args   = normalisedCmd.Substring(5).Trim();
                        string[] tokens = args.Split(CommaOrSpace, StringSplitOptions.RemoveEmptyEntries);
                        if (tokens != null && tokens.Length == 3)
                        {
                            if (Int32.TryParse(tokens[0], out int x) &&
                                Int32.TryParse(tokens[1], out int y) &&
                                Enum.TryParse <Direction>(tokens[2].ToUpperInvariant(), out Direction facing))
                            {
                                robot.Place(x, y, facing, tableTop);
                            }
                        }
                    }
                    else if (normalisedCmd.StartsWith("LEFT"))
                    {
                        robot.Left();
                    }
                    else if (normalisedCmd.StartsWith("RIGHT"))
                    {
                        robot.Right();
                    }
                    else if (normalisedCmd.StartsWith("MOVE"))
                    {
                        robot.Move();
                    }
                }
            }

            // check output
            Assert.AreEqual(expectedOutput, robot.Report(), description);
        }
Example #9
0
        static void Main(string[] args)
        {
            try
            {
                ToyRobot tRobot1 = new ToyRobot(5, 5);

                Console.WriteLine("PLACE (0,0,NORTH)");
                tRobot1.Place(0, 0, Directions.North);

                Console.WriteLine(tRobot1.Report());

                Console.WriteLine("MOVE");
                tRobot1.Move();

                Console.WriteLine(tRobot1.Report());

                Console.WriteLine();
                Console.WriteLine();

                ToyRobot tRobot2 = new ToyRobot(5, 5);

                Console.WriteLine("PLACE (0,0,NORTH)");
                tRobot2.Place(0, 0, Directions.North);

                Console.WriteLine(tRobot2.Report());

                Console.WriteLine("MOVE");
                tRobot2.Left();

                Console.WriteLine(tRobot2.Report());

                Console.WriteLine();
                Console.WriteLine();

                ToyRobot tRobot3 = new ToyRobot(5, 5);

                Console.WriteLine("PLACE (1,2,EAST)");
                tRobot3.Place(1, 2, Directions.East);

                Console.WriteLine(tRobot3.Report());

                Console.WriteLine("MOVE");
                tRobot3.Move();

                Console.WriteLine(tRobot3.Report());

                Console.WriteLine("MOVE");
                tRobot3.Move();

                Console.WriteLine(tRobot3.Report());

                Console.WriteLine("LEFT");
                tRobot3.Left();

                Console.WriteLine(tRobot3.Report());

                Console.WriteLine("MOVE");
                tRobot3.Move();

                Console.WriteLine(tRobot3.Report());

                Console.WriteLine();
                Console.WriteLine();

                Console.ReadKey();
            }
            catch (Exception)
            {
            }
        }