Skip to content

Conversation

@Griboedoff
Copy link
Owner

No description provided.

Copy link

@m1ralx m1ralx left a comment

Choose a reason for hiding this comment

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

[WIP]

[TestFixture]
internal class CircularCloudLayouter_Should
{
private static int GetCurrentTimeStamp() => (int) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
Copy link

Choose a reason for hiding this comment

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

Правда нужно кастовать к инту?

Copy link
Owner Author

Choose a reason for hiding this comment

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

TotalSeconds возвращает double

[SetUp]
public void SetUp()
{
Cloud = new CircularCloudLayouter(new Point(300, 300));
Copy link

@m1ralx m1ralx Oct 24, 2016

Choose a reason for hiding this comment

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

Почему Point а не Size?
Блин, понятно

Copy link
Owner Author

Choose a reason for hiding this comment

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

в конструкторе задается точка центра(условие задачи)

namespace TagsCloudVisualization
{
[TestFixture]
internal class CircularCloudLayouter_Should
Copy link

Choose a reason for hiding this comment

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

тут правильно, а в имени файла _should

int seed)
{
GenerateRectangles(maxWidth, maxHeigth, numberOfRectangles, seed);
var result = new List<Size>();
Copy link

Choose a reason for hiding this comment

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

Можно сделать Enumerable.Empty<Size>()

{
result = result
.Concat(GenerateRectangles(maxWidth, maxHeigth, numberOfRectangles, seed).Where(size => size.Width > size.Height))
.ToList();
Copy link

Choose a reason for hiding this comment

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

тогда вот этот вызов .ToList() можно будет убрать`

Copy link
Owner Author

Choose a reason for hiding this comment

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

решарпер ругается на possible multiple enumeration

Copy link

Choose a reason for hiding this comment

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

@Griboedoff ну можно сделать лист из IEnumerable :D и возвращать этот лист .SelectMany...

Copy link
Owner Author

Choose a reason for hiding this comment

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

звучит как дичь, не?

Copy link

Choose a reason for hiding this comment

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

@Griboedoff да, конечно)

Copy link

@m1ralx m1ralx Oct 25, 2016

Choose a reason for hiding this comment

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

но нужно понимать, что ToList() каждый раз -- тоже не оч хорошо

.Concat(GenerateRectangles(maxWidth, maxHeigth, numberOfRectangles, seed).Where(size => size.Width > size.Height))
.ToList();
}
return result.Take(numberOfRectangles);
Copy link

Choose a reason for hiding this comment

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

Тем более, возвращаешь ты всё-равно Enumerable

var rectangleSize2 = new Size(10, 10);
Cloud.PutNextRectangle(rectangleSize);
Cloud.PutNextRectangle(rectangleSize2);
Cloud.PlacedRectangles.Should().HaveCount(2);
Copy link

Choose a reason for hiding this comment

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

Поговорили про PlacedRectangles

Copy link

Choose a reason for hiding this comment

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

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

public void NotPlace_IfRectIsOutsideCloudBorder()
{
var size = new Size(1000, 10);
Cloud.PutNextRectangle(size);
Copy link

Choose a reason for hiding this comment

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

Тут и в других тестах лучше отделять стадии AAA пустыми строками. Так легче читать. Даже такие простые тесты :)

// var rects = GenerateWordLikeRectangles(100, 30, 500, 10);
foreach (var square in rects)
cloud.PutNextRectangle(square);
var filename = Path.Combine(
Copy link

Choose a reason for hiding this comment

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

Можно вынести это в отдельную функцию, и возможно даже получится сделать её однообразной для этого теста и для TearDown, в котором тоже вычисляется filename

{
public static bool IsIntersectedWith(this Rectangle r1, Rectangle r2)
{
return r1.Bottom >= r2.Top && r1.Right >= r2.Left && r2.Bottom >= r1.Top && r2.Right >= r1.Left;
Copy link

Choose a reason for hiding this comment

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

Вэйт, а это разве не подходит?

throw new ArgumentException($"Size must be positive {rectangleSize}");

var nextSpiralPoint = spiral.GetNextSpiralPoint();
var location = new Point(nextSpiralPoint.X - rectangleSize.Width / 2, nextSpiralPoint.Y - rectangleSize.Height / 2);
Copy link

Choose a reason for hiding this comment

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

Лучше подобные штуки выносить в метод с говорящим названием. Ну и переменной тоже, наверное, можно подобрать более подходящее. А то не очень понятно, чей это location

Copy link

Choose a reason for hiding this comment

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

Имеется в виду, что не круто, когда для понимания чего-то простого нужно сначала посмотреть, где и для чего оно используется.

var location = new Point(nextSpiralPoint.X - rectangleSize.Width / 2, nextSpiralPoint.Y - rectangleSize.Height / 2);

var nextRectangle = new Rectangle(
location,
Copy link

Choose a reason for hiding this comment

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

это можно и в одну строчку оставить

nextSpiralPoint = spiral.GetNextSpiralPoint();
nextRectangle =
new Rectangle(
new Point(nextSpiralPoint.X - rectangleSize.Width / 2, nextSpiralPoint.Y - rectangleSize.Height / 2),
Copy link

Choose a reason for hiding this comment

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

кажется, где-то я уже видел такую же строчку кода

PlacedRectangles = new List<Rectangle>();
}

public Rectangle PutNextRectangle(Size rectangleSize)
Copy link

Choose a reason for hiding this comment

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

кажется, что этот метод всё-таки можно ещё немного декомпозировать. Например, можно вытащить поиск подходящей позиции для прямоугольника.

var verticalyMoved = true;
while (horizontalyMoved || verticalyMoved)
{
var vectToCenter = center.Sub(new Point(rect.Location.X + rect.Width / 2, rect.Location.Y + rect.Height / 2));
Copy link

Choose a reason for hiding this comment

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

Не экономь на спичках символах. Пиши полные имена переменных

currentRadius = 0;
}

public Point GetNextSpiralPoint()
Copy link

Choose a reason for hiding this comment

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

Попробуешь оформить в виде генератора?

Copy link
Owner Author

Choose a reason for hiding this comment

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

А зачем?

}
}

public class SpiralVizualizer : Form
Copy link

Choose a reason for hiding this comment

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

Блин, давай всё-таки каждый класс в отдельном файле. А ещё лучше -- группировать файлы в директории.

}

[TestFixture]
public class Spiral_Should
Copy link

Choose a reason for hiding this comment

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

ну вот что-то на Spiral-то мало тестов :(


public static bool IsInside(this Rectangle r1, Rectangle r2)
{
return r1.IsIntersectedWith(r2) &&
Copy link

Choose a reason for hiding this comment

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

На это бы тоже тестов :)

Copy link

Choose a reason for hiding this comment

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

В смысле на каждый Extension-метод


namespace TagsCloudVisualization
{
public static class PointExtensions
Copy link

Choose a reason for hiding this comment

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

эти Extension методы конечно простые, но всё равно лучше было бы их протестировать

public List<Rectangle> PlacedRectangles { get; }

private bool IsInValidPosition(Rectangle checkingRect)
=> !(PlacedRectangles.Any(rect => rect.IsIntersectedWith(checkingRect) || checkingRect.IsInside(rect))
Copy link

Choose a reason for hiding this comment

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

о, вот кстати, может быть такое, что все уже расставленные прямоугольники будут внутри checkingRect?

Copy link

@m1ralx m1ralx left a comment

Choose a reason for hiding this comment

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

-_-

Griboedoff and others added 4 commits October 25, 2016 11:47
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.

3 participants