fix tests

This commit is contained in:
Bane Stojkovic
2025-12-29 10:54:39 +01:00
parent 721d582dcd
commit 9be97f5213
2 changed files with 12 additions and 1 deletions
@@ -101,7 +101,9 @@ public class CalcUtils {
return null;
}
double luminance = calculateLuminance(color);
Color monochromeColor = (luminance < threshold) ? Color.BLACK : Color.WHITE;
// Use <= to handle edge case where luminance equals threshold (should be white)
// Add small epsilon to account for floating point precision issues
Color monochromeColor = (luminance < threshold - 1e-10) ? Color.BLACK : Color.WHITE;
// Preserve alpha channel if present
if (color.getAlpha() < 255) {
monochromeColor = new Color(monochromeColor.getRed(), monochromeColor.getGreen(),
@@ -229,8 +229,17 @@ public class CalcUtilsTest {
@Test
public void testConvertToMonochromeWithAlpha() {
// Test color with alpha channel - alpha should be preserved
// Red (255, 0, 0) has luminance ~76, which is < 128, so it becomes BLACK
Color transparentRed = new Color(255, 0, 0, 128);
Color result = CalcUtils.convertToMonochrome(transparentRed);
assertEquals(Color.BLACK.getRed(), result.getRed());
assertEquals(Color.BLACK.getGreen(), result.getGreen());
assertEquals(Color.BLACK.getBlue(), result.getBlue());
assertEquals(128, result.getAlpha());
// Test light color with alpha - should become WHITE
Color transparentLight = new Color(255, 255, 200, 128);
result = CalcUtils.convertToMonochrome(transparentLight);
assertEquals(Color.WHITE.getRed(), result.getRed());
assertEquals(Color.WHITE.getGreen(), result.getGreen());
assertEquals(Color.WHITE.getBlue(), result.getBlue());