From 8a6d032022c2ac4e380d36c6c45554708caf0792 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 2 Oct 2018 17:20:08 +0100 Subject: [PATCH] Fix colorspace string representation tests. --- src/ImageSharp/ColorSpaces/CieLch.cs | 2 +- src/ImageSharp/ColorSpaces/CieLchuv.cs | 2 +- src/ImageSharp/ColorSpaces/CieLuv.cs | 2 +- .../CieXyChromaticityCoordinates.cs | 2 +- src/ImageSharp/ColorSpaces/CieXyy.cs | 2 +- src/ImageSharp/ColorSpaces/CieXyz.cs | 2 +- src/ImageSharp/ColorSpaces/Cmyk.cs | 2 +- src/ImageSharp/ColorSpaces/Hsl.cs | 2 +- src/ImageSharp/ColorSpaces/Hsv.cs | 2 +- src/ImageSharp/ColorSpaces/HunterLab.cs | 2 +- src/ImageSharp/ColorSpaces/LinearRgb.cs | 2 +- src/ImageSharp/ColorSpaces/Lms.cs | 2 +- src/ImageSharp/ColorSpaces/Rgb.cs | 2 +- src/ImageSharp/ColorSpaces/YCbCr.cs | 2 +- .../Conversion/StringRepresentationTests.cs | 65 ------------------- .../Colorspaces/StringRepresentationTests.cs | 65 +++++++++++++++++++ 16 files changed, 79 insertions(+), 79 deletions(-) delete mode 100644 tests/ImageSharp.Tests/Colorspaces/Conversion/StringRepresentationTests.cs create mode 100644 tests/ImageSharp.Tests/Colorspaces/StringRepresentationTests.cs diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index 68fe124a6a..47eb53e770 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLch [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}]"; + public override string ToString() => $"CieLch({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"; /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index e37f7fa20d..a92cad2a3d 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLchuv [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}"; + public override string ToString() => $"CieLchuv({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"; /// public override bool Equals(object obj) => obj is CieLchuv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index 10ff7287ed..c8639c8162 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLuv [ L={this.L:#0.##}, U={this.U:#0.##}, V={this.V:#0.##} ]"; + public override string ToString() => $"CieLuv({this.L:#0.##}, {this.U:#0.##}, {this.V:#0.##})"; /// public override bool Equals(object obj) => obj is CieLuv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index 64ba44878c..06aaafb553 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); /// - public override string ToString() => $"CieXyChromaticityCoordinates [ X={this.X:#0.##}, Y={this.Y:#0.##}]"; + public override string ToString() => $"CieXyChromaticityCoordinates({this.X:#0.##}, {this.Y:#0.##})"; /// public override bool Equals(object obj) => obj is CieXyChromaticityCoordinates other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index 2b40c30393..e8e129df90 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieXyy [ X={this.X:#0.##}, Y={this.Y:#0.##}, Yl={this.Yl:#0.##} ]"; + public override string ToString() => $"CieXyy({this.X:#0.##}, {this.Y:#0.##}, {this.Yl:#0.##})"; /// public override bool Equals(object obj) => obj is CieXyy other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index b992a7a3e6..8995d3eeba 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieXyz [ X={this.X:#0.##}, Y={this.Y:#0.##}, Z={this.Z:#0.##} ]"; + public override string ToString() => $"CieXyz({this.X:#0.##}, {this.Y:#0.##}, {this.Z:#0.##})"; /// public override bool Equals(object obj) => obj is CieXyz other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index ea3c0b047b..78153eced8 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Cmyk [ C={this.C:#0.##}, M={this.M:#0.##}, Y={this.Y:#0.##}, K={this.K:#0.##}]"; + public override string ToString() => $"Cmyk({this.C:#0.##}, {this.M:#0.##}, {this.Y:#0.##}, {this.K:#0.##})"; /// public override bool Equals(object obj) => obj is Cmyk other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index 1110241675..2197b8504d 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Hsl [ H={this.H:#0.##}, S={this.S:#0.##}, L={this.L:#0.##} ]"; + public override string ToString() => $"Hsl({this.H:#0.##}, {this.S:#0.##}, {this.L:#0.##})"; /// public override bool Equals(object obj) => obj is Hsl other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index fdd34b1b43..b10444aff4 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Hsv [ H={this.H:#0.##}, S={this.S:#0.##}, V={this.V:#0.##} ]"; + public override string ToString() => $"Hsv({this.H:#0.##}, {this.S:#0.##}, {this.V:#0.##})"; /// public override bool Equals(object obj) => obj is Hsv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index 9c7b456641..8771081d5b 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"HunterLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; + public override string ToString() => $"HunterLab({this.L:#0.##}, {this.A:#0.##}, {this.B:#0.##})"; /// public override bool Equals(object obj) => obj is HunterLab other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index d055afc808..14ff919c19 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"LinearRgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; + public override string ToString() => $"LinearRgb({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##})"; /// public override bool Equals(object obj) => obj is LinearRgb other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index becfea3415..2ad7c5a10a 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Lms [ L={this.L:#0.##}, M={this.M:#0.##}, S={this.S:#0.##} ]"; + public override string ToString() => $"Lms({this.L:#0.##}, {this.M:#0.##}, {this.S:#0.##})"; /// public override bool Equals(object obj) => obj is Lms other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index e75de117c0..39fe534535 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Rgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; + public override string ToString() => $"Rgb({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##})"; /// public override bool Equals(object obj) => obj is Rgb other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index a1514505a3..6b94f4a4a8 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"YCbCr [ Y={this.Y}, Cb={this.Cb}, Cr={this.Cr} ]"; + public override string ToString() => $"YCbCr({this.Y}, {this.Cb}, {this.Cr})"; /// public override bool Equals(object obj) => obj is YCbCr other && this.Equals(other); diff --git a/tests/ImageSharp.Tests/Colorspaces/Conversion/StringRepresentationTests.cs b/tests/ImageSharp.Tests/Colorspaces/Conversion/StringRepresentationTests.cs deleted file mode 100644 index 580e6cb4ec..0000000000 --- a/tests/ImageSharp.Tests/Colorspaces/Conversion/StringRepresentationTests.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.Numerics; -using SixLabors.ImageSharp.ColorSpaces; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Colorspaces.Conversion -{ - public class StringRepresentationTests - { - private static readonly Vector3 one = new Vector3(1); - private static readonly Vector3 zero = new Vector3(0); - private static readonly Vector3 random = new Vector3(42.4F, 94.5F, 83.4F); - - public static readonly TheoryData TestData = new TheoryData - { - { new CieLab(zero), "CieLab(0,0,0)" }, - { new CieLch(zero), "CieLch(0,0,0)" }, - { new CieLchuv(zero), "CieLchuv(0,0,0)" }, - { new CieLuv(zero), "CieLuv(0,0,0)" }, - { new CieXyz(zero), "CieXyz(0,0,0)" }, - { new CieXyy(zero), "CieXyy(0,0,0)" }, - { new HunterLab(zero), "HunterLab(0,0,0)" }, - { new Lms(zero), "Lms(0,0,0)" }, - { new LinearRgb(zero), "LinearRgb(0,0,0)" }, - { new Rgb(zero), "Rgb(0,0,0)" }, - { new Hsl(zero), "Hsl(0,0,0)" }, - { new Hsv(zero), "Hsv(0,0,0)" }, - { new YCbCr(zero), "YCbCr(0,0,0)" }, - - { new CieLab(one), "CieLab(1,1,1)" }, - { new CieLch(one), "CieLch(1,1,1)" }, - { new CieLchuv(one), "CieLchuv(1,1,1)" }, - { new CieLuv(one), "CieLuv(1,1,1)" }, - { new CieXyz(one), "CieXyz(1,1,1)" }, - { new CieXyy(one), "CieXyy(1,1,1)" }, - { new HunterLab(one), "HunterLab(1,1,1)" }, - { new Lms(one), "Lms(1,1,1)" }, - { new LinearRgb(one), "LinearRgb(1,1,1)" }, - { new Rgb(one), "Rgb(1,1,1)" }, - { new Hsl(one), "Hsl(1,1,1)" }, - { new Hsv(one), "Hsv(1,1,1)" }, - { new YCbCr(one), "YCbCr(1,1,1)" }, - - { new CieLab(random), "CieLab(42.4,94.5,83.4)" }, - { new CieLch(random), "CieLch(42.4,94.5,83.4)" }, - { new CieLchuv(random), "CieLchuv(42.4,94.5,83.4)" }, - { new CieLuv(random), "CieLuv(42.4,94.5,83.4)" }, - { new CieXyz(random), "CieXyz(42.4,94.5,83.4)" }, - { new CieXyy(random), "CieXyy(42.4,94.5,83.4)" }, - { new HunterLab(random), "HunterLab(42.4,94.5,83.4)" }, - { new Lms(random), "Lms(42.4,94.5,83.4)" }, - { new LinearRgb(random), "LinearRgb(1,1,1)" }, // clamping to 1 is expected - { new Rgb(random), "Rgb(1,1,1)" }, // clamping to 1 is expected - { new Hsl(random), "Hsl(42.4,1,1)" }, // clamping to 1 is expected - { new Hsv(random), "Hsv(42.4,1,1)" }, // clamping to 1 is expected - { new YCbCr(random), "YCbCr(42.4,94.5,83.4)" }, - }; - - [Theory] - [MemberData(nameof(TestData))] - public void StringRepresentationsAreCorrect(object color, string text) => Assert.Equal(text, color.ToString()); - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colorspaces/StringRepresentationTests.cs b/tests/ImageSharp.Tests/Colorspaces/StringRepresentationTests.cs new file mode 100644 index 0000000000..44b02f1657 --- /dev/null +++ b/tests/ImageSharp.Tests/Colorspaces/StringRepresentationTests.cs @@ -0,0 +1,65 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Numerics; +using SixLabors.ImageSharp.ColorSpaces; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Colorspaces +{ + public class StringRepresentationTests + { + private static readonly Vector3 one = new Vector3(1); + private static readonly Vector3 zero = new Vector3(0); + private static readonly Vector3 random = new Vector3(42.4F, 94.5F, 83.4F); + + public static readonly TheoryData TestData = new TheoryData + { + { new CieLab(zero), "CieLab(0, 0, 0)" }, + { new CieLch(zero), "CieLch(0, 0, 0)" }, + { new CieLchuv(zero), "CieLchuv(0, 0, 0)" }, + { new CieLuv(zero), "CieLuv(0, 0, 0)" }, + { new CieXyz(zero), "CieXyz(0, 0, 0)" }, + { new CieXyy(zero), "CieXyy(0, 0, 0)" }, + { new HunterLab(zero), "HunterLab(0, 0, 0)" }, + { new Lms(zero), "Lms(0, 0, 0)" }, + { new LinearRgb(zero), "LinearRgb(0, 0, 0)" }, + { new Rgb(zero), "Rgb(0, 0, 0)" }, + { new Hsl(zero), "Hsl(0, 0, 0)" }, + { new Hsv(zero), "Hsv(0, 0, 0)" }, + { new YCbCr(zero), "YCbCr(0, 0, 0)" }, + + { new CieLab(one), "CieLab(1, 1, 1)" }, + { new CieLch(one), "CieLch(1, 1, 1)" }, + { new CieLchuv(one), "CieLchuv(1, 1, 1)" }, + { new CieLuv(one), "CieLuv(1, 1, 1)" }, + { new CieXyz(one), "CieXyz(1, 1, 1)" }, + { new CieXyy(one), "CieXyy(1, 1, 1)" }, + { new HunterLab(one), "HunterLab(1, 1, 1)" }, + { new Lms(one), "Lms(1, 1, 1)" }, + { new LinearRgb(one), "LinearRgb(1, 1, 1)" }, + { new Rgb(one), "Rgb(1, 1, 1)" }, + { new Hsl(one), "Hsl(1, 1, 1)" }, + { new Hsv(one), "Hsv(1, 1, 1)" }, + { new YCbCr(one), "YCbCr(1, 1, 1)" }, + + { new CieLab(random), "CieLab(42.4, 94.5, 83.4)" }, + { new CieLch(random), "CieLch(42.4, 94.5, 83.4)" }, + { new CieLchuv(random), "CieLchuv(42.4, 94.5, 83.4)" }, + { new CieLuv(random), "CieLuv(42.4, 94.5, 83.4)" }, + { new CieXyz(random), "CieXyz(42.4, 94.5, 83.4)" }, + { new CieXyy(random), "CieXyy(42.4, 94.5, 83.4)" }, + { new HunterLab(random), "HunterLab(42.4, 94.5, 83.4)" }, + { new Lms(random), "Lms(42.4, 94.5, 83.4)" }, + { new LinearRgb(random), "LinearRgb(1, 1, 1)" }, // clamping to 1 is expected + { new Rgb(random), "Rgb(1, 1, 1)" }, // clamping to 1 is expected + { new Hsl(random), "Hsl(42.4, 1, 1)" }, // clamping to 1 is expected + { new Hsv(random), "Hsv(42.4, 1, 1)" }, // clamping to 1 is expected + { new YCbCr(random), "YCbCr(42.4, 94.5, 83.4)" }, + }; + + [Theory] + [MemberData(nameof(TestData))] + public void StringRepresentationsAreCorrect(object color, string text) => Assert.Equal(text, color.ToString()); + } +} \ No newline at end of file