1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
using System;
using Microsoft.Xna.Framework;
using Xunit;
namespace MonoGame.Extended.Tests.Particles
{
public class ColourTests
{
public class Constructor
{
[Fact]
public void WhenGivenValues_ReturnsInitializedColour()
{
var colour = new HslColor(1f, 1f, 1f);
Assert.Equal(1f, colour.H);
Assert.Equal(1f, colour.S);
Assert.Equal(1f, colour.L);
}
}
public class AreEqualColourMethod
{
[Fact]
public void WhenGivenEqualValues_ReturnsTrue()
{
var x = new HslColor(360f, 1f, 1f);
var y = new HslColor(360f, 1f, 1f);
Assert.Equal(x, y);
}
[Fact]
public void WhenGivenDifferentValues_ReturnsFalse()
{
var x = new HslColor(0f, 1f, 0f);
var y = new HslColor(360f, 1f, 1f);
Assert.False(x.Equals(y));
}
}
public class AreEqualObjectMethod
{
[Fact]
public void WhenGivenEqualColour_ReturnsTrue()
{
var x = new HslColor(360f, 1f, 1f);
Object y = new HslColor(360f, 1f, 1f);
Assert.Equal(x, y);
}
[Fact]
public void WhenGivenDifferentColour_ReturnsFalse()
{
var x = new HslColor(360f, 1f, 1f);
Object y = new HslColor(0f, 1f, 0f);
Assert.False(x.Equals(y));
}
[Fact]
public void WhenGivenObjectOfAntotherType_ReturnsFalse()
{
var colour = new HslColor(360f, 1f, 1f);
// ReSharper disable once SuspiciousTypeConversion.Global
Assert.False(colour.Equals(DateTime.Now));
}
}
public class GetHashCodeMethod
{
[Fact]
public void WhenObjectsAreDifferent_YieldsDifferentHashCodes()
{
var x = new HslColor(0f, 1f, 0f);
var y = new HslColor(360f, 1f, 1f);
Assert.NotEqual(x.GetHashCode(), y.GetHashCode());
}
[Fact]
public void WhenObjectsAreSame_YieldsIdenticalHashCodes()
{
var x = new HslColor(180f, 0.5f, 0.5f);
var y = new HslColor(180f, 0.5f, 0.5f);
Assert.Equal(x.GetHashCode(), y.GetHashCode());
}
}
public class ToStringMethod
{
[Theory]
[InlineData(360f, 1f, 1f, "H:0.0° S:100.0 L:100.0")]
[InlineData(180f, 0.5f, 0.5f, "H:180.0° S:50.0 L:50.0")]
[InlineData(0f, 0f, 0f, "H:0.0° S:0.0 L:0.0")]
public void ReturnsCorrectValue(float h, float s, float l, string expected)
{
var colour = new HslColor(h, s, l);
Assert.Equal(expected, colour.ToString());
}
}
public class ToRgbMethod
{
[Theory]
[InlineData(0f, 1f, 0.5f, "{R:255 G:0 B:0 A:255}")] // Color.Red
[InlineData(360f, 1f, 0.5f, "{R:255 G:0 B:0 A:255}")] // Color.Red
[InlineData(120f, 1f, 0.5f, "{R:0 G:255 B:0 A:255}")] // Color.Lime
public void ReturnsCorrectValue(float h, float s, float l, string expected)
{
var hslColour = new HslColor(h, s, l);
Color rgbColor = hslColour.ToRgb();
Assert.Equal(expected, rgbColor.ToString());
}
[Fact]
public void FromRgbAndToRgbWorksCorrectly()
{
HslColor blueHsl = HslColor.FromRgb(Color.Blue);
Color blueRgb = blueHsl.ToRgb();
Assert.Equal(Color.Blue, blueRgb);
}
}
}
}
|