1 package tim.prune.jpeg.drew;
3 import static org.junit.jupiter.api.Assertions.*;
5 import org.junit.jupiter.api.Test;
8 * JUnit tests for the Rational values used by the Exif
18 for (int i=0; i<16000; i++)
23 testIntVal(-i, 1, -i);
24 testIntVal(i*2, 2, i);
25 testIntVal(i*2+1, 2, i); // rounding down the 0.5
26 testIntVal(-i*2, 2, -i);
27 testIntVal(i*2, -2, -i);
28 testIntVal(-i*2, -2, i);
33 * Check that a rational converts to an integer properly
34 * @param inTop number on top of the rational (numerator)
35 * @param inBottom number on bottom of the rational (denominator)
36 * @param inExpected expected int value
38 private void testIntVal(long inTop, long inBottom, int inExpected)
40 Rational value = new Rational(inTop, inBottom);
41 assertEquals(inExpected, value.intValue(), "" + inTop + "/" + inBottom);
45 void testManyDoubles()
47 for (int i=0; i<16000; i++)
49 testDoubleVal(0, i, 0.0);
50 testDoubleVal(i, 0, 0.0);
51 testDoubleVal(i, 1, i);
52 testDoubleVal(i*2, 2, i);
53 testDoubleVal(i*2+1, 2, i+0.5);
54 testDoubleVal(i*2, -2, -i);
57 testDoubleVal(123, 3, 123.0/3.0);
61 * Check that a rational converts to a double properly
62 * @param inTop number on top of the rational (numerator)
63 * @param inBottom number on bottom of the rational (denominator)
64 * @param inExpected expected double value (exact)
66 private void testDoubleVal(long inTop, long inBottom, double inExpected)
68 Rational value = new Rational(inTop, inBottom);
69 assertEquals(inExpected, value.doubleValue(), 0.0, "" + inTop + "/" + inBottom);