RatioNumber extends Number implements Comparable<RatioNumber> { @Override public int intValue() { return (int) 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 testIntValue() throws Exception { Assert.assertEquals(1, new RatioNumber(1.0, 1.0).intValue()); assertEquals(0, new RatioNumber(1.0, 0.1).intValue()); assertEquals(0, new RatioNumber(1.0, 0.0).intValue()); assertEquals(0, new RatioNumber(1.0, 0.5).intValue()); assertEquals(1, new RatioNumber(1.0, 1.1).intValue()); assertEquals(1, new RatioNumber(0.0, 1.1).intValue()); }