Skip to content

Commit

Permalink
Added TagCloudGeneratorTest with Samples
Browse files Browse the repository at this point in the history
  • Loading branch information
BMV989 committed Dec 24, 2024
1 parent c7671c0 commit 80c03cc
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
5 changes: 2 additions & 3 deletions TagCloudClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ private static void RegisterWordsFilters(ContainerBuilder builder, Options setti
builder.RegisterType<LowercaseFilter>().As<IWordsFilter>();
builder.RegisterType<BoringWordsFilter>().As<IWordsFilter>();
}


private static void RegisterLayouter(ContainerBuilder builder, Options settings)

private static void RegisterLayouter(ContainerBuilder builder, Options settings)
{
builder.RegisterType<CircularCloudLayouter>().As<ICloudLayouter>();
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions TagCloudTests/Samples/sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
flap
vulgar
branch
creator
creator
creator
lettuce
lettuce
lettuce
psychedelic
alike
alike
nutritious
foolish
innate
innate
innate
innate
innate
naive
pushy
hapless
fuel
dependent
dependent
Binary file added TagCloudTests/Samples/sample.docx
Binary file not shown.
25 changes: 25 additions & 0 deletions TagCloudTests/Samples/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
flap
vulgar
branch
creator
creator
creator
lettuce
lettuce
lettuce
psychedelic
alike
alike
nutritious
foolish
innate
innate
innate
innate
innate
naive
pushy
hapless
fuel
dependent
dependent
41 changes: 41 additions & 0 deletions TagCloudTests/TagCloudGeneratorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Text;
using ApprovalTests;
using ApprovalTests.Reporters;
using FluentAssertions;
using SkiaSharp;
using TagCloud;
using TagCloud.CloudLayouter;
using TagCloud.Visualization;
using TagCloud.WordsFilter;
using TagCloud.WordsReader;

namespace TagCloudTests;

[TestFixture]
[UseReporter(typeof(RiderReporter))]
[ApprovalTests.Namers.UseApprovalSubdirectory("Samples/Snapshots")]
public class TagCloudGeneratorTest
{
[Test]
public void TagCloudGenerator_GenerateTagCloud_ShouldGenerateFile()
{
var generator = InitGenerator();

var savePath = generator.GenerateTagCloud();

File.Exists(savePath).Should().BeTrue();
Approvals.VerifyFile(savePath);
}

private static TagCloudGenerator InitGenerator()
{
var fileReader = new FileReader("../../../Samples/sample.txt", Encoding.UTF8);
var imageSaver = new TagCloudSaver("test", "png");
var layouter = new CircularCloudLayouter(new SKPoint(1920 / 2f, 1080 / 2f));
var imageGenerator = new TagCloudBitmapGenerator(new SKSizeI(1920, 1080), SKTypeface.FromFamilyName("Arial"),
SKColors.Black, SKColors.Azure, layouter);
List<IWordsFilter> filters = [new LowercaseFilter(), new BoringWordsFilter()];

return new TagCloudGenerator(fileReader, imageSaver, imageGenerator, filters);
}
}

0 comments on commit 80c03cc

Please sign in to comment.