1package libcore.java.math;
2
3import java.lang.reflect.Method;
4
5/**
6 * Tests java.lang.StrictMath
7 * Looks for the filenames in csvFileNames in tests/resources
8 * Tests functions and numbers found in those files.
9 * Run: vogar --classpath out/target/common/obj/JAVA_LIBRARIES/core-tests-support_intermediates/javalib.jar
10 * libcore/luni/src/test/java/libcore/java/math/RunCSVTestsStrict.java
11 */
12public class RunCSVTestsStrict extends CSVTest {
13    public static final String[] csvFileNames = { "/math_tests.csv",
14            "/math_important_numbers.csv", "/math_java_only.csv" };
15
16    public void test_csv() throws Exception {
17        this.TestCSVInputs(csvFileNames);
18    }
19
20    /**
21     * Runs single-input test using assertEquals.
22     */
23    @Override
24    void runTest(String func, double expectedOutput, double input, String extra)
25            throws Exception {
26        Class<StrictMath> mathClass = StrictMath.class;
27        Method m = mathClass.getMethod(func, new Class[] { Double.TYPE });
28        Object returnValue = m.invoke(null, input);
29
30        try {
31            assertEquals(extra + ": " + m + ": " + input + ": ", expectedOutput,
32                    (double) returnValue, 0D);
33        } catch (ClassCastException e) {
34            assertEquals(extra + ": " + m + ": " + input + ": ", (int) expectedOutput,
35                    (int) returnValue, 0D);
36        }
37    }
38
39    /**
40     * Runs 2-input test using assertEquals.
41     */
42    @Override
43    void run2InputTest(String func, double expectedOutput, double input1,
44            double input2, String extra) throws Exception {
45        Class<StrictMath> mathClass = StrictMath.class;
46        Method m;
47        Object returnValue;
48        if (func.equals("scalb")) {
49            m = mathClass.getMethod(func, new Class[] { Double.TYPE, Integer.TYPE });
50            returnValue = m.invoke(null, input1, (int) input2);
51        } else {
52            m = mathClass.getMethod(func, new Class[] { Double.TYPE, Double.TYPE });
53            returnValue = m.invoke(null, input1, input2);
54        }
55
56        try {
57            assertEquals(extra + ": " + m + ": " , expectedOutput, (double) returnValue, 0D);
58        } catch (ClassCastException e) {
59            assertEquals(extra + ": " + m + ": ", (int) expectedOutput, (int) returnValue, 0D);
60        }
61    }
62}
63