Browse Source

Add Sampler test, touch #321

Former-commit-id: b55309b168262965045654344b1263ba80f070ef
Former-commit-id: 2ae48d651daa1382d988600ffc94c59055012f43
Former-commit-id: 1035ff8b5fc5c32cb81e42bdc788aa04dea1167b
pull/1/head
James Jackson-South 10 years ago
parent
commit
a65a2b3ef7
  1. 38
      tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

38
tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

@ -10,7 +10,7 @@
public class SamplerTests : ProcessorTestBase
{
public static readonly TheoryData<string, IResampler> Samplers =
public static readonly TheoryData<string, IResampler> ReSamplers =
new TheoryData<string, IResampler>
{
{ "Bicubic", new BicubicResampler() },
@ -30,6 +30,12 @@
//{ "Welch", new WelchResampler() }
};
public static readonly TheoryData<string, IImageProcessor> Samplers = new TheoryData<string, IImageProcessor>
{
{ "Resize", new Resize(new BicubicResampler()) },
{ "Crop", new Crop() }
};
public static readonly TheoryData<RotateType, FlipType> RotateFlips = new TheoryData<RotateType, FlipType>
{
{ 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"))

Loading…
Cancel
Save