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

Andronov Alexander #224

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions cs/TagCloud.Tests/CircularCloudLayouterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System.Drawing.Imaging;

namespace TagCloud.Tests
{
public class CircularCloudLayouterTests

This comment was marked as resolved.

{
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]
[Description(
"���������, ��� �������������� ����������� ������ ������ ����� � ������� � ����� center." +
"��� �����������, ��� �������������� ����������� � ���� ����� ���������� ������.")]
public void PutNextRectangle_PlaceManyRectangles_ShouldFitInTightCircleAroundCenter()
{
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}");
}
}
}
}
2 changes: 2 additions & 0 deletions cs/TagCloud.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global using NUnit.Framework;
global using System.Drawing;
24 changes: 24 additions & 0 deletions cs/TagCloud.Tests/TagCloud.Tests.csproj
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>
84 changes: 84 additions & 0 deletions cs/TagCloud.Visualization/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions cs/TagCloud.Visualization/Form1.cs
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)
{

}
}
}
60 changes: 60 additions & 0 deletions cs/TagCloud.Visualization/Form1.resx
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>
17 changes: 17 additions & 0 deletions cs/TagCloud.Visualization/Program.cs
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());
}
}
}
15 changes: 15 additions & 0 deletions cs/TagCloud.Visualization/TagCloud.Visualization.csproj
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>
Loading