-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Сазонов Александр #237
Open
AlexxSaz
wants to merge
52
commits into
kontur-courses:master
Choose a base branch
from
AlexxSaz:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Сазонов Александр #237
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
ad2d818
Initial TagsCloudVisualization commit
AlexxSaz e68c53d
Custom classes raplaced by system drawing lib
AlexxSaz f5e166b
Inited points generator class
AlexxSaz 55e34ba
Added implementation to GetNewPoint and tests
AlexxSaz 6d20961
PointGenerator refactored
AlexxSaz 8056773
Implementation changed to use PointGenerator
AlexxSaz d667276
Refactored CircularCLoudLayouter
AlexxSaz 9e1ec6f
Created extention method for Point
AlexxSaz 898414c
Point generator refactored
AlexxSaz 7e04cfb
Solution changed to tdd.sln
AlexxSaz 903e69b
Point extension removed
AlexxSaz 86704ff
Tests moved to special namespace
AlexxSaz d0636b7
Point generator tests refactored
AlexxSaz 891e73d
Interface created
AlexxSaz 8fdf444
Added new tests
AlexxSaz 1320a4a
Created new project for tests
AlexxSaz 91a0388
Created new interface
AlexxSaz fd798c6
Point generator tests moved to new project
AlexxSaz 53157f1
Cloud layouter test moved and renamed
AlexxSaz 9047c0e
TagCloud added
AlexxSaz e71f57f
Cherry picked extension for point
AlexxSaz 0ac9619
Added extension for rectangle
AlexxSaz 3ad22ea
Changed point extensions
AlexxSaz 3b25de2
Fixed getting new rectangle in CircularCloudLayouter
AlexxSaz 18aa897
TagCloud refactored
AlexxSaz 0e7de68
PointGenerator refactored
AlexxSaz 3843478
Some tests refactored
AlexxSaz e42563c
Added new tests to tag cloud
AlexxSaz 055b888
Added test to check that layouter has circular form
AlexxSaz 02a9b74
Added class that creates tag cloud example
AlexxSaz 574bcc8
Installation of default objects has been changed
AlexxSaz f983fe4
Angle step changed
AlexxSaz 692ce6c
Reworked layouter tests for new angle step
AlexxSaz 677cdf9
Added visualization class
AlexxSaz 5f6471e
Created samples and readme
AlexxSaz 0647fae
GenereatePoint method reworked to pure method
AlexxSaz 99b191c
Added teardown to save failed pictures
AlexxSaz 7ee7523
Refactored layouter tests
AlexxSaz a777a93
CloudLayouter tests reworked
AlexxSaz 2b4a1ed
Test replaced by program.cs
AlexxSaz 72851ba
TagCloud properties reworked to constant time. But addRectangle isnt …
AlexxSaz a1d4e86
Replaced sample to random rectangles
AlexxSaz af5b600
PointGenerator test for spiral is reworked
AlexxSaz 1acce94
Some things refactored
AlexxSaz 936f24c
Rework method that returns new color
AlexxSaz 20fbb7f
Added new class to generate sizes
AlexxSaz ceda81c
Fluent style changed
AlexxSaz 8482ee9
CloudLayouter test fixed
AlexxSaz a18455d
Parallelizable accepted to whole project
AlexxSaz 19ea2dc
Removed virtual method
AlexxSaz 25352da
Tag cloud properties reworked to expression body
AlexxSaz 57390e8
Fixed drawing lib problem
AlexxSaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using FluentAssertions; | ||
using System.Drawing; | ||
using FluentAssertions.Execution; | ||
using TagsCloudVisualization; | ||
using TagsCloudVisualization.Extensions; | ||
using TagsCloudVisualization.Interfaces; | ||
|
||
[assembly: Parallelizable(ParallelScope.Children)] | ||
|
||
namespace TagsCloudTests; | ||
|
||
[TestFixture] | ||
public class CloudLayouterShould | ||
{ | ||
private readonly Point _defaultCenter = new(0, 0); | ||
AlexxSaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private readonly Random _random = new(); | ||
private readonly ISizesGenerator _defaultSizesGenerator = new RandomSizesGenerator(); | ||
|
||
[Test] | ||
[Repeat(5)] | ||
public void PutNextRectangle_ReturnRectangleWithExpectedLocation_AfterFirstExecution() | ||
{ | ||
var expectedCenter = new Point(_random.Next(-10, 10), _random.Next(-10, 10)); | ||
var rectangleSize = _defaultSizesGenerator | ||
.GenerateSize() | ||
.Take(1) | ||
.First(); | ||
var cloudLayouter = new CircularCloudLayouter(expectedCenter); | ||
|
||
var actualRectangle = cloudLayouter.PutNextRectangle(rectangleSize); | ||
|
||
actualRectangle | ||
.GetCentralPoint() | ||
.Should() | ||
.BeEquivalentTo(expectedCenter); | ||
} | ||
|
||
[TestCase(-1, 1)] | ||
[TestCase(1, -1)] | ||
[TestCase(0, 0)] | ||
public void PutNextRectangle_ThrowArgumentOutOfRangeException_AfterExecutionWith(int width, int height) | ||
{ | ||
var rectangleSize = new Size(width, height); | ||
var circularCloudLayouter = new CircularCloudLayouter(_defaultCenter); | ||
|
||
var executePutNewRectangle = () => | ||
circularCloudLayouter | ||
.PutNextRectangle(rectangleSize); | ||
|
||
executePutNewRectangle | ||
.Should() | ||
.Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Test] | ||
[Repeat(5)] | ||
public void PutNextRectangle_ReturnRectangleThatNotIntersectsWithOther_AfterManyExecution() | ||
{ | ||
var rectangleSizes = _defaultSizesGenerator | ||
.GenerateSize() | ||
.Take(_random.Next(10, 200)); | ||
var cloudLayouter = new CircularCloudLayouter(_defaultCenter); | ||
|
||
var rectangles = rectangleSizes | ||
.Select(size => cloudLayouter.PutNextRectangle(size)) | ||
.ToArray(); | ||
|
||
for (var i = 0; i < rectangles.Length; i++) | ||
for (var j = i + 1; j < rectangles.Length; j++) | ||
rectangles[i] | ||
.IntersectsWith(rectangles[j]) | ||
.Should() | ||
.BeFalse(); | ||
} | ||
|
||
[Test] | ||
[Repeat(20)] | ||
public void PutNextRectangle_ReturnRectanglesInCircle_AfterManyExecution() | ||
{ | ||
var rectangleSizes = _defaultSizesGenerator | ||
.GenerateSize() | ||
.Take(_random.Next(100, 200)); | ||
var circularCloudLayouter = new CircularCloudLayouter(_defaultCenter); | ||
|
||
var rectanglesList = rectangleSizes | ||
.Select(rectangleSize => circularCloudLayouter | ||
.PutNextRectangle(rectangleSize)) | ||
.ToList(); | ||
|
||
var circleRadius = rectanglesList | ||
.Select(rectangle => rectangle.GetCentralPoint()) | ||
.Max(pointOnCircle => pointOnCircle.GetDistanceTo(_defaultCenter)); | ||
var fromRectangleToCenterDistances = | ||
rectanglesList | ||
.Select(rectangle => rectangle | ||
.GetCentralPoint() | ||
.GetDistanceTo(_defaultCenter)); | ||
|
||
var sumRectanglesSquare = rectanglesList.Sum(rectangle => rectangle.Width * rectangle.Height); | ||
var circleSquare = circleRadius * circleRadius * Math.PI; | ||
var precision = circleSquare * 0.375; | ||
|
||
using (new AssertionScope()) | ||
{ | ||
circleSquare | ||
.Should() | ||
.BeApproximately(sumRectanglesSquare, precision); | ||
foreach (var distanceToCenter in fromRectangleToCenterDistances) | ||
distanceToCenter | ||
.Should() | ||
.BeLessOrEqualTo(circleRadius); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Drawing; | ||
using FluentAssertions; | ||
using TagsCloudVisualization.Extensions; | ||
|
||
namespace TagsCloudTests; | ||
|
||
[TestFixture] | ||
public class PointExtensionShould | ||
{ | ||
[TestCase(0, 0, 1, 2)] | ||
[TestCase(0, 0, 1, 0)] | ||
[TestCase(3, 5, 0, 5)] | ||
public void PointShiftTo_ReturnedMovedPoint_WhenSet(int pointX, int pointY, int shiftX, int shiftY) | ||
{ | ||
var point = new Point(pointX, pointY); | ||
var movementDirection = new Size(shiftX, shiftY); | ||
|
||
var movedPoint = Point.Add(point, movementDirection); | ||
|
||
MoveTo_CheckShift(point, movementDirection, movedPoint); | ||
} | ||
|
||
[Test] | ||
public void MoveTo_ReturnedNotMovedPoint_WhenSetZeroDirection() | ||
{ | ||
var point = new Point(5, 6); | ||
|
||
MoveTo_CheckShift(point, new Size(0, 0), point); | ||
} | ||
|
||
private static void MoveTo_CheckShift(Point point, Size movementDirection, Point expectedPoint) | ||
{ | ||
var movedPoint = point.MoveTo(movementDirection); | ||
|
||
movedPoint | ||
.Should() | ||
.BeEquivalentTo(expectedPoint); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Drawing; | ||
using FluentAssertions; | ||
using TagsCloudVisualization; | ||
using TagsCloudVisualization.Extensions; | ||
using TagsCloudVisualization.Interfaces; | ||
|
||
namespace TagsCloudTests; | ||
|
||
[TestFixture] | ||
public class PointGeneratorShould | ||
{ | ||
private readonly Point _defaultCenter = new(1, 1); | ||
private readonly Random _random = new(); | ||
|
||
[Test] | ||
public void GetNewPoint_ReturnCenter_AfterFirstExecution() | ||
{ | ||
var pointGenerator = new SpiralPointGenerator(_defaultCenter); | ||
using var newPointIterator = pointGenerator | ||
.GeneratePoint() | ||
.GetEnumerator(); | ||
newPointIterator.MoveNext(); | ||
var point = newPointIterator.Current; | ||
|
||
point | ||
.Should() | ||
.BeEquivalentTo(_defaultCenter); | ||
} | ||
|
||
[TestCase(0)] | ||
[TestCase(-1)] | ||
public void ThrowArgumentOutOfRangeException_AfterExecutionWith(double radiusStep) | ||
{ | ||
var pointGeneratorCreate = () => new SpiralPointGenerator(_defaultCenter, radiusStep); | ||
|
||
pointGeneratorCreate | ||
.Should() | ||
.Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Test] | ||
[Repeat(20)] | ||
public void GetNewPoint_ReturnPointWithGreaterRadius_AfterManyExecutions() | ||
{ | ||
var newPointGenerator = new SpiralPointGenerator(_defaultCenter); | ||
var countOfPoints = _random.Next(10, 200); | ||
var points = newPointGenerator | ||
.GeneratePoint() | ||
.Take(countOfPoints) | ||
.ToArray(); | ||
|
||
var distances = points | ||
.Select(p => p.GetDistanceTo(_defaultCenter)) | ||
.ToArray(); | ||
var angles = points | ||
.Select(p => Math.Atan2(p.Y - _defaultCenter.Y, p.X - _defaultCenter.X)) | ||
.ToArray(); | ||
|
||
distances | ||
.Zip(distances.Skip(1), (a, b) => a <= b) | ||
.All(x => x) | ||
.Should() | ||
.BeTrue(); | ||
angles | ||
.Zip(angles.Skip(1), (a, b) => a <= b || Math.Abs(a - b) < 0.1) | ||
.All(x => x) | ||
.Should() | ||
.BeTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Drawing; | ||
using FluentAssertions; | ||
using TagsCloudVisualization.Extensions; | ||
|
||
namespace TagsCloudTests; | ||
|
||
[TestFixture] | ||
public class RectangleExtensionShould | ||
{ | ||
[Test] | ||
[Repeat(5)] | ||
public void GetCentralPoint_ReturnExpectedCenter_AfterExecutionWithRandomRectangle() | ||
{ | ||
var rectangleLocation = new Point(0, 0); | ||
var random = new Random(); | ||
var rectangleSize = new Size(random.Next(1, 100), random.Next(1, 100)); | ||
var rectangle = new Rectangle(rectangleLocation, rectangleSize); | ||
var expectedCentralPoint = new Point(rectangleLocation.X + rectangleSize.Width / 2, | ||
rectangleLocation.Y - rectangleSize.Height / 2); | ||
|
||
rectangle | ||
.GetCentralPoint() | ||
.Should() | ||
.Be(expectedCentralPoint); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Drawing; | ||
using FluentAssertions; | ||
using TagsCloudVisualization; | ||
|
||
namespace TagsCloudTests; | ||
|
||
[TestFixture] | ||
public class TagCloudCreatorShould | ||
{ | ||
private readonly Point _defaultCenter = new(0, 0); | ||
private readonly Random _random = new(); | ||
|
||
[Test] | ||
[Repeat(5)] | ||
public void Create_ReturnTagCloudEquivalentToConstructor_AfterExecution() | ||
{ | ||
var sizesGenerator = new RandomSizesGenerator(); | ||
var rectangleSizes = sizesGenerator | ||
.GenerateSize() | ||
.Take(_random.Next(10, 200)) | ||
.ToArray(); | ||
var currCloudLayouter = new CircularCloudLayouter(_defaultCenter); | ||
var expectedCloudLayouter = new CircularCloudLayouter(_defaultCenter); | ||
var defaultTagCloud = new TagCloud(currCloudLayouter); | ||
foreach (var rectangleSize in rectangleSizes) | ||
defaultTagCloud.AddNextRectangleWith(rectangleSize); | ||
|
||
var expectedTagCloud = TagCloudCreator.Create(rectangleSizes, expectedCloudLayouter); | ||
AlexxSaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
defaultTagCloud | ||
.Should() | ||
.BeEquivalentTo(expectedTagCloud); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не нашел тестов на :
Если такие есть, отпиши в этом комменте их названия и логику работы. Потому что те, что я нашел, как будто не проверяют все эти требования
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Переписал тесты. В новых коммитах:
тест PutNextRectangle_ReturnRectanglesInCircle_AfterManyExecution проверяет, что сумма площади всех прямоугольников примерно равна площади окружности, в которой прямоугольники находятся. А также, что расстояние от каждого прямоугольника до центра лейаута меньше, чем радиус окружности. Этот тест говорит о том, что форма облака - окружность, а также, что облако максимально плотное.
тест PutNextRectangle_ReturnRectangleThatNotIntersectsWithOther_AfterManyExecution проверяет, что каждый из прямоугольников на лейауте не пересекается со всеми остальными прямоугольниками, кроме себя самого.