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()); }
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)); }
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()); }
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(); }); }
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; } }
public void SetUp() { center = new Point(0, 0); spiral = new Spiral(center); spiralEnumerator = spiral.GetNextPoint().GetEnumerator(); spiralEnumerator.MoveNext(); }
public void Spiral_ShouldStartInCenter() { var center = new Point(10, 10); var spiral = new Spiral(center, 1, 1); spiral.GetNextPoint().Should().BeEquivalentTo(center); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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; } }
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); }
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); }
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); } }
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)); }
public void ReturnFirstPointAsCenter() { var firstPoint = spiral.GetNextPoint(); firstPoint.ShouldBeEquivalentTo(center); }