Skip to content

Commit f51906e

Browse files
committed
Добавил тесты
1 parent b04caf5 commit f51906e

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

‎ImageConvolution.Tests/ConvolutionTests.cs‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,58 @@ public void Test_AgentProcessor_NonExistentFolder()
177177
Assert.False(Directory.Exists(outputDir));
178178
}
179179

180+
[Fact]
181+
public void Test_LibraryProcessor_Parallel_Success()
182+
{
183+
string inputDir = "test_input_lib_par";
184+
string outputDir = "test_output_lib_par";
185+
try
186+
{
187+
CreateTestImage(inputDir, "lib_test.jpg");
188+
LibraryProcessor.ProcessImagesWithImageSharp(inputDir, outputDir);
189+
190+
Assert.True(Directory.Exists(outputDir));
191+
Assert.Single(Directory.GetFiles(outputDir));
192+
}
193+
finally
194+
{
195+
if (Directory.Exists(inputDir)) Directory.Delete(inputDir, true);
196+
if (Directory.Exists(outputDir)) Directory.Delete(outputDir, true);
197+
}
198+
}
199+
200+
[Fact]
201+
public void Test_CustomKernelSize_5x5()
202+
{
203+
double[,] image = new double[10, 10];
204+
for (int i = 0; i < 10; i++)
205+
for (int j = 0; j < 10; j++) image[i, j] = 100;
206+
207+
double[,] kernel5x5 = new double[5, 5];
208+
for (int i = 0; i < 5; i++)
209+
for (int j = 0; j < 5; j++) kernel5x5[i, j] = 1.0 / 25.0;
210+
211+
double[,] result = ConvolutionProcessor.Convolve(image, kernel5x5, EdgeStrategy.Extend);
212+
Assert.Equal(100, Math.Round(result[5, 5]));
213+
}
214+
215+
[Fact]
216+
public void Test_SharpenAndLaplacianKernels()
217+
{
218+
double[,] image = { { 50, 50, 50 }, { 50, 50, 50 }, { 50, 50, 50 } };
219+
220+
var resLapl = ConvolutionProcessor.Convolve(image, Kernels.Laplacian);
221+
var resSharp = ConvolutionProcessor.Convolve(image, Kernels.Sharpen);
222+
223+
Assert.Equal(0, Math.Round(resLapl[1, 1]));
224+
Assert.Equal(50, Math.Round(resSharp[1, 1]));
225+
}
226+
227+
[Fact]
228+
public void Test_LibraryProcessor_NonExistentFolder()
229+
{
230+
LibraryProcessor.ProcessImagesWithImageSharp("non_existent_folder_123", "output_123");
231+
Assert.False(Directory.Exists("output_123"));
232+
}
233+
180234
}

0 commit comments

Comments
 (0)