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

Заколюкин Степан #255

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions cs/TagsCloudVisualization/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ static void Main(string[] args)

var visual = new VisualizationCloudLayout(800, 600, Color.White, colors);

visual.CreateAnImage(new Point(400, 300), 175, 30, 100, 5, 25)
visual.CreateAnImage(new CircularCloudLayouter(new Point(400, 300)), 175, 30, 100, 5, 25)
.Save("../../../../TagsCloudVisualization/Task 2/CentralСloud.png");

visual.CreateAnImage(new Point(250, 150), 50, 30, 80, 5, 25)
visual.CreateAnImage(new CircularCloudLayouter(new Point(250, 150)), 50, 30, 80, 5, 25)
.Save("../../../../TagsCloudVisualization/Task 2/SmalСloud.png");
Copy link

Choose a reason for hiding this comment

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

Можно путь в константу вынести

}
}
4 changes: 4 additions & 0 deletions cs/TagsCloudVisualization/TagsCloudVisualization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="TestErrorReports\" />
</ItemGroup>
Copy link

Choose a reason for hiding this comment

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

Вот этот блок вроде как можно удалить


</Project>
28 changes: 25 additions & 3 deletions cs/TagsCloudVisualization/Task 1,3/CircularCloudLayouterTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using FluentAssertions;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using System.Drawing;
using TagsCloudVisualization.Task_2;


namespace TagsCloudVisualization;
Expand All @@ -9,6 +11,9 @@ namespace TagsCloudVisualization;
[TestFixture]
public class CircularCloudLayouterTests
{
private readonly static List<Rectangle> listRectangles = [];
private readonly static CircularCloudLayouter cloudLayouter;
Copy link

Choose a reason for hiding this comment

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

принято писать static readonly

Copy link

Choose a reason for hiding this comment

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

и статик не нужен

И я не понял как это работает: readonly поле не задаётся, но в конце TearDown его пробрасывает и вызывает

Copy link
Author

Choose a reason for hiding this comment

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

Это поле тут оказалась лишним, оно не использовалось для создания визуализации, я добавил перегрузку метода и убрал его


[Test]
public void CircularCloudLayouter_CorrectInitialization_NoExceptions()
{
Expand Down Expand Up @@ -41,15 +46,14 @@ public void PutNextRectangle_RandomSizes_MustBeTheRightSize()
[Test]
public void PutNextRectangle_RandomSizes_ShouldNotIntersect()
{
var cloud = new CircularCloudLayouter(new Point(960, 540));
var listRectangles = new List<Rectangle>();
var cloudLayouter = new CircularCloudLayouter(new Point(960, 540));
var random = new Random();

for (int i = 0; i < 100; i++)
{
var width = random.Next(30, 200);

var rectangle = cloud.PutNextRectangle(new(width, random.Next(width / 6, width / 3)));
var rectangle = cloudLayouter.PutNextRectangle(new(width, random.Next(width / 6, width / 3)));

listRectangles.Any(rect => rect.IntersectsWith(rectangle))
.Should()
Expand All @@ -58,4 +62,22 @@ public void PutNextRectangle_RandomSizes_ShouldNotIntersect()
listRectangles.Add(rectangle);
}
}

[TearDown]
public void CreateReportInCaseOfAnError()
{
if (TestContext.CurrentContext.Result.Outcome == ResultState.Failure)
{
var colors = new[] { Color.Red, Color.Green, Color.Brown, Color.Yellow, Color.Blue };
var path = "../../../../TagsCloudVisualization/TestErrorReports/сloud.png";
var visual = new VisualizationCloudLayout(1920, 1080, Color.White, colors);

visual.CreateAnImage(cloudLayouter, 175, 30, 100, 5, 25, listRectangles)
Copy link

Choose a reason for hiding this comment

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

Вообще по хорошему следует передавать не layouter, а результат его работы, тк TearDown это уже доп операции с отчетом о тестах, отрубом баз данных, если были использованы, итд.

И в принципе передавать в аргументы объект, который совершает действие, это не хорошо, такого следует избегать. Делегаты - "вы не понимаете, это другое", тк там чаще всего передают функцию, совершающую мелкие и сходу понятные действия типа фильтрации или аггрегирования

.Save(path);

Console.WriteLine($"Tag cloud visualization saved to file {Path.GetFullPath(path)}");
}

listRectangles.Clear();
}
}
Binary file modified cs/TagsCloudVisualization/Task 2/CentralСloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified cs/TagsCloudVisualization/Task 2/SmalСloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions cs/TagsCloudVisualization/Task 2/VisualizationCloudLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ public VisualizationCloudLayout(int width, int height, Color backgroundColor, IE
RectanglePalette = rectanglePalette.ToArray();
}

public Bitmap CreateAnImage(Point center, int amountRectangles,
public Bitmap CreateAnImage(CircularCloudLayouter cloudLayouter, int amountRectangles,
Copy link

Choose a reason for hiding this comment

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

Ну и тут тоже CreateImage

int startWidthRectangles, int endWidthRectangles,
int startHeightRectangles, int endHeightRectangles)
int startHeightRectangles, int endHeightRectangles, IEnumerable<Rectangle> rectangles = null)
{
var image = new Bitmap(Width, Height);
var rectangles = CloudLayout.GenerateCloudLayout(

rectangles = rectangles ?? CloudLayout.GenerateCloudLayout(
amountRectangles,
startWidthRectangles, endWidthRectangles,
startHeightRectangles, endHeightRectangles,
new CircularCloudLayouter(center));
cloudLayouter);
var graphics = Graphics.FromImage(image);

DrawCloudLayout(graphics, rectangles);
Expand Down