From a63bb0b63e7aa72144c3d34b36d6331b46482608 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 11 Mar 2018 22:41:34 +1100 Subject: [PATCH] Add LaplacianKernelFactory tests --- .../Processors/LaplacianKernelFactoryTests.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs diff --git a/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs b/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs new file mode 100644 index 000000000..439632210 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs @@ -0,0 +1,68 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Convolution.Processors; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Convolution.Processors +{ + public class LaplacianKernelFactoryTests + { + private static readonly ApproximateFloatComparer ApproximateComparer = new ApproximateFloatComparer(0.0001F); + + private static readonly DenseMatrix Expected3x3Matrix = new DenseMatrix( + new float[,] + { + { -1, -1, -1 }, + { -1, 8, -1 }, + { -1, -1, -1 } + }); + + private static readonly DenseMatrix Expected5x5Matrix = new DenseMatrix( + new float[,] + { + { -1, -1, -1,-1, -1 }, + { -1, -1, -1,-1, -1 }, + { -1, -1, 24,-1, -1 }, + { -1, -1, -1,-1, -1 }, + { -1, -1, -1,-1, -1 } + }); + + [Fact] + public void LaplacianKernelFactoryOutOfRangeThrows() + { + Assert.Throws(() => + { + LaplacianKernelFactory.CreateKernel(2); + }); + } + + [Fact] + public void LaplacianKernelFactoryCreatesCorrect3x3Matrix() + { + DenseMatrix actual = LaplacianKernelFactory.CreateKernel(3); + for (int y = 0; y < actual.Rows; y++) + { + for (int x = 0; x < actual.Columns; x++) + { + Assert.Equal(Expected3x3Matrix[y, x], actual[y, x], ApproximateComparer); + } + } + } + + [Fact] + public void LaplacianKernelFactoryCreatesCorrect5x5Matrix() + { + DenseMatrix actual = LaplacianKernelFactory.CreateKernel(5); + for (int y = 0; y < actual.Rows; y++) + { + for (int x = 0; x < actual.Columns; x++) + { + Assert.Equal(Expected5x5Matrix[y, x], actual[y, x], ApproximateComparer); + } + } + } + } +} \ No newline at end of file