RatioNumber extends Number implements Comparable<RatioNumber> { @Override public float floatValue() { return (float) (ratio); } RatioNumber(double value, double ratio); static RatioNumber valueOf(String valueString); @Override int intValue(); @Override long longValue(); @Override float floatValue(); @Override double doubleValue(); @Override int compareTo(RatioNumber other); RatioNumber add(RatioNumber other); double value(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final RatioNumber ZERO; }
@Test public void testFloatValue() throws Exception { assertEquals(1.0f, new RatioNumber(1.0, 1.0).floatValue(), 0.0f); assertEquals(0.1f, new RatioNumber(1.0, 0.1).floatValue(), 0.0f); assertEquals(1.0f, new RatioNumber(0.0, 1.0).floatValue(), 0.0f); assertEquals(0.5f, new RatioNumber(1, 0.5).floatValue(), 0.0f); assertEquals(1.1f, new RatioNumber(1, 1.1).floatValue(), 0.0f); assertEquals(0.0f, new RatioNumber(11, 0.0).floatValue(), 0.0f); }