コード例 #1
0
        public void StageAddLawnMower_CalledTwice_AddsTwoLawnMowersToMowersWithMovementInstructionsAtExpectedIndex()
        {
            //Arrange
            string[] argsSplit = "5 5\n1 2 N\nLMLMLMLMM\n3 3 E\nMMRMMMRMRMM".Split(new[] { "\n" }, StringSplitOptions.None);
            var lawn = new Lawn(5, 5);
            var stage = new Stage(lawn);
            var mowerInitializationTuples = ProgramWithPublicMethods.GetMowerInitializationTuples(argsSplit);

            //Act
            stage.AddLawnMower(mowerInitializationTuples[0].Item1, mowerInitializationTuples[0].Item2, mowerInitializationTuples[0].Item3, mowerInitializationTuples[0].Item4);
            stage.AddLawnMower(mowerInitializationTuples[1].Item1, mowerInitializationTuples[1].Item2, mowerInitializationTuples[1].Item3, mowerInitializationTuples[1].Item4);

            //Assert lawnMower1 inputs
            Assert.AreEqual(1, stage.MowersWithMovementInstructions[0].Item1.XCord);
            Assert.AreEqual(2, stage.MowersWithMovementInstructions[0].Item1.YCord);
            Assert.AreEqual(CompassDirection.N, stage.MowersWithMovementInstructions[0].Item1.Heading);
            StringAssert.IsMatch("LMLMLMLMM", stage.MowersWithMovementInstructions[0].Item2);

            //Assert lawnMower2 inputs
            Assert.AreEqual(3, stage.MowersWithMovementInstructions[1].Item1.XCord);
            Assert.AreEqual(3, stage.MowersWithMovementInstructions[1].Item1.YCord);
            Assert.AreEqual(CompassDirection.E, stage.MowersWithMovementInstructions[1].Item1.Heading);
            StringAssert.IsMatch("MMRMMMRMRMM", stage.MowersWithMovementInstructions[1].Item2);

        }
コード例 #2
0
        public void LawnPlaceLawnMower_PassedLawnMowerWithXAndYAlreadyOccupied_ThrowsMowerPositionOccupiedException()
        {
            //Arrange            
            ILawn lawn = new Lawn(5, 5);
            var mower1 = new LawnMower(0, 0, CompassDirection.N, ref lawn);

            //Act
            //Assert
            Assert.Throws<Lawn.LawnMowerPositionOccupiedException>(() => new LawnMower(0, 0, CompassDirection.N, ref lawn));
        }
コード例 #3
0
        public void LawnPlaceMower_PassedLawnMowerWithXOrYOutOfRange_ThrowsIndexOutOfRangeException()
        {
            //Arrange            
            ILawn lawn = new Lawn(5, 5);
            var lawnMower = new LawnMower(1, 2, CompassDirection.N, ref lawn);

            //Act
            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => lawn.PlaceLawnMower(lawnMower, 6, 6));            
        }
コード例 #4
0
        public void LawnConstructor_Passed55_ReturnsLawnWithMowerPositonsXAndYlengthsOf6()
        {
            //Arrange
            //Act
            ILawn lawn = new Lawn(5,5);

            //Assert
            Assert.AreEqual(6, lawn.LawnMowerPostions.GetLength(0));
            Assert.AreEqual(6, lawn.LawnMowerPostions.GetLength(1));
        }
コード例 #5
0
        protected static ILawn GetLawn(string xYArgs)
        {
            if (string.IsNullOrEmpty(xYArgs))
                throw new ArgumentException("xYArgs cannot be null or string.empty");

            int x;
            int y;
            GetLawnMaxXy(xYArgs, out x, out y);

            var lawn = new Lawn(x, y);
            return lawn;
        }
コード例 #6
0
        public CompassDirection LawnMowerSetNewHeading_CalledWithCurrentHeadingAndARotation_SetsLawnMowerHeading(CompassDirection compassDirection, int rotation)
        {
            //Arrange
            ILawn lawn = new Lawn(5, 5);
            var lawnMower = new LawnMowerWithPublicMethods(0, 0, compassDirection, ref lawn);

            //Act
            lawnMower.SetNewHeading(rotation);

            //Assert
            return lawnMower.Heading;
        }