DistanceCalculator { public static double calculate(Color colorToChange, Color colorToKeep) { return (double) Math.round(Math.abs((Math.cbrt(Math.pow(Double.valueOf(colorToChange.getRed()) - Double.valueOf(colorToKeep.getRed()), CUBIC) + Math.pow(Double.valueOf(colorToChange.getGreen()) - Double.valueOf(colorToKeep.getGreen()), CUBIC) + Math.pow(Double.valueOf(colorToChange.getBlue()) - Double.valueOf(colorToKeep.getBlue()), CUBIC)))) * ROUND_VALUE) / ROUND_VALUE; } private  DistanceCalculator(); static double calculate(Color colorToChange, Color colorToKeep);  }
@Test public void testCalculateWhiteBlack() { Color colorA = Color.WHITE; Color colorB = Color.BLACK; System.out.println("DistanceCalculator - CalculateWhiteBlack : [WHITE] and [BLACK]"); double result = DistanceCalculator.calculate(colorA, colorB); assertEquals(367.77, result, 0.001); }
@Test public void testCalculateBlackWhite() { Color colorA = Color.BLACK; Color colorB = Color.WHITE; System.out.println("DistanceCalculator - CalculateBlackWhite : [BLACK] and [WHITE]"); double result = DistanceCalculator.calculate(colorA, colorB); assertEquals(367.77, result, 0.001); }
@Test public void testCalculateWhiteSilverRgb() { Color colorA = Color.WHITE; Color colorB = new Color(192,192,192); System.out.println("DistanceCalculator - CalculateWhiteSilverRgb : [WHITE] and [rgb(192,192,192) = SILVER]"); double result = DistanceCalculator.calculate(colorA, colorB); assertEquals(90.86, result, 0.001); }
@Test public void testCalculateTwoGreenRgb() { Color colorA = new Color(70, 136, 71); Color colorB = new Color(66, 118, 69); System.out.println("DistanceCalculator - CalculateTwoGreenRgb : [rgb(70, 136, 71) = #468847] and [rgb(66, 118, 69) = #427645]"); double result = DistanceCalculator.calculate(colorA, colorB); assertEquals(18.07, result, 0.001); }