-
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
Заколюкин Степан #255
base: master
Are you sure you want to change the base?
Заколюкин Степан #255
Changes from 1 commit
3544016
00e0c4b
b442385
bef6b80
2aa2d08
d40d671
bc219ac
d5358bb
90aeca8
93d54c5
0bffa4d
9830897
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,8 @@ | |
<PackageReference Include="System.Drawing.Common" Version="9.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="TestErrorReports\" /> | ||
</ItemGroup> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот этот блок вроде как можно удалить |
||
|
||
</Project> |
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; | ||
|
@@ -9,6 +11,9 @@ namespace TagsCloudVisualization; | |
[TestFixture] | ||
public class CircularCloudLayouterTests | ||
{ | ||
private readonly static List<Rectangle> listRectangles = []; | ||
private readonly static CircularCloudLayouter cloudLayouter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. принято писать static readonly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. и статик не нужен И я не понял как это работает: readonly поле не задаётся, но в конце TearDown его пробрасывает и вызывает There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это поле тут оказалась лишним, оно не использовалось для создания визуализации, я добавил перегрузку метода и убрал его |
||
|
||
[Test] | ||
public void CircularCloudLayouter_CorrectInitialization_NoExceptions() | ||
{ | ||
|
@@ -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() | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
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.
Можно путь в константу вынести