-
Notifications
You must be signed in to change notification settings - Fork 305
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
Andronov Alexander #224
Open
batyadmx
wants to merge
6
commits into
kontur-courses:master
Choose a base branch
from
batyadmx:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Andronov Alexander #224
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e5976a
Add TagCloud
batyadmx 53c8caf
CircularCloudLayouter refactor
batyadmx 234e366
Work on CircularCloudLayouterTests
batyadmx 35aaad9
Work on CircularCloudLayouter
batyadmx 5909205
Add negative size tests
batyadmx 611cb30
Small refactor
batyadmx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using System.Drawing.Imaging; | ||
|
||
namespace TagCloud.Tests | ||
{ | ||
public class CircularCloudLayouterTests | ||
{ | ||
private readonly static string projectDirectory | ||
= Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName; | ||
private readonly static string pathToFailureImagesFolder | ||
= Path.Combine(projectDirectory, "FailureImages"); | ||
|
||
private Point center; | ||
private Size imageSize; | ||
|
||
private CircularCloudLayouter layouter; | ||
private Size[] sizes; | ||
|
||
[OneTimeSetUp] | ||
public void OneTimeSetup() | ||
{ | ||
EnsureFolderCreated(pathToFailureImagesFolder); | ||
|
||
var dir = new DirectoryInfo(pathToFailureImagesFolder); | ||
|
||
foreach(var file in dir.EnumerateFiles()) file.Delete(); | ||
} | ||
|
||
public static void EnsureFolderCreated(string folderPath) | ||
{ | ||
if (!Directory.Exists(folderPath)) | ||
Directory.CreateDirectory(folderPath); | ||
} | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
imageSize = new Size(2000, 2000); | ||
|
||
center = new Point(imageSize.Width / 2, imageSize.Height / 2); | ||
layouter = new CircularCloudLayouter(center); | ||
sizes = GenerateSizes(); | ||
} | ||
|
||
[Test] | ||
public void PutNextRectangle_PlaceOneRectangle_DoesntThrowException() | ||
{ | ||
Assert.DoesNotThrow(() => layouter.PutNextRectangle(sizes[0])); | ||
} | ||
|
||
[Test] | ||
public void PutNextRectangle_PlaceOneRectangle_ReturnRightSizeRect() | ||
{ | ||
var rect = layouter.PutNextRectangle(sizes[0]); | ||
|
||
Assert.True(rect.Size == sizes[0]); | ||
} | ||
|
||
[Test] | ||
public void PutNextRectangle_PlaceManyRectangles_ShouldNotIntersect() | ||
{ | ||
var rectangles = sizes.Select(x => layouter.PutNextRectangle(x)).ToArray(); | ||
|
||
|
||
foreach (var rect1 in rectangles) | ||
{ | ||
foreach(var rect2 in rectangles) | ||
{ | ||
if (rect1 != rect2) | ||
Assert.False(rect1.IntersectsWith(rect2)); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void PutNextRectangle_PlaceManyRectangles_ShouldFitInCircleAroundCenter() | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
{ | ||
var rectangles = sizes.Select(x => layouter.PutNextRectangle(x)).ToArray(); | ||
|
||
|
||
var totalArea = rectangles.Select(x => x.Width * x.Height).Sum(); | ||
var radius = Math.Sqrt(totalArea / Math.PI) * 1.2; | ||
|
||
foreach (var rect in rectangles) | ||
{ | ||
Assert.True(new PointF(rect.X, rect.Y).DistanceTo(center) < radius); | ||
} | ||
} | ||
|
||
[TestCase(-1, 0)] | ||
[TestCase(0, -1)] | ||
[TestCase(-1, -1)] | ||
public void PutNextRectangle_NegativeSize_ShouldThrowArgumentException(int width, int height) | ||
{ | ||
var size = new Size(width, height); | ||
|
||
Assert.Throws<ArgumentException>(() => layouter.PutNextRectangle(size)); | ||
} | ||
|
||
public static Size[] GenerateSizes() | ||
{ | ||
var sizes = new List<Size>(); | ||
|
||
for (int x = 30; x < 55; x++) | ||
{ | ||
for (int y = 30; y < 55; y++) | ||
{ | ||
sizes.Add(new Size(x, y)); | ||
} | ||
} | ||
|
||
return sizes.ToArray(); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
var context = TestContext.CurrentContext; | ||
var fileName = $"{context.Test.Name}.jpg"; | ||
var pathToSave = Path.Combine(pathToFailureImagesFolder, fileName); | ||
|
||
if (context.Result.FailCount != 0) | ||
{ | ||
var img = TagCloudVisualizer.DrawImage(layouter.Rectangles, imageSize); | ||
img.Save(pathToSave, ImageFormat.Jpeg); | ||
Console.WriteLine($"Tag cloud visualization saved to file {pathToSave}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
global using NUnit.Framework; | ||
global using System.Drawing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" /> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TagCloud\TagCloud.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace TagCloud.Visualization | ||
{ | ||
public partial class Form1 : Form | ||
{ | ||
TagCloudForDebug layouter; | ||
Random rd=new Random(); | ||
|
||
public Form1() | ||
{ | ||
InitializeComponent(); | ||
var center = new Point(pictureBox1.Width / 2, pictureBox1.Height / 2); | ||
layouter = new TagCloudForDebug(center); | ||
} | ||
|
||
private void button1_Click(object sender, EventArgs e) | ||
{ | ||
//var inp = textBox1.Text.Split().Select(int.Parse).ToArray(); | ||
//var size = new Size(inp[0], inp[1]); | ||
var size = new Size(rd.Next(20,40), rd.Next(20,40)); | ||
foreach (var el in layouter.PutNextRectangle(size)) | ||
{ | ||
pictureBox1.Image = el; | ||
pictureBox1.Update(); | ||
} | ||
} | ||
|
||
private void pictureBox1_Click(object sender, EventArgs e) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<root> | ||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
<xsd:complexType> | ||
<xsd:choice maxOccurs="unbounded"> | ||
<xsd:element name="metadata"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" use="required" type="xsd:string" /> | ||
<xsd:attribute name="type" type="xsd:string" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="assembly"> | ||
<xsd:complexType> | ||
<xsd:attribute name="alias" type="xsd:string" /> | ||
<xsd:attribute name="name" type="xsd:string" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="data"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="resheader"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:choice> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>2.0</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace TagCloud.Visualization | ||
{ | ||
internal static class Program | ||
{ | ||
/// <summary> | ||
/// The main entry point for the application. | ||
/// </summary> | ||
[STAThread] | ||
static void Main() | ||
{ | ||
// To customize application configuration such as set high DPI settings or default font, | ||
// see https://aka.ms/applicationconfiguration. | ||
ApplicationConfiguration.Initialize(); | ||
Application.Run(new Form1()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net6.0-windows</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TagCloud\TagCloud.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.