Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 540 invoked from network); 24 Jan 2011 18:08:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Jan 2011 18:08:16 -0000 Received: (qmail 27468 invoked by uid 500); 24 Jan 2011 18:08:15 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 27152 invoked by uid 500); 24 Jan 2011 18:08:13 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 27145 invoked by uid 99); 24 Jan 2011 18:08:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jan 2011 18:08:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jan 2011 18:08:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3CF182388A36; Mon, 24 Jan 2011 18:07:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1062902 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java Date: Mon, 24 Jan 2011 18:07:49 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110124180749.3CF182388A36@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebb Date: Mon Jan 24 18:07:48 2011 New Revision: 1062902 URL: http://svn.apache.org/viewvc?rev=1062902&view=rev Log: Remove reflection tests as they are in FastMathStrictComparisonTest Enable fail if not all StrictMath methods have been implemented Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java?rev=1062902&r1=1062901&r2=1062902&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java Mon Jan 24 18:07:48 2011 @@ -16,11 +16,9 @@ */ package org.apache.commons.math.util; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.util.Arrays; import org.apache.commons.math.dfp.Dfp; import org.apache.commons.math.dfp.DfpField; @@ -37,25 +35,6 @@ public class FastMathTest { private static final double MAX_ERROR_ULP = 0.51; private static final int NUMBER_OF_TRIALS = 1000; - // Values which often need special handling - private static final Double[] DOUBLE_SPECIAL_VALUES = { - -0.0, +0.0, // 1,2 - Double.NaN, // 3 - Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, // 4,5 - -Double.MAX_VALUE, Double.MAX_VALUE, // 6,7 - // decreasing order of absolute value to help catch first failure - -MathUtils.EPSILON, MathUtils.EPSILON, // 8,9 - -MathUtils.SAFE_MIN, MathUtils.SAFE_MIN, // 10,11 - -Double.MIN_VALUE, Double.MIN_VALUE, // 12,13 - }; - - private static final Float [] FLOAT_SPECIAL_VALUES = { - -0.0f, +0.0f, // 1,2 - Float.NaN, // 3 - Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, // 4,5 - Float.MIN_VALUE, Float.MAX_VALUE, // 6,7 - -Float.MIN_VALUE, -Float.MAX_VALUE, // 8,9 - }; private DfpField field; private RandomGenerator generator; @@ -1100,124 +1079,6 @@ public class FastMathTest { Assert.assertEquals(Float.NEGATIVE_INFINITY, FastMath.scalb(-1.1e-7f, 152), 0F); } - private static void reportError(String message) { - final boolean fatal = false; - if (fatal) { - Assert.fail(message); - } else { - System.out.println(message); - } - } - - private static void check(Method mathMethod, Object[] params, Object expected, Object actual, int[] entries){ - if (!expected.equals(actual)){ - if (expected instanceof Double) { - double exp = (Double) expected; - // Need to discount 0 otherwise +0.0 == -0.0 - if (exp != 0 && MathUtils.equals(exp, (Double) actual, 1)) { - return; - } - } else { - float exp = (Float) expected; - // Need to discount 0 otherwise +0.0 == -0.0 - if (exp != 0 && MathUtils.equals(exp, ((Float) actual), 1)) { - return; - } - } - StringBuilder sb = new StringBuilder(); - sb.append(mathMethod.getReturnType().getSimpleName()); - sb.append(" "); - sb.append(mathMethod.getName()); - sb.append("("); - String sep = ""; - for(Object o : params){ - sb.append(sep); - sb.append(o); - sep=", "; - } - sb.append(") expected "); - sb.append(expected); - sb.append(" actual "); - sb.append(actual); - sb.append(" entries "); - sb.append(Arrays.toString(entries)); - reportError(sb.toString()); - } - } - - private static class CompareSpecials { - private final Object[] specialvalues; - CompareSpecials(Object[] values){ - specialvalues=values; - } - void compareSpecials(Method mathMethod, Method fastMethod, Type[] types) throws Exception { - Object[] params = new Object[types.length]; - int entry1 = 0; - int[] entries = new int[types.length]; - for(Object d : specialvalues) { - entry1++; - params[0] = d; - entries[0] = entry1; - if (params.length > 1){ - int entry2 = 0; - for(Object d1 : specialvalues) { - entry2++; - params[1] = d1; - entries[1] = entry2; - compare(mathMethod, fastMethod, params, entries); - } - } else { - compare(mathMethod, fastMethod, params, entries); - } - } - } - private void compare(Method mathMethod, Method fastMethod, - Object[] params, int[] entries) throws IllegalAccessException, - InvocationTargetException { - try { - Object expected = mathMethod.invoke(mathMethod, params); - Object actual = fastMethod.invoke(mathMethod, params); - check(mathMethod, params, expected, actual, entries); - } catch (IllegalArgumentException e) { - Assert.fail(mathMethod+" "+e); - } - } - } - - private void testSpecialCases(Class type, CompareSpecials comparer) throws Exception { - Method math[] = StrictMath.class.getDeclaredMethods(); - for(Method mathMethod : math) { - Type ret = mathMethod.getGenericReturnType(); - if (ret.equals(type) && Modifier.isPublic(mathMethod.getModifiers())){ - Type []params = mathMethod.getGenericParameterTypes(); - if (params.length >=1 && params[0].equals(type)) { - Method fastMethod = null; - String name = mathMethod.getName(); - try { - fastMethod = FastMath.class.getDeclaredMethod(name, (Class[]) params); - if (Modifier.isPublic(fastMethod.getModifiers())) { - comparer.compareSpecials(mathMethod, fastMethod, params); - } else { - System.out.println("Cannot find public FastMath method corresponding to: "+mathMethod); - } - } catch (NoSuchMethodException e) { - System.out.println("Cannot find FastMath method corresponding to: "+mathMethod); - } - } - } - } - } - - @Test - public void testFloatSpecialCases() throws Exception { - testSpecialCases(float.class, new CompareSpecials(FLOAT_SPECIAL_VALUES)); - } - - @Test - public void testDoubleSpecialCases() throws Exception { - testSpecialCases(double.class, new CompareSpecials(DOUBLE_SPECIAL_VALUES)); - } - private boolean compareClassMethods(Class class1, Class class2){ boolean allfound = true; for(Method method1 : class1.getDeclaredMethods()){ @@ -1237,7 +1098,7 @@ public class FastMathTest { @Test public void checkMissingFastMathClasses() { boolean ok = compareClassMethods(StrictMath.class, FastMath.class); - // TODO Assert.assertTrue("FastMath should implement all StrictMath methods", ok); + Assert.assertTrue("FastMath should implement all StrictMath methods", ok); } @Ignore