Utils { public static float getHue(float value, float min, float max, int minColor, int maxColor) { float hue; if (min == max || value <= min) { hue = minColor; } else if (value > max) { hue = maxColor; } else { float colorValue = (value - min) / (max - min); hue = minColor + colorValue * (maxColor - minColor); } float result = hue % 360.0f; if (result >= 360.0 || result < 0) { result = 0; } return result; }  static float getHue(float value, float min, float max, int minColor, int maxColor); static float metersToFeet(float meters); static float kmhToMph(float kmh); static float kmhToKt(float kmh); static float msToFpm(float ms);  }
@Test public void getHue() { float hue = Utils.getHue(0, 0, 100, 120, 360); Assert.assertEquals(hue, 120, 0.1); hue = Utils.getHue(4, 1, 7, 90, 180); Assert.assertEquals(hue, 135, 0.1); }
@Test public void getHue_exceed() { float hue = Utils.getHue(1, 2, 3, 0, 90); Assert.assertEquals(hue, 0, 0.1); hue = Utils.getHue(2, 0, 1, 0, 90); Assert.assertEquals(hue, 90, 0.1); }
@Test public void getHue_invalid() { float hue = Utils.getHue(1, 0, 0, 0, 360); Assert.assertEquals(hue, 0, 0.1); hue = Utils.getHue(1, 0, 1, 0, 360); Assert.assertEquals(hue, 0, 0.1); }