Skip to content

Commit aca9d0f

Browse files
committed
Improve #275 - Add test coverage for hash codes
1 parent add0e76 commit aca9d0f

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

CSF.Screenplay.Selenium/Color.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public override bool Equals(object obj)
192192
public override string ToString() => ToRgbaString();
193193

194194
/// <inheritdoc/>
195-
public override int GetHashCode() => HashCode.Combine(Red, Green, Blue, Alpha);
195+
public override int GetHashCode() => HashCode.Combine(Red, Green, Blue, AlphaAsByte);
196196

197197
/// <summary>
198198
/// Creates a new instance of <see cref="Color"/> from the specified RGBA values.

Tests/CSF.Screenplay.Selenium.Tests/ColorTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,29 @@ public void ParseFollowedByToHexStringShouldRoundtripTheColor(string colorString
211211
{
212212
Assert.That(() => Color.Parse(colorString).ToHexString(), Is.EqualTo(colorString));
213213
}
214+
215+
[TestCase("rgb(1, 2, 3)", 1, 2, 3, 1)]
216+
[TestCase("rgb(10%, 20%, 30%)", 25, 51, 76, 1)]
217+
[TestCase("rgb(\t1, 2, 3)", 1, 2, 3, 1)]
218+
[TestCase("rgba(1, 2, 3, 0.5)", 1, 2, 3, 0.5D)]
219+
[TestCase("rgba(10%, 20%, 30%, 0.5)", 25, 51, 76, 0.5D)]
220+
[TestCase("#ff00a0", 255, 0, 160, 1)]
221+
[TestCase("#01Ff03", 1, 255, 3, 1)]
222+
[TestCase("#00FF33", 0, 255, 51, 1)]
223+
[TestCase("#0f3", 0, 255, 51, 1)]
224+
[TestCase("hsl(120, 100%, 25%)", 0, 128, 0, 1)]
225+
[TestCase("hsl(100, 0%, 50%)", 128, 128, 128, 1)]
226+
[TestCase("hsl(0, 100%, 50%)", 255, 0, 0, 1)]
227+
[TestCase("hsl(120, 100%, 50%)", 0, 255, 0, 1)]
228+
[TestCase("hsl(240, 100%, 50%)", 0, 0, 255, 1)]
229+
[TestCase("hsl(0, 0%, 100%)", 255, 255, 255, 1)]
230+
[TestCase("hsla(120, 100%, 25%, 1)", 0, 128, 0, 1)]
231+
[TestCase("hsla(100, 0%, 50%, 0.5)", 128, 128, 128, 0.5)]
232+
[TestCase("green", 0, 128, 0, 1)]
233+
[TestCase("gray", 128, 128, 128, 1)]
234+
[TestCase("transparent", 0, 0, 0, 0)]
235+
public void GetHashCodeShouldReturnTheSameResultForEquivalentColors(string colorString, byte red, byte green, byte blue, double alpha)
236+
{
237+
Assert.That(() => Color.Parse(colorString).GetHashCode(), Is.EqualTo(new Color(red, green, blue, alpha).GetHashCode()));
238+
}
214239
}

0 commit comments

Comments
 (0)