From a65a2b3ef72b4d2ee7f908e1fdfdf99d6dd782eb Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 4 Feb 2016 17:22:28 +1100 Subject: [PATCH] Add Sampler test, touch #321 Former-commit-id: b55309b168262965045654344b1263ba80f070ef Former-commit-id: 2ae48d651daa1382d988600ffc94c59055012f43 Former-commit-id: 1035ff8b5fc5c32cb81e42bdc788aa04dea1167b --- .../Processors/Samplers/SamplerTests.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs index c75ab4bed..52600f1cc 100644 --- a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs @@ -10,7 +10,7 @@ public class SamplerTests : ProcessorTestBase { - public static readonly TheoryData Samplers = + public static readonly TheoryData ReSamplers = new TheoryData { { "Bicubic", new BicubicResampler() }, @@ -30,6 +30,12 @@ //{ "Welch", new WelchResampler() } }; + public static readonly TheoryData Samplers = new TheoryData + { + { "Resize", new Resize(new BicubicResampler()) }, + { "Crop", new Crop() } + }; + public static readonly TheoryData RotateFlips = new TheoryData { { RotateType.None, FlipType.Vertical }, @@ -41,6 +47,34 @@ [Theory] [MemberData("Samplers")] + public void SampleImage(string name, IImageProcessor processor) + { + if (!Directory.Exists("TestOutput/Sample")) + { + Directory.CreateDirectory("TestOutput/Sample"); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + Stopwatch watch = Stopwatch.StartNew(); + Image image = new Image(stream); + string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); + using (FileStream output = File.OpenWrite($"TestOutput/Sample/{ Path.GetFileName(filename) }")) + { + processor.OnProgress += this.ProgressUpdate; + image.Process(image.Width / 2, image.Height / 2, processor).Save(output); + processor.OnProgress -= this.ProgressUpdate; + } + + Trace.WriteLine($"{ name }: { watch.ElapsedMilliseconds}ms"); + } + } + } + + [Theory] + [MemberData("ReSamplers")] public void ImageShouldResize(string name, IResampler sampler) { if (!Directory.Exists("TestOutput/Resize")) @@ -150,7 +184,7 @@ } [Theory] - [MemberData("Samplers")] + [MemberData("ReSamplers")] public void ImageShouldRotate(string name, IResampler sampler) { if (!Directory.Exists("TestOutput/Rotate"))