-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageTests.cs
More file actions
111 lines (82 loc) · 3.68 KB
/
Copy pathImageTests.cs
File metadata and controls
111 lines (82 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Kattbot.Services.Images;
using Kattbot.Tests.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
namespace Kattbot.Tests;
[TestClass]
[TestCategory("ShittyTests")]
public class ImageTests
{
private readonly TestContext _testContext;
public ImageTests(TestContext testContext)
{
_testContext = testContext;
}
[TestMethod]
[DataRow("froge.png")]
public async Task PetPetTest(string inputFilename)
{
string inputFile = Path.Combine("Resources", inputFilename);
using Image<Rgba32> image = Image.Load<Rgba32>(inputFile);
Image result = ImageEffects.PetPet(image);
string outputFile = Path.Combine(PathUtils.TryGetTempPathFromEnv(), "kattbot", "z_output_petpet_froge.gif");
await result.SaveAsGifAsync(outputFile, _testContext.CancellationTokenSource.Token);
Assert.IsTrue(File.Exists(outputFile));
}
[TestMethod]
[DataRow("froge.png")]
public async Task CropToCircle(string inputFilename)
{
string inputFile = Path.Combine("Resources", inputFilename);
string outputFile = Path.Combine(PathUtils.TryGetTempPathFromEnv(), "kattbot", $"cropped_{inputFilename}");
using Image<Rgba32> image = Image.Load<Rgba32>(inputFile);
Image<Rgba32> croppedImage = ImageEffects.CropToCircle(image);
await croppedImage.SaveAsPngAsync(outputFile, _testContext.CancellationTokenSource.Token);
Assert.IsTrue(File.Exists(outputFile));
}
[TestMethod]
[DataRow("froge.png")]
public async Task Twirl(string inputFilename)
{
string inputFile = Path.Combine("Resources", inputFilename);
string outputFile = Path.Combine(PathUtils.TryGetTempPathFromEnv(), "kattbot", $"twirled_{inputFilename}");
using Image<Rgba32> image = Image.Load<Rgba32>(inputFile);
Image croppedImage = ImageEffects.TwirlImage(image);
await croppedImage.SaveAsPngAsync(outputFile, _testContext.CancellationTokenSource.Token);
Assert.IsTrue(File.Exists(outputFile));
}
[TestMethod]
[DynamicData(nameof(GetTileImageFiles))]
public async Task FillMaskWithTiledImage(string tileImageFilename)
{
string targetImageFile = Path.Combine("Resources", "dumptruck_v1.png");
string maskImageFile = Path.Combine("Resources", "dumptruck_v1_double_mask.png");
string tileImageFile = Path.Combine("Resources", "DumpTruckTiles", tileImageFilename);
string outputDir = Path.Combine(PathUtils.TryGetTempPathFromEnv(), "kattbot");
string outputFile = Path.Combine(outputDir, $"mask_filled_{tileImageFilename}");
Directory.CreateDirectory(outputDir);
using Image<Rgba32> targetImage = Image.Load<Rgba32>(targetImageFile);
using Image<Rgba32> maskImage = Image.Load<Rgba32>(maskImageFile);
using Image<Rgba32> tileImage = Image.Load<Rgba32>(tileImageFile);
Image filledImage = FillMaskWithTilesEffect.ApplyEffect(targetImage, maskImage, tileImage);
await filledImage.SaveAsPngAsync(outputFile, _testContext.CancellationToken);
Assert.IsTrue(File.Exists(outputFile));
}
private static IEnumerable<object[]> GetTileImageFiles()
{
string tilesDirectory = Path.Combine("Resources", "DumpTruckTiles");
if (!Directory.Exists(tilesDirectory))
{
yield break;
}
string[] imageFiles = Directory.GetFiles(tilesDirectory, "*.png");
foreach (string filePath in imageFiles)
{
yield return [Path.GetFileName(filePath)];
}
}
}