Skip to content

Commit

Permalink
Add tests for high precision Color cases
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfirsov committed Oct 2, 2023
1 parent eb5aec5 commit fa434dd
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions tests/ImageSharp.Tests/Color/ColorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,42 @@ public void WithAlpha()
Assert.Equal(expected, (Rgba32)c2);
}

[Fact]
public void Equality_WhenTrue()
[Theory]
[InlineData(false)]
[InlineData(true)]
public void Equality_WhenTrue(bool highPrecision)
{
Color c1 = new Rgba64(100, 2000, 3000, 40000);
Color c2 = new Rgba64(100, 2000, 3000, 40000);

if (highPrecision)
{
c1 = Color.FromPixel(c1.ToPixel<RgbaVector>());
c2 = Color.FromPixel(c2.ToPixel<RgbaVector>());
}

Assert.True(c1.Equals(c2));
Assert.True(c1 == c2);
Assert.False(c1 != c2);
Assert.True(c1.GetHashCode() == c2.GetHashCode());
}

[Fact]
public void Equality_WhenFalse()
[Theory]
[InlineData(false)]
[InlineData(true)]
public void Equality_WhenFalse(bool highPrecision)
{
Color c1 = new Rgba64(100, 2000, 3000, 40000);
Color c2 = new Rgba64(101, 2000, 3000, 40000);
Color c3 = new Rgba64(100, 2000, 3000, 40001);

if (highPrecision)
{
c1 = Color.FromPixel(c1.ToPixel<RgbaVector>());
c2 = Color.FromPixel(c2.ToPixel<RgbaVector>());
c3 = Color.FromPixel(c3.ToPixel<RgbaVector>());
}

Assert.False(c1.Equals(c2));
Assert.False(c2.Equals(c3));
Assert.False(c3.Equals(c1));
Expand All @@ -47,13 +64,20 @@ public void Equality_WhenFalse()
Assert.False(c1.Equals(null));
}

[Fact]
public void ToHex()
[Theory]
[InlineData(false)]
[InlineData(true)]
public void ToHex(bool highPrecision)
{
string expected = "ABCD1234";
var color = Color.ParseHex(expected);
string actual = color.ToHex();
Color color = Color.ParseHex(expected);

if (highPrecision)
{
color = Color.FromPixel(color.ToPixel<RgbaVector>());
}

string actual = color.ToHex();
Assert.Equal(expected, actual);
}

Expand Down

0 comments on commit fa434dd

Please sign in to comment.