diff options
author | Bertrand Le Roy <beleroy@microsoft.com> | 2017-10-16 21:14:19 +0300 |
---|---|---|
committer | Bertrand Le Roy <beleroy@microsoft.com> | 2017-11-04 02:35:42 +0300 |
commit | 830a689014d18cc61fe4d645955bf3edba2da498 (patch) | |
tree | e365f082c214969f84d19fe25b9aabb8ca45cf57 /Xamarin.PropertyEditing.Tests/CommonColorTests.cs | |
parent | 4e9b49cf2d69c1cffb2358a9e57583e6035cbc31 (diff) |
Test color to hue conversion
Diffstat (limited to 'Xamarin.PropertyEditing.Tests/CommonColorTests.cs')
-rw-r--r-- | Xamarin.PropertyEditing.Tests/CommonColorTests.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Tests/CommonColorTests.cs b/Xamarin.PropertyEditing.Tests/CommonColorTests.cs new file mode 100644 index 0000000..84c683f --- /dev/null +++ b/Xamarin.PropertyEditing.Tests/CommonColorTests.cs @@ -0,0 +1,74 @@ +using System.Collections; +using NUnit.Framework; +using Xamarin.PropertyEditing.Drawing; + +namespace Xamarin.PropertyEditing.Tests +{ + public class CommonColorTests + { + [Test, TestCaseSource (typeof(CommonColorTests), "HuesFromColors")] + public CommonColor HueFromColor (CommonColor color) => color.ToHue (); + + private static IEnumerable HuesFromColors() { + // Shades of grey all map to red + yield return new TestCaseData (new CommonColor (0, 0, 0)).Returns (new CommonColor (255, 0, 0)) + .SetName ("HueFromColorBlackHasRedHue"); + yield return new TestCaseData (new CommonColor (255, 255, 255)).Returns (new CommonColor (255, 0, 0)) + .SetName ("HueFromColorWhiteHasRedHue"); + yield return new TestCaseData (new CommonColor (127, 127, 127)).Returns (new CommonColor (255, 0, 0)) + .SetName ("HueFromColorGreyHasRedHue"); + // Fully-saturated primary colors map to themselves + yield return new TestCaseData (new CommonColor (255, 0, 0)).Returns (new CommonColor (255, 0, 0)) + .SetName ("HueFromColorRedHueHasRedHue"); + yield return new TestCaseData (new CommonColor (0, 255, 0)).Returns (new CommonColor (0, 255, 0)) + .SetName ("HueFromColorGreenHueHasGreenHue"); + yield return new TestCaseData (new CommonColor (0, 0, 255)).Returns (new CommonColor (0, 0, 255)) + .SetName ("HueFromColorBlueHueHasBlueHue"); + yield return new TestCaseData (new CommonColor (255, 255, 0)).Returns (new CommonColor (255, 255, 0)) + .SetName ("HueFromColorYellowHueHasYellowHue"); + yield return new TestCaseData (new CommonColor (255, 0, 255)).Returns (new CommonColor (255, 0, 255)) + .SetName ("HueFromColorPurpleHueHasPurpleHue"); + yield return new TestCaseData (new CommonColor (0, 255, 255)).Returns (new CommonColor (0, 255, 255)) + .SetName ("HueFromColorCyanHueHasCyanHue"); + // Darker shades of primary colors map to the fully-saturated shade + yield return new TestCaseData (new CommonColor (127, 0, 0)).Returns (new CommonColor (255, 0, 0)) + .SetName ("HueFromColorDarkRedHasRedHue"); + yield return new TestCaseData (new CommonColor (0, 127, 0)).Returns (new CommonColor (0, 255, 0)) + .SetName ("HueFromColorDarkGreenHasGreenHue"); + yield return new TestCaseData (new CommonColor (0, 0, 127)).Returns (new CommonColor (0, 0, 255)) + .SetName ("HueFromColorDarkBlueHasBlueHue"); + yield return new TestCaseData (new CommonColor (127, 127, 0)).Returns (new CommonColor (255, 255, 0)) + .SetName ("HueFromColorDarkYellowHasYellowHue"); + yield return new TestCaseData (new CommonColor (127, 0, 127)).Returns (new CommonColor (255, 0, 255)) + .SetName ("HueFromColorDarkPurpleHasPurpleHue"); + yield return new TestCaseData (new CommonColor (0, 127, 127)).Returns (new CommonColor (0, 255, 255)) + .SetName ("HueFromColorDarkCyanHasCyanHue"); + // Saturated shades of non-primary colors map to themselves + yield return new TestCaseData (new CommonColor (255, 142, 0)).Returns (new CommonColor (255, 142, 0)) + .SetName ("HueFromColorOrangeHueHasOrangeHue"); + yield return new TestCaseData (new CommonColor (255, 0, 142)).Returns (new CommonColor (255, 0, 142)) + .SetName ("HueFromColorPinkHueHasPinkHue"); + yield return new TestCaseData (new CommonColor (142, 255, 0)).Returns (new CommonColor (142, 255, 0)) + .SetName ("HueFromColorYellowishGreenHueHasYellowishGreenHue"); + yield return new TestCaseData (new CommonColor (0, 255, 142)).Returns (new CommonColor (0, 255, 142)) + .SetName ("HueFromColorBlueishGreenHueHasBlueishGreenHue"); + yield return new TestCaseData (new CommonColor (142, 0, 255)).Returns (new CommonColor (142, 0, 255)) + .SetName ("HueFromColorDeepPurpleHueHasDeepPurpleHue"); + yield return new TestCaseData (new CommonColor (0, 142, 255)).Returns (new CommonColor (0, 142, 255)) + .SetName ("HueFromColorBoringBlueHueHasBoringBlueHue"); + // More random colors (and also check alpha is 255) + yield return new TestCaseData (new CommonColor (42, 142, 194, 78)).Returns (new CommonColor (0, 167, 255, 255)) + .SetName ("HueFromColorPetroleumBlueHasSaturatedBlueHue"); + yield return new TestCaseData (new CommonColor (142, 42, 194)).Returns (new CommonColor (167, 0, 255)) + .SetName ("HueFromColorUglyPurpleHasSaturatedUglyPurpleHue"); + yield return new TestCaseData (new CommonColor (142, 194, 42)).Returns (new CommonColor (167, 255, 0)) + .SetName ("HueFromColorKhakiHasSaturatedGreenHue"); + yield return new TestCaseData (new CommonColor (42, 194, 142)).Returns (new CommonColor (0, 255, 167)) + .SetName ("HueFromColorDullGreenHasSaturatedGreenHue"); + yield return new TestCaseData (new CommonColor (194, 42, 142)).Returns (new CommonColor (255, 0, 167)) + .SetName ("HueFromColorPetroleumBlueHasSaturatedBlueHue"); + yield return new TestCaseData (new CommonColor (194, 142, 42)).Returns (new CommonColor (255, 167, 0)) + .SetName ("HueFromDullBrownHasOrangeHue"); + } + } +} |