Exemple #1
0
        public void ReportsCorrectly()
        {
            var toyRobot = new ToyRobot();

            toyRobot.Command("PLACE 1,2,N");
            var output = toyRobot.Command("REPORT");

            Assert.AreEqual(output, "I'm sitting at X: 1, Y: 2, facing North and feeling great. Thanks for asking!");
        }
        public void CommandBeforePlaceThrowsException()
        {
            var toyRobot = new ToyRobot();

            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("MOVE"));
            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("LEFT"));
            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("RIGHT"));
            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("REPORT"));
        }
Exemple #3
0
        public void TurnsRightCorrectly()
        {
            var toyRobot = new ToyRobot();

            toyRobot.Command("PLACE 0,0,N");
            toyRobot.Command("RIGHT");
            Assert.AreEqual(toyRobot.Direction, Direction.East);

            toyRobot.Command("RIGHT");
            Assert.AreEqual(toyRobot.Direction, Direction.South);

            toyRobot.Command("RIGHT");
            Assert.AreEqual(toyRobot.Direction, Direction.West);

            toyRobot.Command("RIGHT");
            Assert.AreEqual(toyRobot.Direction, Direction.North);
        }
Exemple #4
0
        public void PlacesCorrectly()
        {
            var toyRobot = new ToyRobot();

            toyRobot.Command("PLACE 1,2,N");
            Assert.AreEqual(toyRobot.X, 1);
            Assert.AreEqual(toyRobot.Y, 2);
            Assert.AreEqual(toyRobot.Direction, Direction.North);

            toyRobot.Command("PLACE 3,2,S");
            Assert.AreEqual(toyRobot.X, 3);
            Assert.AreEqual(toyRobot.Y, 2);
            Assert.AreEqual(toyRobot.Direction, Direction.South);

            toyRobot.Command("PLACE 2,1,E");
            Assert.AreEqual(toyRobot.X, 2);
            Assert.AreEqual(toyRobot.Y, 1);
            Assert.AreEqual(toyRobot.Direction, Direction.East);

            toyRobot.Command("PLACE 0,1,W");
            Assert.AreEqual(toyRobot.X, 0);
            Assert.AreEqual(toyRobot.Y, 1);
            Assert.AreEqual(toyRobot.Direction, Direction.West);
        }
        public void MoveOffTableIsPrevented()
        {
            var toyRobot = new ToyRobot();

            // Check the top of the table
            toyRobot.Command("PLACE 0,0,N");
            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("MOVE"));

            // Check the bottom of the table
            toyRobot.Command("PLACE 0,4,S");
            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("MOVE"));

            // Check the left of the table
            toyRobot.Command("PLACE 0,0,W");
            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("MOVE"));

            // Check the right of the table
            toyRobot.Command("PLACE 4,0,E");
            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("MOVE"));
        }
Exemple #6
0
        public void MovesInCorrectDirection()
        {
            var toyRobot = new ToyRobot();

            toyRobot.Command("PLACE 0,1,N");
            toyRobot.Command("MOVE");
            Assert.AreEqual(toyRobot.X, 0);
            Assert.AreEqual(toyRobot.Y, 0);

            toyRobot.Command("PLACE 0,0,S");
            toyRobot.Command("MOVE");
            Assert.AreEqual(toyRobot.X, 0);
            Assert.AreEqual(toyRobot.Y, 1);

            toyRobot.Command("PLACE 0,0,E");
            toyRobot.Command("MOVE");
            Assert.AreEqual(toyRobot.X, 1);
            Assert.AreEqual(toyRobot.Y, 0);

            toyRobot.Command("PLACE 1,0,W");
            toyRobot.Command("MOVE");
            Assert.AreEqual(toyRobot.X, 0);
            Assert.AreEqual(toyRobot.Y, 0);
        }
        public void PlaceOffTableThrowsException()
        {
            var toyRobot = new ToyRobot();

            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("PLACE 10,10,N"));
        }
        public void InvalidCommandThrowsException()
        {
            var toyRobot = new ToyRobot();

            Assert.Throws <InvalidCommandException>(() => toyRobot.Command("THIS IS NOT A COMMAND"));
        }