Example #1
0
        public void changeHeadingMultiple()
        {
            //Arrange
            IGarden testGarden = new Garden();
            Mower testMower = new Mower(testGarden);

            //Act
            testMower.move("LLRRR");

            //Assert
            Assert.AreEqual('E', testMower.Heading);
        }
Example #2
0
        static void Main(string[] args)
        {
            List<Mower> mowers = new List<Mower>();

            Console.Write("Garden Length: ");
            int gardenLength = int.Parse(Console.ReadLine());

            Console.Write("Garden Width: ");
            int gardenWidth = int.Parse(Console.ReadLine());

            Garden garden = new Garden { Length = gardenLength, Width = gardenWidth };

            Console.Write("No. of Mowers: ");
            int mowerCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < mowerCount; i++)
            {
                mowers.Add(new Mower(garden));
            }

            foreach (Mower robotMower in mowers)
            {
                Console.Write("X Y Heading: ");
                string mowerParams = Console.ReadLine();

                Console.Write("Instructions: ");
                string moveParams = Console.ReadLine();

                try {
                    char[] mowerParamArray = mowerParams.ToCharArray();

                    robotMower.Position.X = int.Parse(mowerParamArray[0].ToString());

                    robotMower.Position.Y = int.Parse(mowerParamArray[1].ToString());

                    robotMower.Heading = mowerParamArray[2];

                    robotMower.move(moveParams);
                }
                catch
                {
                    Console.Write("The move is illegal: ");
                }

            }

            foreach (Mower robotMower in mowers)
            {
                Console.WriteLine(robotMower.ToString());
            }

            Console.ReadLine();
        }
Example #3
0
        public void changeHeading()
        {
            //Arrange
            IGarden testGarden = new Garden();
            Mower testMower = new Mower(testGarden);

            //Act
            testMower.move('L');

            //Assert
            Assert.AreEqual('W', testMower.Heading);
        }
Example #4
0
        public void moveSingle()
        {
            //Arrange
            IGarden testGarden = new Garden {Width=1, Length=1 };
            Mower testMower = new Mower(testGarden);

            //Act
            testMower.move('M');

            //Assert
            Assert.AreEqual(0, testMower.Position.X);
            Assert.AreEqual(1, testMower.Position.Y);
        }
Example #5
0
        public void moveMultiple2()
        {
            //Arrange
            IGarden testGarden = new Garden { Width = 5, Length = 5 };
            Mower testMower = new Mower(testGarden, new CoOrdinate { X = 3, Y = 3 }, 'E');

            //Act
            testMower.move("MMRMMRMRRM");

            //Assert
            Assert.AreEqual('E', testMower.Heading);
            Assert.AreEqual(5, testMower.Position.X);
            Assert.AreEqual(1, testMower.Position.Y);
        }
Example #6
0
        public void moveMultiple()
        {
            //Arrange
            IGarden testGarden = new Garden { Width = 5, Length = 5 };
            Mower testMower = new Mower(testGarden, new CoOrdinate {X=1, Y=2 }, 'N');

            //Act
            testMower.move("LMLMLMLMM");

            //Assert
            Assert.AreEqual('N', testMower.Heading);
            Assert.AreEqual(1, testMower.Position.X);
            Assert.AreEqual(3, testMower.Position.Y);
        }
Example #7
0
        public void moveException()
        {
            //Arrange
            IGarden testGarden = new Garden { Width = 1, Length = 1 };
            Mower testMower = new Mower(testGarden, new CoOrdinate { X = 0, Y = 0 }, 'W');
            string message = string.Empty;
            //Act
            try {
                testMower.move('M');
            }
            catch(Exception ex)
            {
                message = ex.Message;
            }

            //Assert
            Assert.AreEqual(0, testMower.Position.X);
            Assert.AreEqual(0, testMower.Position.Y);
            Assert.AreEqual("You have reached the edge of the garden", message);
        }