Skip to content
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
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
ad2d818
Initial TagsCloudVisualization commit
AlexxSaz Nov 9, 2024
e68c53d
Custom classes raplaced by system drawing lib
AlexxSaz Nov 11, 2024
f5e166b
Inited points generator class
AlexxSaz Nov 11, 2024
55e34ba
Added implementation to GetNewPoint and tests
AlexxSaz Nov 12, 2024
6d20961
PointGenerator refactored
AlexxSaz Nov 12, 2024
8056773
Implementation changed to use PointGenerator
AlexxSaz Nov 12, 2024
d667276
Refactored CircularCLoudLayouter
AlexxSaz Nov 12, 2024
9e1ec6f
Created extention method for Point
AlexxSaz Nov 12, 2024
898414c
Point generator refactored
AlexxSaz Nov 12, 2024
7e04cfb
Solution changed to tdd.sln
AlexxSaz Nov 13, 2024
903e69b
Point extension removed
AlexxSaz Nov 13, 2024
86704ff
Tests moved to special namespace
AlexxSaz Nov 13, 2024
d0636b7
Point generator tests refactored
AlexxSaz Nov 13, 2024
891e73d
Interface created
AlexxSaz Nov 13, 2024
8fdf444
Added new tests
AlexxSaz Nov 13, 2024
1320a4a
Created new project for tests
AlexxSaz Nov 15, 2024
91a0388
Created new interface
AlexxSaz Nov 15, 2024
fd798c6
Point generator tests moved to new project
AlexxSaz Nov 15, 2024
53157f1
Cloud layouter test moved and renamed
AlexxSaz Nov 15, 2024
9047c0e
TagCloud added
AlexxSaz Nov 16, 2024
e71f57f
Cherry picked extension for point
AlexxSaz Nov 12, 2024
0ac9619
Added extension for rectangle
AlexxSaz Nov 16, 2024
3ad22ea
Changed point extensions
AlexxSaz Nov 16, 2024
3b25de2
Fixed getting new rectangle in CircularCloudLayouter
AlexxSaz Nov 16, 2024
18aa897
TagCloud refactored
AlexxSaz Nov 16, 2024
0e7de68
PointGenerator refactored
AlexxSaz Nov 16, 2024
3843478
Some tests refactored
AlexxSaz Nov 16, 2024
e42563c
Added new tests to tag cloud
AlexxSaz Nov 17, 2024
055b888
Added test to check that layouter has circular form
AlexxSaz Nov 17, 2024
02a9b74
Added class that creates tag cloud example
AlexxSaz Nov 17, 2024
574bcc8
Installation of default objects has been changed
AlexxSaz Nov 17, 2024
f983fe4
Angle step changed
AlexxSaz Nov 17, 2024
692ce6c
Reworked layouter tests for new angle step
AlexxSaz Nov 17, 2024
677cdf9
Added visualization class
AlexxSaz Nov 17, 2024
5f6471e
Created samples and readme
AlexxSaz Nov 17, 2024
0647fae
GenereatePoint method reworked to pure method
AlexxSaz Nov 17, 2024
99b191c
Added teardown to save failed pictures
AlexxSaz Nov 17, 2024
7ee7523
Refactored layouter tests
AlexxSaz Nov 17, 2024
a777a93
CloudLayouter tests reworked
AlexxSaz Nov 17, 2024
2b4a1ed
Test replaced by program.cs
AlexxSaz Nov 17, 2024
72851ba
TagCloud properties reworked to constant time. But addRectangle isnt …
AlexxSaz Nov 17, 2024
a1d4e86
Replaced sample to random rectangles
AlexxSaz Nov 17, 2024
af5b600
PointGenerator test for spiral is reworked
AlexxSaz Nov 17, 2024
1acce94
Some things refactored
AlexxSaz Nov 17, 2024
936f24c
Rework method that returns new color
AlexxSaz Nov 18, 2024
20fbb7f
Added new class to generate sizes
AlexxSaz Nov 18, 2024
ceda81c
Fluent style changed
AlexxSaz Nov 19, 2024
8482ee9
CloudLayouter test fixed
AlexxSaz Nov 19, 2024
a18455d
Parallelizable accepted to whole project
AlexxSaz Nov 19, 2024
19ea2dc
Removed virtual method
AlexxSaz Nov 19, 2024
25352da
Tag cloud properties reworked to expression body
AlexxSaz Nov 19, 2024
57390e8
Fixed drawing lib problem
AlexxSaz Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cs/TagsCloudVisualization/TagsCloudVisualization.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TagsCloudVisualization", "TagsCloudVisualization\TagsCloudVisualization.csproj", "{9F1C8BD9-7ED7-4833-A0F8-15D7432DA72D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9F1C8BD9-7ED7-4833-A0F8-15D7432DA72D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F1C8BD9-7ED7-4833-A0F8-15D7432DA72D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F1C8BD9-7ED7-4833-A0F8-15D7432DA72D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F1C8BD9-7ED7-4833-A0F8-15D7432DA72D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {502A7689-9DFF-4F99-AB63-30F2D6000F56}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Drawing;

namespace TagsCloudVisualization;

public class CircularCloudLayouter(Point center)
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly PointGenerator _pointGenerator = new(center);
private readonly List<Rectangle> _rectangles = [];

public Rectangle PutNextRectangle(Size size)
{
if (size.Width < 1 || size.Height < 1)
throw new ArgumentOutOfRangeException(
$"{nameof(size.Width)} and {nameof(size.Height)} should be more than zero");
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved

Rectangle newRectangle;
do newRectangle = new Rectangle(_pointGenerator.GetNewPoint(), size);
while (_rectangles.Any(rec => newRectangle.IntersectsWith(rec)));

_rectangles.Add(newRectangle);
return newRectangle;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using FluentAssertions;
using NUnit.Framework;
using System.Drawing;

namespace TagsCloudVisualization;

[TestFixture]
public class CircularCloudLayouterShould
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
{
private Point _defaultCenter;
private CircularCloudLayouter _defaultCircularCloudLayouter;

[SetUp]
public void SetUp()
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
{
_defaultCenter = new Point(0, 0);
_defaultCircularCloudLayouter = new CircularCloudLayouter(_defaultCenter);
}

[TestCase(1, 1, 4, 2)]
public void PutNextRectangle_ReturnRectangleWithBaseCenter_AfterFirstExecutionWith(int x, int y, int width, int height)
{
var point = new Point(x, y);
var size = new Size(width, height);
var circularCloudLayouter = new CircularCloudLayouter(point);
var expectedRectangle = new Rectangle(point, size);

circularCloudLayouter.PutNextRectangle(size).Should().BeEquivalentTo(expectedRectangle);
}

[TestCase(-1, 1)]
[TestCase(1, -1)]
[TestCase(0, 0)]
public void PutNextRectangle_ThrowArgumentOutOfRangeException_AfterExecutionWith(int width, int height)
{
var size = new Size(width, height);
var action = () => _defaultCircularCloudLayouter.PutNextRectangle(size);
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved

action.Should().Throw<ArgumentOutOfRangeException>();
}

[Test]
public void PutNextRectangle_ReturnRectangleThatNotCrossingWithOther_AfterFewExecution()
{
var rnd = new Random();
var rectangleList = new List<Rectangle>();
var width = rnd.Next(5, 20);
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
var height = rnd.Next(2, 5);
var size = new Size(width, height);
for (var i = 0; i < 10; i++)
{
var currRectangle =
_defaultCircularCloudLayouter.PutNextRectangle(size);
rectangleList.Add(currRectangle);
}
var lastRectangle = rectangleList[^1];

for (var i = 0; i < rectangleList.Count - 1; i++)
{
var currRectangle = rectangleList[i];
lastRectangle.IntersectsWith(currRectangle).Should().BeFalse();
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

10 changes: 10 additions & 0 deletions cs/TagsCloudVisualization/TagsCloudVisualization/PointExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Drawing;

namespace TagsCloudVisualization;

public static class PointExtension
{
public static Point MoveTo(this Point point, Size direction) =>
Point.Add(point, direction);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Drawing;
using NUnit.Framework;
using FluentAssertions;

namespace TagsCloudVisualization;

public class PointExtensionShould
{
private Point _defaultPoint;

[SetUp]
public void SetUp()
{
_defaultPoint = new Point(0, 0);
}

[TestCase(5, 5)]
public void MoveTo_ReturnMovedPoint_AfterExecutionWith(int width, int height)
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
{
var direction = new Size(width, height);

var newPoint = _defaultPoint.MoveTo(direction);

newPoint.Should().NotBe(_defaultPoint);
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
}
}

28 changes: 28 additions & 0 deletions cs/TagsCloudVisualization/TagsCloudVisualization/PointGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Drawing;

namespace TagsCloudVisualization;
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
public class PointGenerator(Point centerPoint)
{
private const double AngleStep = Math.PI / 360;
private const double RadiusStep = 0.01;
private double _radius;
private double _angle;
private readonly Size _center = new(centerPoint);

public Point GetNewPoint()
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved
{
var newX = (int)(_radius * Math.Cos(_angle));
var newY = (int)(_radius * Math.Sin(_angle));
var newPoint = new Point(newX, newY).MoveTo(_center);

TakeAStep();
AlexxSaz marked this conversation as resolved.
Show resolved Hide resolved

return newPoint;
}

private void TakeAStep()
{
_angle += AngleStep;
_radius += RadiusStep;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using NUnit.Framework;
using FluentAssertions;
using System.Drawing;

namespace TagsCloudVisualization;

[TestFixture]
public class PointGeneratorShould

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хочется тестов на

Некоторые требования к раскладке:
Форма итогового облака должна быть близка к кругу с центром в точке center.
Прямоугольники не должны пересекаться друг с другом.
Облако должно быть плотным, чем плотнее, тем лучше.

{
private PointGenerator _defaultPointGenerator;
private Point _defaultCenter;

[SetUp]
public void SetUp()
{
_defaultCenter = new Point(5, 2);
_defaultPointGenerator = new PointGenerator(_defaultCenter);
}

[Test]
public void GetNewPoint_ReturnCenter_AfterFirstExecution()
{
var point = _defaultPointGenerator.GetNewPoint();

point.Should().BeEquivalentTo(_defaultCenter);
}

[TestCase(1000)]
[TestCase(0)]
[TestCase(10000)]
public void GetNewPoint_ReturnUniqPointEvery100Step_AfterExecution(int stepCount)
{
const int stepToCheck = 100;
var pointsHashset = new HashSet<Point>();

for (var i = 1; i <= stepCount; i++)
{
var currPoint = _defaultPointGenerator.GetNewPoint();
if (i % stepToCheck == 0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему именно 100 шаг? Пока не понимаю, что проверяет этот тест в таких органичениях

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я все еще не понимаю, зачем конструкция if (i % radiusCheckPeriod != 0) continue; )

pointsHashset.Add(currPoint);
}

pointsHashset.Should().HaveCount(stepCount / stepToCheck);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

</Project>