Skip to content

Commit f96d287

Browse files
Update ColorNumericsTests.cs
1 parent 6b486e3 commit f96d287

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,59 @@ public void GetBT709Luminance_WithVector4(float x, float y, float z, int luminan
2424
Assert.Equal(expected, actual);
2525
}
2626

27-
// TODO: We need to test all ColorNumerics methods!
27+
[Theory]
28+
[InlineData((ushort)0, (byte)0)]
29+
[InlineData((ushort)128, (byte)0)]
30+
[InlineData((ushort)129, (byte)1)]
31+
[InlineData((ushort)257, (byte)1)]
32+
[InlineData((ushort)32896, (byte)128)]
33+
[InlineData(ushort.MaxValue, byte.MaxValue)]
34+
public void From16BitTo8Bit_ReturnsExpectedValue(ushort component, byte expected)
35+
{
36+
byte actual = ColorNumerics.From16BitTo8Bit(component);
37+
38+
Assert.Equal(expected, actual);
39+
}
40+
41+
[Fact]
42+
public void From16BitTo8Bit_RoundTripsAllExpanded8BitValues()
43+
{
44+
for (int i = 0; i <= byte.MaxValue; i++)
45+
{
46+
byte expected = (byte)i;
47+
ushort component = ColorNumerics.From8BitTo16Bit(expected);
48+
49+
byte actual = ColorNumerics.From16BitTo8Bit(component);
50+
51+
Assert.Equal(expected, actual);
52+
}
53+
}
54+
55+
[Theory]
56+
[InlineData(0U, (byte)0)]
57+
[InlineData(8421504U, (byte)0)]
58+
[InlineData(8421505U, (byte)1)]
59+
[InlineData(16843009U, (byte)1)]
60+
[InlineData(2155905152U, (byte)128)]
61+
[InlineData(uint.MaxValue, byte.MaxValue)]
62+
public void From32BitTo8Bit_ReturnsExpectedValue(uint component, byte expected)
63+
{
64+
byte actual = ColorNumerics.From32BitTo8Bit(component);
65+
66+
Assert.Equal(expected, actual);
67+
}
68+
69+
[Fact]
70+
public void From32BitTo8Bit_RoundTripsAllExpanded8BitValues()
71+
{
72+
for (int i = 0; i <= byte.MaxValue; i++)
73+
{
74+
byte expected = (byte)i;
75+
uint component = ColorNumerics.From8BitTo32Bit(expected);
76+
77+
byte actual = ColorNumerics.From32BitTo8Bit(component);
78+
79+
Assert.Equal(expected, actual);
80+
}
81+
}
2882
}

0 commit comments

Comments
 (0)