-
Notifications
You must be signed in to change notification settings - Fork 0
HW #1
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
base: ToPR
Are you sure you want to change the base?
HW #1
Conversation
up .gitignore
add spiral vizualizer
finish task
reload examples
up readme
m1ralx
left a comment
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.
[WIP]
| [TestFixture] | ||
| internal class CircularCloudLayouter_Should | ||
| { | ||
| private static int GetCurrentTimeStamp() => (int) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; |
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.
Правда нужно кастовать к инту?
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.
TotalSeconds возвращает double
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| Cloud = new CircularCloudLayouter(new Point(300, 300)); |
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.
Почему Point а не Size?
Блин, понятно
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.
в конструкторе задается точка центра(условие задачи)
| namespace TagsCloudVisualization | ||
| { | ||
| [TestFixture] | ||
| internal class CircularCloudLayouter_Should |
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.
тут правильно, а в имени файла _should
| int seed) | ||
| { | ||
| GenerateRectangles(maxWidth, maxHeigth, numberOfRectangles, seed); | ||
| var result = new List<Size>(); |
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.
Можно сделать Enumerable.Empty<Size>()
| { | ||
| result = result | ||
| .Concat(GenerateRectangles(maxWidth, maxHeigth, numberOfRectangles, seed).Where(size => size.Width > size.Height)) | ||
| .ToList(); |
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.
тогда вот этот вызов .ToList() можно будет убрать`
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.
решарпер ругается на possible multiple enumeration
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.
@Griboedoff ну можно сделать лист из IEnumerable :D и возвращать этот лист .SelectMany...
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.
звучит как дичь, не?
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.
@Griboedoff да, конечно)
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.
но нужно понимать, что ToList() каждый раз -- тоже не оч хорошо
| .Concat(GenerateRectangles(maxWidth, maxHeigth, numberOfRectangles, seed).Where(size => size.Width > size.Height)) | ||
| .ToList(); | ||
| } | ||
| return result.Take(numberOfRectangles); |
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.
Тем более, возвращаешь ты всё-равно Enumerable
| var rectangleSize2 = new Size(10, 10); | ||
| Cloud.PutNextRectangle(rectangleSize); | ||
| Cloud.PutNextRectangle(rectangleSize2); | ||
| Cloud.PlacedRectangles.Should().HaveCount(2); |
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.
Поговорили про PlacedRectangles
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.
Тут можно сделать свойство у облака -- сколько уже прямоугольников оно содержит
| public void NotPlace_IfRectIsOutsideCloudBorder() | ||
| { | ||
| var size = new Size(1000, 10); | ||
| Cloud.PutNextRectangle(size); |
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.
Тут и в других тестах лучше отделять стадии AAA пустыми строками. Так легче читать. Даже такие простые тесты :)
| // var rects = GenerateWordLikeRectangles(100, 30, 500, 10); | ||
| foreach (var square in rects) | ||
| cloud.PutNextRectangle(square); | ||
| var filename = Path.Combine( |
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.
Можно вынести это в отдельную функцию, и возможно даже получится сделать её однообразной для этого теста и для 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; |
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.
Вэйт, а это разве не подходит?
| 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); |
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.
Лучше подобные штуки выносить в метод с говорящим названием. Ну и переменной тоже, наверное, можно подобрать более подходящее. А то не очень понятно, чей это location
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.
Имеется в виду, что не круто, когда для понимания чего-то простого нужно сначала посмотреть, где и для чего оно используется.
| var location = new Point(nextSpiralPoint.X - rectangleSize.Width / 2, nextSpiralPoint.Y - rectangleSize.Height / 2); | ||
|
|
||
| var nextRectangle = new Rectangle( | ||
| location, |
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.
это можно и в одну строчку оставить
| nextSpiralPoint = spiral.GetNextSpiralPoint(); | ||
| nextRectangle = | ||
| new Rectangle( | ||
| new Point(nextSpiralPoint.X - rectangleSize.Width / 2, nextSpiralPoint.Y - rectangleSize.Height / 2), |
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.
кажется, где-то я уже видел такую же строчку кода
| PlacedRectangles = new List<Rectangle>(); | ||
| } | ||
|
|
||
| public Rectangle PutNextRectangle(Size rectangleSize) |
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.
кажется, что этот метод всё-таки можно ещё немного декомпозировать. Например, можно вытащить поиск подходящей позиции для прямоугольника.
| var verticalyMoved = true; | ||
| while (horizontalyMoved || verticalyMoved) | ||
| { | ||
| var vectToCenter = center.Sub(new Point(rect.Location.X + rect.Width / 2, rect.Location.Y + rect.Height / 2)); |
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.
Не экономь на спичках символах. Пиши полные имена переменных
| currentRadius = 0; | ||
| } | ||
|
|
||
| public Point GetNextSpiralPoint() |
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.
Попробуешь оформить в виде генератора?
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.
А зачем?
TagsCloudVisualization/Spiral.cs
Outdated
| } | ||
| } | ||
|
|
||
| public class SpiralVizualizer : Form |
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.
Блин, давай всё-таки каждый класс в отдельном файле. А ещё лучше -- группировать файлы в директории.
TagsCloudVisualization/Spiral.cs
Outdated
| } | ||
|
|
||
| [TestFixture] | ||
| public class Spiral_Should |
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.
ну вот что-то на Spiral-то мало тестов :(
|
|
||
| public static bool IsInside(this Rectangle r1, Rectangle r2) | ||
| { | ||
| return r1.IsIntersectedWith(r2) && |
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.
На это бы тоже тестов :)
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.
В смысле на каждый Extension-метод
|
|
||
| namespace TagsCloudVisualization | ||
| { | ||
| public static class PointExtensions |
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.
эти Extension методы конечно простые, но всё равно лучше было бы их протестировать
| public List<Rectangle> PlacedRectangles { get; } | ||
|
|
||
| private bool IsInValidPosition(Rectangle checkingRect) | ||
| => !(PlacedRectangles.Any(rect => rect.IsIntersectedWith(checkingRect) || checkingRect.IsInside(rect)) |
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.
о, вот кстати, может быть такое, что все уже расставленные прямоугольники будут внутри checkingRect?
m1ralx
left a comment
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.
-_-
Changed some methods to build-in
Add throwing exception if cloud is too small (add test too)
No description provided.