예제 #1
0
        public void GivenAPointInsideRectangle_WhenValidatingIfIsOverlapping_ThenWillReturnTrue()
        {
            var rectangularPolygon = RectangularBattlefieldArea.FromLTRB(0, 0, 2, 2);
            var point = new Point(1, 1);

            Assert.That(rectangularPolygon.Contains(point), Is.True);
        }
예제 #2
0
        public void GivenAPointOutsideOfRectangle_WhenValidatingIfIsOverlapping_ThenWillReturnFalse(int x, int y)
        {
            var rectangularPolygon = RectangularBattlefieldArea.FromLTRB(0, 0, 2, 2);
            var point = new Point(x, y);

            Assert.That(rectangularPolygon.Contains(point), Is.False);
        }
예제 #3
0
        public void GivenAnInstance_WhenConvertingToString_ThenWillBeInExpectedFormat()
        {
            var rectangularPolygon = RectangularBattlefieldArea.FromLTRB(0, 0, 2, 2);

            var stringValue = rectangularPolygon.ToString();

            Assert.That(stringValue, Is.EqualTo("RectangularBattlefieldArea: {X=0,Y=0,Width=2,Height=2}"));
        }
        /// <summary>
        ///     Processes the specified line and loads the appropriate resources in the battlefield context.
        /// </summary>
        /// <param name="battlefieldContext">The battlefield context.</param>
        /// <param name="line">The parsed line.</param>
        /// <exception cref="FormatException">
        /// </exception>
        public void Process(IBattlefieldCreationContext battlefieldContext, string line)
        {
            var elements = line
                           .Split(' ')
                           .Where(element => !string.IsNullOrEmpty(element))
                           .ToList();

            ValidateElementsCount(line, elements);
            var x = ValidateIntegerParameter(line, elements[0], "first");

            ValidatePositiveInteger(line, x, "first");
            var y = ValidateIntegerParameter(line, elements[1], "second");

            ValidatePositiveInteger(line, y, "second");

            var battlefield = RectangularBattlefieldArea.FromLTRB(0, 0, x, y);

            battlefieldContext.SetBattlefieldArea(battlefield);
        }