Пример #1
0
        /// <summary>
        /// Gets the fertile plots of land in ascending order as a single string
        /// </summary>
        /// <param name="plotsToSaltAsStrings">The plots to salt as a collection of strings, with each string representing an plot to salt</param>
        /// <returns>A single string containing the fertile plots, separated by a space, in ascending order</returns>
        public static string GetFertileLandsAsOrderedString(string[] plotsToSaltAsStrings)
        {
            _logger.Debug($"Entering {nameof(GetFertileLandsAsOrderedString)}");

            var pointFactory     = new PointFactory();
            var rectangleFactory = new RectangleFactory();
            var landFactory      = new LandFactory();

            var landDefinition = rectangleFactory.CreateRectangle(pointFactory, COLUMNS_OF_LAND, ROWS_OF_LAND);
            var land           = landFactory.CreateLand(landDefinition);

            // Salt the land
            var plotsToSalt = plotsToSaltAsStrings.Select(plotToSaltAsString => rectangleFactory.CreateRectangle(pointFactory, plotToSaltAsString));

            foreach (var plotToSalt in plotsToSalt)
            {
                land.AddSalt(plotToSalt);
            }

            // This line satisfies the output requirements
            string fertileLandAsOrderedString = string.Join(" ", land.FertilePlotsInSquareMeters.OrderBy(plot => plot));

            _logger.Debug($"Exiting {nameof(GetFertileLandsAsOrderedString)} with a return value of \"{fertileLandAsOrderedString}\"");
            return(fertileLandAsOrderedString);
        }
Пример #2
0
        public void Should_ReturnCorrectRectangle_When_LengthAndWidthAreValid()
        {
            var rectangleFactory = new RectangleFactory();
            var pointFactory     = new MockPointFactory(new Point(0, 0), new Point(30, 40));
            var rectangle        = rectangleFactory.CreateRectangle(pointFactory, 30, 40);

            Assert.AreEqual(0, rectangle.BottomLeft.X);
            Assert.AreEqual(0, rectangle.BottomLeft.Y);
            Assert.AreEqual(30, rectangle.BottomRight.X);
            Assert.AreEqual(0, rectangle.BottomRight.Y);
            Assert.AreEqual(30, rectangle.TopRight.X);
            Assert.AreEqual(40, rectangle.TopRight.Y);
            Assert.AreEqual(0, rectangle.TopLeft.X);
            Assert.AreEqual(40, rectangle.TopLeft.Y);
            Assert.AreEqual(30, rectangle.XLength);
            Assert.AreEqual(40, rectangle.YLength);
        }
Пример #3
0
        public void Should_ReturnCorrectRectangle_When_RectanglePointsStringIsValid()
        {
            var rectangleFactory = new RectangleFactory();
            var pointFactory     = new MockPointFactory(new Point(10, 23), new Point(34, 50));
            var rectangle        = rectangleFactory.CreateRectangle(pointFactory, "10 23 34 50");

            Assert.AreEqual(10, rectangle.BottomLeft.X);
            Assert.AreEqual(23, rectangle.BottomLeft.Y);
            Assert.AreEqual(34, rectangle.BottomRight.X);
            Assert.AreEqual(23, rectangle.BottomRight.Y);
            Assert.AreEqual(34, rectangle.TopRight.X);
            Assert.AreEqual(50, rectangle.TopRight.Y);
            Assert.AreEqual(10, rectangle.TopLeft.X);
            Assert.AreEqual(50, rectangle.TopLeft.Y);
            Assert.AreEqual(24, rectangle.XLength);
            Assert.AreEqual(27, rectangle.YLength);
        }
Пример #4
0
 public void Should_ThrowException_When_PointFactoryIsNull()
 {
     var rectangeFactory = new RectangleFactory();
     var rectangle       = rectangeFactory.CreateRectangle(null, "10 20 30 40");
 }
Пример #5
0
 public void Should_ThrowException_When_TooManyPointsAreEntered()
 {
     var rectangeFactory = new RectangleFactory();
     var rectangle       = rectangeFactory.CreateRectangle(new MockPointFactory(), "10 20 30 40 50");
 }
Пример #6
0
 public void Should_ThrowException_When_PointsAreEmpty()
 {
     var rectangeFactory = new RectangleFactory();
     var rectangle       = rectangeFactory.CreateRectangle(new MockPointFactory(), string.Empty);
 }
Пример #7
0
 public void Should_ThrowException_When_PointsAreNull()
 {
     var rectangeFactory = new RectangleFactory();
     var rectangle       = rectangeFactory.CreateRectangle(new MockPointFactory(), null);
 }