-
-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the unit tests for the separate method.
- Loading branch information
Showing
2 changed files
with
93 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
tests/Magick.NET.Tests/Shared/MagickImageTests/TheSeparateMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2013-2019 Dirk Lemstra <https://github.com/dlemstra/Magick.NET/> | ||
// | ||
// Licensed under the ImageMagick License (the "License"); you may not use this file except in | ||
// compliance with the License. You may obtain a copy of the License at | ||
// | ||
// https://www.imagemagick.org/script/license.php | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the | ||
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
// either express or implied. See the License for the specific language governing permissions | ||
// and limitations under the License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ImageMagick; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Magick.NET.Tests | ||
{ | ||
public partial class MagickImageTests | ||
{ | ||
[TestClass] | ||
public class TheSeparateMethod | ||
{ | ||
[TestMethod] | ||
public void ShouldReturnTheCorrectNumberOfChannels() | ||
{ | ||
using (IMagickImage rose = new MagickImage(Files.Builtin.Rose)) | ||
{ | ||
var i = 0; | ||
foreach (MagickImage image in rose.Separate()) | ||
{ | ||
i++; | ||
image.Dispose(); | ||
} | ||
|
||
Assert.AreEqual(3, i); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldReturnTheSpecifiedChannels() | ||
{ | ||
using (IMagickImage rose = new MagickImage(Files.Builtin.Rose)) | ||
{ | ||
var i = 0; | ||
foreach (MagickImage image in rose.Separate(Channels.Red | Channels.Green)) | ||
{ | ||
i++; | ||
image.Dispose(); | ||
} | ||
|
||
Assert.AreEqual(2, i); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void Test_Separate_Composite() | ||
{ | ||
using (IMagickImage logo = new MagickImage(Files.Builtin.Logo)) | ||
{ | ||
using (IMagickImage blue = logo.Separate(Channels.Blue).First()) | ||
{ | ||
AssertSeparate(blue, ColorSpace.Gray, 146); | ||
|
||
using (IMagickImage green = logo.Separate(Channels.Green).First()) | ||
{ | ||
AssertSeparate(green, ColorSpace.Gray, 62); | ||
|
||
blue.Composite(green, CompositeOperator.Modulate); | ||
|
||
AssertSeparate(blue, ColorSpace.sRGB, 15); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void AssertSeparate(IMagickImage image, ColorSpace colorSpace, byte value) | ||
{ | ||
Assert.AreEqual(colorSpace, image.ColorSpace); | ||
|
||
using (IPixelCollection pixels = image.GetPixels()) | ||
{ | ||
Pixel pixel = pixels.GetPixel(340, 260); | ||
ColorAssert.AreEqual(MagickColor.FromRgb(value, value, value), pixel.ToColor()); | ||
} | ||
} | ||
} | ||
} | ||
} |