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

Ватлин Алексей #242

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Alex-Vay
Copy link

@Alex-Vay Alex-Vay commented Nov 13, 2024

@SlavikGh0st
Решенные 3 задания с примерами работы программы (вид количество фигур/шаг/угол). Также при запуске и провале теста создаются соответствующие изображения в bin\Debug\net8.0+нужная директория внутри папок самих проектов

var layouter = new CircularCloudLayouter(new(0, 0), 0.1, 0.1);
var size = new Size(width, height);

Action action = () => layouter.PutNextRectangle(size);

This comment was marked as resolved.


public class CircularCloudLayouter : ICircularCloudLayouter
{
private Point center;

This comment was marked as resolved.

if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0)
throw new ArgumentException($"{nameof(rectangleSize)} height and width must be greater than zero");
var rectangle = GetNextRectangle(rectangleSize);
while (rectangles.Any(rectangle.IntersectsWith)) //����� ������������ do while

This comment was marked as resolved.

public class CircularCloudLayouter : ICircularCloudLayouter
{
private Point center;
private List<Rectangle> rectangles = [];

This comment was marked as resolved.

return centerOfRectangle;
}

private Rectangle CreateRectangleWithCenter(Point center, Size rectangleSize)

This comment was marked as resolved.

private Rectangle GetNextRectangle(Size rectagleSize)
{
var rectanglePosition = spiral.GetNextPointPosition();
var centerOfRectangle = CreateRectangleWithCenter(rectanglePosition, rectagleSize);

This comment was marked as resolved.

return rectangle;
}

private Rectangle GetNextRectangle(Size rectagleSize)

This comment was marked as resolved.

[TestCase(1, 0, TestName = "WhenHeightIsZero")]
[TestCase(-1, 1, TestName = "WhenWidthIsNegative")]
[TestCase(1, -1, TestName = "WhenHeightIsNegative")]
public void LayouterPutNextRectangle_ShouldThrowArgumentException(int width, int height)

This comment was marked as resolved.

}

[Test]
public void FirstRectang_ShouldBeInCenter()

This comment was marked as resolved.

var rectangleSize = new Size(10, 10);

var actualRectangle = layouter.PutNextRectangle(rectangleSize);
var expectedRectangle = new Rectangle(

This comment was marked as resolved.


[Test]
[Repeat(10)]
public void AllRectanglesCenter_ShoulBeLikeInitCenter()

This comment was marked as resolved.


[Test]
[Repeat(10)]
public void Rectangles_ShouldNotHaveIntersects()

Choose a reason for hiding this comment

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

Тест-метод должен говорить, какой метод мы тестируем


[Test]
[Repeat(10)]
public void RectanglesDensity_ShouldBeMax()

This comment was marked as resolved.

var layouter = CloudGenerator.GenerateCloud(100);
rectanglesInTest = layouter.GetRectangles();

var actualCenter = GetCenterOfAllRectangles(rectanglesInTest);

This comment was marked as resolved.

var layouter = CloudGenerator.GenerateCloud(100);
rectanglesInTest = layouter.GetRectangles();

var rectanglesArea = rectanglesInTest.Sum(rect => rect.Width * rect.Height);

This comment was marked as resolved.


private double GetDistanceBetweenPoints(Point point1, Point point2)
=> Math.Sqrt(Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2));
}

This comment was marked as resolved.

public const double LayoutStep = 0.1;
public const double LayoutAngleOffset = 0.1;
public const string ImagesDirectory = "images";
}

This comment was marked as resolved.


public static class CloudGenerator
{
public static CircularCloudLayouter GenerateCloud(int rectanglesNumber = Constans.RectanglesNumber)

This comment was marked as resolved.

{
public static CircularCloudLayouter GenerateCloud(int rectanglesNumber = Constans.RectanglesNumber)
{
var center = new Point(Constans.ImageWidth / 2, Constans.ImageHeight / 2);

This comment was marked as resolved.

var cloudLayouter = new CircularCloudLayouter(center);
var random = new Random();
var rectangles = new Rectangle[rectanglesNumber];
rectangles = rectangles

This comment was marked as resolved.

random.Next(Constans.MinRectangleSize, Constans.MaxRectangleSize))))
.ToArray();
return cloudLayouter;
}

This comment was marked as resolved.

IEnumerable<Rectangle> rectangles,
Size bitmapSize,
string directory = Constans.ImagesDirectory,
string currentPath = null

This comment was marked as resolved.

bitmap.Save(path, ImageFormat.Jpeg);
}

private Color GetRandomColor()

This comment was marked as resolved.

)
{
var bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height);
var graphics = Graphics.FromImage(bitmap);

Choose a reason for hiding this comment

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

Не диспоузим этот объект - потеря памяти

Choose a reason for hiding this comment

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

using graphics = ...

…енератор точек, создал readme, перенес тесты из отдельного проекта в основной
{
public Point Center { get; }
public List<Rectangle> GeneratedRectangles { get; }
private IPointsGenerator spiral { get; }

Choose a reason for hiding this comment

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

Вижу тебе понравились свойства)

Для spiral логичнее использовать поле с пометкой readonly - таким образом зафиксируем, что оно инициализируется в конструкторе, и больше в логике этого класса не меняется.

А сейчас это private свойство до которого никто не может достучаться)


public static class ICircularCloudLayouterExtensions
{
public static void GenerateCloud(this ICircularCloudLayouter cloudLayouter,

Choose a reason for hiding this comment

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

По код-стайлу, если в одну строку сигнатура метода не вмещается, то лучше все параметры с новой строки.

private readonly double step = 0.1;
private readonly double angleOffset = 0.1;
private readonly Point center;
private double angle = 0;

Choose a reason for hiding this comment

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

Лучше переименовать на currentAngle

private readonly Point center;
private double angle = 0;

public SpiralPointsGenerator(Point center) => this.center = center;

Choose a reason for hiding this comment

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

В этом случае как-то теряются "дефолтные значения", давай сделаем один конструктор, но с опциональными параметрами:

public SpiralPointsGenerator(Point center, double step = 0.1, double angleOffset = 0.1)
{ ...

Choose a reason for hiding this comment

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

соответственно инициализацию у полей можно будет убрать

private readonly double step;
private readonly double angleOffset;
private readonly Point center;
private double angle;


namespace TagsCloudVisualization.Tests.CircularCloudLayouterTests;

[TestFixture, Parallelizable]

Choose a reason for hiding this comment

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

Для Parallelizable нужно указать, что "не параллельно"


public CircularCloudLayouter(Point center, int step, int angleOffset)
{
GeneratedRectangles = new List<Rectangle>();

Choose a reason for hiding this comment

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

центр забыл проинициализировать

Choose a reason for hiding this comment

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

можно наследоваться от других конструкторов и писать только различающуюся логику

public CircularCloudLayouter(Point center, int step, int angleOffset) : this(center)
{
    spiral = new SpiralPointsGenerator(center, step, angleOffset);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants