Browse Source

Update ColorNumericsTests.cs

pull/3096/head
James Jackson-South 4 weeks ago
parent
commit
f96d28714d
  1. 56
      tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs

56
tests/ImageSharp.Tests/Helpers/ColorNumericsTests.cs

@ -24,5 +24,59 @@ public class ColorNumericsTests
Assert.Equal(expected, actual);
}
// TODO: We need to test all ColorNumerics methods!
[Theory]
[InlineData((ushort)0, (byte)0)]
[InlineData((ushort)128, (byte)0)]
[InlineData((ushort)129, (byte)1)]
[InlineData((ushort)257, (byte)1)]
[InlineData((ushort)32896, (byte)128)]
[InlineData(ushort.MaxValue, byte.MaxValue)]
public void From16BitTo8Bit_ReturnsExpectedValue(ushort component, byte expected)
{
byte actual = ColorNumerics.From16BitTo8Bit(component);
Assert.Equal(expected, actual);
}
[Fact]
public void From16BitTo8Bit_RoundTripsAllExpanded8BitValues()
{
for (int i = 0; i <= byte.MaxValue; i++)
{
byte expected = (byte)i;
ushort component = ColorNumerics.From8BitTo16Bit(expected);
byte actual = ColorNumerics.From16BitTo8Bit(component);
Assert.Equal(expected, actual);
}
}
[Theory]
[InlineData(0U, (byte)0)]
[InlineData(8421504U, (byte)0)]
[InlineData(8421505U, (byte)1)]
[InlineData(16843009U, (byte)1)]
[InlineData(2155905152U, (byte)128)]
[InlineData(uint.MaxValue, byte.MaxValue)]
public void From32BitTo8Bit_ReturnsExpectedValue(uint component, byte expected)
{
byte actual = ColorNumerics.From32BitTo8Bit(component);
Assert.Equal(expected, actual);
}
[Fact]
public void From32BitTo8Bit_RoundTripsAllExpanded8BitValues()
{
for (int i = 0; i <= byte.MaxValue; i++)
{
byte expected = (byte)i;
uint component = ColorNumerics.From8BitTo32Bit(expected);
byte actual = ColorNumerics.From32BitTo8Bit(component);
Assert.Equal(expected, actual);
}
}
}

Loading…
Cancel
Save