Ejemplo n.º 1
0
        public void GetNextPoint_ReturnOtherPoint_WhenNotFirstCall()
        {
            var    center = new Point(22, 22);
            Spiral spiral = new Spiral(center);

            var nextPoint = spiral.GetNextPoint();

            nextPoint.Should().NotBeEquivalentTo(spiral.GetNextPoint());
        }
Ejemplo n.º 2
0
        public void GetNextPoint_ShouldReturnCorrectPoints_AfterSomeSteps()
        {
            var center = new Point(0, 0);
            var spiral = new Spiral(center, 4, 0.5 * Math.PI);

            spiral.GetNextPoint().Should().BeEquivalentTo(new Point(0, 0));
            spiral.GetNextPoint().Should().BeEquivalentTo(new Point(0, 1));
            spiral.GetNextPoint().Should().BeEquivalentTo(new Point(-2, 0));
            spiral.GetNextPoint().Should().BeEquivalentTo(new Point(0, -3));
            spiral.GetNextPoint().Should().BeEquivalentTo(new Point(4, 0));
        }
Ejemplo n.º 3
0
        public void ResetEnumeration_ThenResetMethodCalled(int steps)
        {
            var spiral = new Spiral();
            var first  = spiral.GetNextPoint();

            for (var i = 0; i < steps; i++)
            {
                spiral.GetNextPoint();
            }
            spiral.Reset();

            first.Should().Be(spiral.GetNextPoint());
        }
Ejemplo n.º 4
0
        public void throwException_IfRectangleCannotBePutOnCloud()
        {
            var spiral = new Spiral(new Point(2, 2), 4, 4, 0.001, 10);

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                while (spiral.CurrentRadius <= spiral.MaxRadius)
                {
                    spiral.GetNextPoint();
                }
                spiral.GetNextPoint();
            });
        }
Ejemplo n.º 5
0
        public void Spiral_ShouldIncreaseDistanceFromCenter_AfterSomeSteps()
        {
            var center = new Point(0, 0);
            var spiral = new Spiral(center, 100, 0.05 * Math.PI);

            var prevDistance = GetDistance(spiral.GetNextPoint(), center);

            for (var i = 0; i < 100; i++)
            {
                var newDistance = GetDistance(spiral.GetNextPoint(), center);
                newDistance.Should().BeGreaterThan(prevDistance);
                prevDistance = newDistance;
            }
        }
Ejemplo n.º 6
0
 public void SetUp()
 {
     center           = new Point(0, 0);
     spiral           = new Spiral(center);
     spiralEnumerator = spiral.GetNextPoint().GetEnumerator();
     spiralEnumerator.MoveNext();
 }
Ejemplo n.º 7
0
        public void Spiral_ShouldStartInCenter()
        {
            var center = new Point(10, 10);
            var spiral = new Spiral(center, 1, 1);

            spiral.GetNextPoint().Should().BeEquivalentTo(center);
        }
Ejemplo n.º 8
0
        public void GetNextPoint_ShouldContainPointsFromSpiral_OnCorrespondingInput(int expectedPointShift)
        {
            const int   parameter     = 2;
            const float stepInRadians = (float)(Math.PI / 6);
            var         expectedPoint = GeometryUtils.ConvertPolarToIntegerCartesian(
                parameter * stepInRadians * expectedPointShift,
                stepInRadians * expectedPointShift);
            var spiral = new Spiral(parameter, 30);

            for (var i = 0; i < expectedPointShift; i++)
            {
                spiral.GetNextPoint();
            }
            var pointFromSpiral = spiral.GetNextPoint();

            pointFromSpiral.Should().Be(expectedPoint);
        }
Ejemplo n.º 9
0
        public void GetNextPoint_ReturnCenterPoint_WhenFirstCall()
        {
            var center   = new Point(22, 22);
            var settings = new SpiralSettings(center);
            var spiral   = new Spiral(settings);

            var nextPoint = spiral.GetNextPoint();

            nextPoint.Should().BeEquivalentTo(center);
        }
Ejemplo n.º 10
0
        public void GetNextPoint_ReturnPointСorrespondsSpiral_WhenManyCalls()
        {
            var    spiralPoints         = new List <Point>();
            var    center               = new Point(22, 22);
            Spiral spiral               = new Spiral(center);
            var    expectedSpiralPoints = new List <Point>
            {
                new Point(22, 22),
                new Point(21, 22),
                new Point(21, 21),
                new Point(22, 21)
            };

            spiralPoints.Add(spiral.GetNextPoint());
            spiralPoints.Add(spiral.GetNextPoint());
            spiralPoints.Add(spiral.GetNextPoint());
            spiralPoints.Add(spiral.GetNextPoint());

            spiralPoints.Should().BeEquivalentTo(expectedSpiralPoints);
        }
Ejemplo n.º 11
0
        public void GetQuadrant_ShouldReturnCorrectQuadrant_AfterSomeSteps()
        {
            var center = new Point(0, 0);
            var spiral = new Spiral(center, 100, 0.25 * Math.PI);

            spiral.GetNextPoint();
            spiral.GetNextPoint();
            spiral.Quadrant.Should().BeEquivalentTo(Quadrant.Top);
            spiral.GetNextPoint();
            spiral.GetNextPoint();
            spiral.Quadrant.Should().BeEquivalentTo(Quadrant.Left);
            spiral.GetNextPoint();
            spiral.GetNextPoint();
            spiral.Quadrant.Should().BeEquivalentTo(Quadrant.Bottom);
            spiral.GetNextPoint();
            spiral.GetNextPoint();
            spiral.Quadrant.Should().BeEquivalentTo(Quadrant.Right);
            spiral.GetNextPoint();
            spiral.GetNextPoint();
            spiral.Quadrant.Should().BeEquivalentTo(Quadrant.Top);
        }
Ejemplo n.º 12
0
        public void ReturnCenter_ThenGettingFirstPoint(int x, int y)
        {
            var center = new Point(x, y);

            sut.SetCenter(center);

            var result = sut.GetNextPoint();

            result.Should().Be(center);
        }
Ejemplo n.º 13
0
        public void ReturnPointsInAlmostCircleWay()
        {
            var spiral = new Spiral();
            var points = new Point[100];

            for (var i = 0; i < points.Length; i++)
            {
                points[i] = spiral.GetNextPoint();
            }
            var size = points.GetBounds().Size;

            size.Width.Should().BeCloseTo(size.Height, 10);
        }
Ejemplo n.º 14
0
        private Rectangle GetNewRectangle(Size rectangleSize)
        {
            Rectangle rectangle;

            do
            {
                var location = Spiral.GetNextPoint();
                rectangle = new Rectangle(location, rectangleSize);
            } while (Collided(rectangle));

            rectangle = MoveCloserToCenter(rectangle);
            Rectangles.Add(rectangle);

            return(rectangle);
        }
Ejemplo n.º 15
0
        public void GetNextPoint_DistanceBetweenEveryNextPointAndCenter_ShouldBeLargerThanPrevious()
        {
            var maximumRadiusDifference = 2;
            var pointsToCheck           = spiral.GetNextPoint().Take(100).ToArray();
            var previousPoint           = pointsToCheck.First();

            foreach (var point in pointsToCheck.Skip(1))
            {
                var currentDistanceToCenter  = CalculateDistanceToCenter(point);
                var previousDistanceToCenter = CalculateDistanceToCenter(previousPoint);
                var radiusDifference         = currentDistanceToCenter - previousDistanceToCenter;
                radiusDifference.Should().BeLessThan(maximumRadiusDifference);
                previousPoint = point;
            }
        }
Ejemplo n.º 16
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            Rectangle nextRectangle;

            do
            {
                nextRectangle = new Rectangle(Spiral.GetNextPoint(), rectangleSize);
            }while (Rectangles.Any(r => r.IntersectsWith(nextRectangle)));

            if (NeedingShiftToCenter)
            {
                nextRectangle = GetShiftedToCenterRectangle(nextRectangle);
            }
            Rectangles.Add(nextRectangle);
            return(nextRectangle);
        }
Ejemplo n.º 17
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            Rectangle nextRectangle;

            do
            {
                var center    = Spiral.GetNextPoint();
                var leftAngle = new Point(center.X - rectangleSize.Width / 2, center.Y - rectangleSize.Height / 2);
                nextRectangle = new Rectangle(leftAngle, rectangleSize);
            } while (Rectangles.Any(r => r.IntersectsWith(nextRectangle)));

            if (NeedingShiftToCenter)
            {
                nextRectangle = GetShiftedToCenterRectangle(nextRectangle);
            }
            Rectangles.Add(nextRectangle);
            return(nextRectangle);
        }
Ejemplo n.º 18
0
        public bool TryPutNextRectangle(Size rectangleSize)
        {
            try
            {
                if (rectangleSize.Width > Width || rectangleSize.Height > Height)
                {
                    throw new ArgumentException();
                }
                if (Rectangles.Count == 0)
                {
                    var rectangleCenter   = new Point(rectangleSize.Width / 2, rectangleSize.Height / 2);
                    var rectangleLocation = new Point(CenterPoint.X - rectangleCenter.X,
                                                      CenterPoint.Y - rectangleCenter.Y);
                    var firstRectangle = new Rectangle(rectangleLocation, rectangleSize);
                    Rectangles.Add(firstRectangle);

                    return(true);
                }
                while (true)
                {
                    var nextPoint = Spiral.GetNextPoint();
                    if (GeometryHelper.IsIncorrectPoint(nextPoint, Width, Height))
                    {
                        continue;
                    }
                    var currentRectangle = new Rectangle(nextPoint, rectangleSize);
                    if (IsPossiblePutRectangle(currentRectangle))
                    {
                        currentRectangle = ShiftRectangleToCenter(currentRectangle);
                        Rectangles.Add(currentRectangle);
                        return(true);
                    }
                }
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 19
0
        public void createCorrectPoints()
        {
            var densityOfSpirals = 0.01;
            var deltaInDegrees   = 10;
            var centerPoint      = new Point(50, 50);
            var spiral           = new Spiral(centerPoint, 100, 100, densityOfSpirals, deltaInDegrees);

            var pointsOfSpiral = new List <Point>();

            while (spiral.CurrentRadius < 25)
            {
                pointsOfSpiral.Add(spiral.GetNextPoint());
            }
            //90 градусов => радиус примерно 90*(0.01+0.001*9) = 1
            pointsOfSpiral.Should().Contain(new Point(centerPoint.X, centerPoint.Y + 1));
            //180 градусов => радиус примерно 180*(0.01+0.001*18) = 5
            pointsOfSpiral.Should().Contain(new Point(centerPoint.X - 5, centerPoint.Y));
            //270 градусов => радиус примерно 270*(0.01+0.001*27) = 10
            pointsOfSpiral.Should().Contain(new Point(centerPoint.X, centerPoint.Y - 10));
            //360 градусов => радиус примерно 360*(0.01+0.001*36) = 4
            pointsOfSpiral.Should().Contain(new Point(centerPoint.X + 17, centerPoint.Y));
            //450 градусов => радиус примерно 450*(0.01+0.001*45) = 25
            pointsOfSpiral.Should().Contain(new Point(centerPoint.X, centerPoint.Y + 25));
        }
Ejemplo n.º 20
0
        public void ReturnFirstPointAsCenter()
        {
            var firstPoint = spiral.GetNextPoint();

            firstPoint.ShouldBeEquivalentTo(center);
        }