From: Bryan T. <tho...@us...> - 2007-08-16 10:49:20
|
Update of /cvsroot/cweb/generic-test/src/java/org/CognitiveWeb/generic/gql In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv27969/src/java/org/CognitiveWeb/generic/gql Modified Files: GValueTestCase.java Log Message: Moved ulps support into the junit-test module (TestCase2 class). Index: GValueTestCase.java =================================================================== RCS file: /cvsroot/cweb/generic-test/src/java/org/CognitiveWeb/generic/gql/GValueTestCase.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GValueTestCase.java 10 Jun 2006 18:16:05 -0000 1.10 --- GValueTestCase.java 16 Aug 2007 09:49:45 -0000 1.11 *************** *** 81,487 **** } ! //************************************************************ ! //************************************************************ ! //************************************************************ ! ! /** ! * Derived from <a ! * href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm"> ! * Comparing floating point numbers </a> by Bruce Dawson. ! * ! * @param A A floating point value. ! * @param B Another floating point value ! * @param maxUlps The maximum error in terms of Units in the Last ! * Place. This specifies how big an error we are willing to accept ! * in terms of the value of the least significant digit of the ! * floating point numbers representation. <i>maxUlps</i> can ! * also be interpreted in terms of how many representable floats ! * we are willing to accept between A and B. This function will ! * allow <code>maxUlps-1</code> floats between <i>A</i> and ! * <i>B</i>. ! */ ! ! static protected int getUlps ! // static public boolean AlmostEqual2sComplement ! ( float A, ! float B ! // , ! // int maxUlps ! ) ! { ! ! // // Make sure maxUlps is non-negative and small enough that the ! // // default NAN won't compare as equal to anything. ! ! // if( ! (maxUlps > 0 && maxUlps < 4 * 1024 * 1024) ) { ! ! // throw new IllegalArgumentException ! // ( "maxUlps is out of range: "+maxUlps ! // ); ! ! // } ! ! int aInt = Float.floatToIntBits( A ); // *(int*)&A; ! ! // Make aInt lexicographically ordered as a twos-complement ! // int. ! ! if (aInt < 0) { ! ! aInt = 0x80000000 - aInt; ! ! } ! ! // Make bInt lexicographically ordered as a twos-complement ! // int. ! ! int bInt = Float.floatToIntBits( B ); // *(int*)&B; ! ! if (bInt < 0) { ! ! bInt = 0x80000000 - bInt; ! ! } ! ! int intDiff = Math.abs ! ( aInt - bInt ! ); ! ! return intDiff; ! ! // if (intDiff <= maxUlps) { ! ! // return true; ! ! // } ! ! // return false; ! ! } ! ! /** ! * Derived from <a ! * href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm"> ! * Comparing floating point numbers </a> by Bruce Dawson. ! * ! * @param A A double precision floating point value. ! * @param B Another double precision floating point value ! * @param maxUlps The maximum error in terms of Units in the Last ! * Place. This specifies how big an error we are willing to accept ! * in terms of the value of the least significant digit of the ! * floating point numbers representation. <i>maxUlps</i> can ! * also be interpreted in terms of how many representable doubles ! * we are willing to accept between A and B. This function will ! * allow <code>maxUlps-1</code> doubles between <i>A</i> and ! * <i>B</i>. ! */ ! ! static protected long getUlps ! // static public boolean AlmostEqual2sComplement ! ( double A, ! double B ! // , ! // long maxUlps ! ) ! { ! ! // Make sure maxUlps is non-negative and small enough that the ! // default NAN won't compare as equal to anything. ! // ! // @todo The range check here is for float. The max possible ! // legal range is larger for double. ! ! // if( ! (maxUlps > 0 && maxUlps < 4 * 1024 * 1024) ) { ! ! // throw new IllegalArgumentException ! // ( "maxUlps is out of range: "+maxUlps ! // ); ! ! // } ! ! long aLong = Double.doubleToLongBits( A ); // *(int*)&A; ! ! // Make aInt lexicographically ordered as a twos-complement ! // long. ! ! if (aLong < 0) { ! ! aLong = 0x8000000000000000L - aLong; ! ! } ! ! // Make bInt lexicographically ordered as a twos-complement ! // int. ! ! long bLong = Double.doubleToLongBits( B ); // *(int*)&B; ! ! if (bLong < 0) { ! ! bLong = 0x8000000000000000L - bLong; ! ! } ! ! long longDiff = Math.abs ! ( aLong - bLong ! ); ! ! ! return longDiff; ! ! // if (longDiff <= maxUlps) { ! ! // return true; ! ! // } ! ! // return false; ! ! } ! ! /** ! * Provides a proper basis for comparing floating point numbers. ! */ ! ! public static void assertEquals ! ( float expected, ! float actual ! ) ! { ! assertEquals ! ( "", ! expected, ! actual ! ); ! } ! ! /** ! * Provides a proper basis for comparing floating point numbers. ! */ ! ! public static void assertEquals ! ( String message, ! float expected, ! float actual ! ) ! { ! ! if( expected == actual ) return; ! ! final int maxUlps = 10; ! ! int ulps = getUlps( expected, actual ); ! ! if( ulps <= maxUlps ) { ! ! return; ! ! } ! ! fail( "Expecting "+expected+", not "+actual+ ! ": abs(difference)="+Math.abs( expected - actual )+ ! ": ulps="+ulps ! ); ! ! } ! ! public static void assertEquals ! ( double expected, ! double actual ! ) ! { ! assertEquals ! ( "", ! expected, ! actual ! ); ! } ! ! public static void assertEquals ! ( String message, ! double expected, ! double actual ! ) ! { ! ! if( expected == actual ) return; ! ! ! final long maxUlps = 10L; ! ! long ulps = getUlps( expected, actual ); ! ! if( ulps <= maxUlps ) { ! ! return; ! ! } ! ! fail( "Expecting "+expected+", not "+actual+ ! ": abs(difference)="+Math.abs( expected - actual )+ ! ", ulps="+ulps ! ); ! ! } ! ! public static void assertSameBigInteger ! ( BigInteger expected, ! BigInteger actual ! ) ! { ! ! assertSameBigInteger ! ( "", ! expected, ! actual ! ); ! ! } ! ! public static void assertSameBigInteger ! ( String message, ! BigInteger expected, ! BigInteger actual ! ) ! { ! ! assertTrue ! ( message+": expected "+expected+", not "+actual, ! expected.equals( actual ) ! ); ! ! } ! ! /** ! * This uses {@link BigDecimal#compareTo( Object other )}, which ! * considers that two {@link BigDecimal}s that are equal in ! * <i>value</i> but have a different <i>scale</i> are the same. ! * (This is NOT true of {@link BigDecimal#equals( Object other )}, ! * which also requires the values to ave the same <i>scale</i>.) ! */ ! ! public static void assertSameBigDecimal ! ( BigDecimal expected, ! BigDecimal actual ! ) ! { ! ! assertEquals ! ( "", ! expected, ! actual ! ); ! ! } ! ! /** ! * This uses {@link BigDecimal#compareTo( Object other )}, which ! * considers that two {@link BigDecimal}s that are equal in ! * <i>value</i> but have a different <i>scale</i> are the same. ! * (This is NOT true of {@link BigDecimal#equals( Object other )}, ! * which also requires the values to ave the same <i>scale</i>.) ! */ ! ! public static void assertSameBigDecimal ! ( String message, ! BigDecimal expected, ! BigDecimal actual ! ) ! { ! ! assertTrue ! ( message+": expected "+expected+", not "+actual, ! expected.compareTo( actual ) == 0 ! ); ! ! } ! ! /** ! * Helper method verifies that the arrays are consistent in length ! * and that their elements are consistent under {@link ! * Object#equals( Object other )}. ! */ ! ! public static void assertSameArray ! ( Object[] expected, ! Object[] actual ! ) ! { ! assertSameArray ! ( "", ! expected, ! actual ! ); ! } ! ! /** ! * Helper method verifies that the arrays are consistent in length ! * and that their elements are consistent under {@link ! * Object#equals( Object other )}. ! */ ! ! public static void assertSameArray ! ( String message, ! Object[] expected, ! Object[] actual ! ) ! { ! ! if( expected == null && actual == null ) { ! ! return; ! ! } ! ! if( expected != null && actual == null ) { ! ! fail( message+" : expecting actual to be non-null." ! ); ! ! } ! ! if( expected == null && actual != null ) { ! ! fail( message+" : expecting actual to be null." ! ); ! ! } ! ! assertEquals ! ( message+" : length is wrong.", ! expected.length, ! actual.length ! ); ! ! for( int i=0; i<expected.length; i++ ) { ! ! if( expected[i] == null && actual[i] == null ) { ! ! continue; ! ! } ! ! if( expected[i] != null && actual[i] == null ) { ! ! fail( message+" : expecting actual["+i+"] to be non-null" ! ); ! ! } ! ! if( expected[i] == null && actual[i] != null ) { ! ! fail( message+" : expecting actual["+i+"] to be null." ! ); ! ! } ! ! assertTrue ! ( message+" : expected["+i+"]="+expected[i]+ ! ", but actual["+i+"]="+actual[i], ! expected[i].equals( actual[i] ) ! ); ! ! } ! ! } //************************************************************ --- 81,487 ---- } ! // //************************************************************ ! // //************************************************************ ! // //************************************************************ ! // ! // /** ! // * Derived from <a ! // * href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm"> ! // * Comparing floating point numbers </a> by Bruce Dawson. ! // * ! // * @param A A floating point value. ! // * @param B Another floating point value ! // * @param maxUlps The maximum error in terms of Units in the Last ! // * Place. This specifies how big an error we are willing to accept ! // * in terms of the value of the least significant digit of the ! // * floating point numbers representation. <i>maxUlps</i> can ! // * also be interpreted in terms of how many representable floats ! // * we are willing to accept between A and B. This function will ! // * allow <code>maxUlps-1</code> floats between <i>A</i> and ! // * <i>B</i>. ! // */ ! // ! // static protected int getUlps ! //// static public boolean AlmostEqual2sComplement ! // ( float A, ! // float B ! //// , ! //// int maxUlps ! // ) ! // { ! // ! //// // Make sure maxUlps is non-negative and small enough that the ! //// // default NAN won't compare as equal to anything. ! // ! //// if( ! (maxUlps > 0 && maxUlps < 4 * 1024 * 1024) ) { ! // ! //// throw new IllegalArgumentException ! //// ( "maxUlps is out of range: "+maxUlps ! //// ); ! // ! //// } ! // ! // int aInt = Float.floatToIntBits( A ); // *(int*)&A; ! // ! // // Make aInt lexicographically ordered as a twos-complement ! // // int. ! // ! // if (aInt < 0) { ! // ! // aInt = 0x80000000 - aInt; ! // ! // } ! // ! // // Make bInt lexicographically ordered as a twos-complement ! // // int. ! // ! // int bInt = Float.floatToIntBits( B ); // *(int*)&B; ! // ! // if (bInt < 0) { ! // ! // bInt = 0x80000000 - bInt; ! // ! // } ! // ! // int intDiff = Math.abs ! // ( aInt - bInt ! // ); ! // ! // return intDiff; ! // ! //// if (intDiff <= maxUlps) { ! // ! //// return true; ! // ! //// } ! // ! //// return false; ! // ! // } ! // ! // /** ! // * Derived from <a ! // * href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm"> ! // * Comparing floating point numbers </a> by Bruce Dawson. ! // * ! // * @param A A double precision floating point value. ! // * @param B Another double precision floating point value ! // * @param maxUlps The maximum error in terms of Units in the Last ! // * Place. This specifies how big an error we are willing to accept ! // * in terms of the value of the least significant digit of the ! // * floating point numbers representation. <i>maxUlps</i> can ! // * also be interpreted in terms of how many representable doubles ! // * we are willing to accept between A and B. This function will ! // * allow <code>maxUlps-1</code> doubles between <i>A</i> and ! // * <i>B</i>. ! // */ ! // ! // static protected long getUlps ! //// static public boolean AlmostEqual2sComplement ! // ( double A, ! // double B ! //// , ! //// long maxUlps ! // ) ! // { ! // ! // // Make sure maxUlps is non-negative and small enough that the ! // // default NAN won't compare as equal to anything. ! // // ! // // @todo The range check here is for float. The max possible ! // // legal range is larger for double. ! // ! //// if( ! (maxUlps > 0 && maxUlps < 4 * 1024 * 1024) ) { ! // ! //// throw new IllegalArgumentException ! //// ( "maxUlps is out of range: "+maxUlps ! //// ); ! // ! //// } ! // ! // long aLong = Double.doubleToLongBits( A ); // *(int*)&A; ! // ! // // Make aInt lexicographically ordered as a twos-complement ! // // long. ! // ! // if (aLong < 0) { ! // ! // aLong = 0x8000000000000000L - aLong; ! // ! // } ! // ! // // Make bInt lexicographically ordered as a twos-complement ! // // int. ! // ! // long bLong = Double.doubleToLongBits( B ); // *(int*)&B; ! // ! // if (bLong < 0) { ! // ! // bLong = 0x8000000000000000L - bLong; ! // ! // } ! // ! // long longDiff = Math.abs ! // ( aLong - bLong ! // ); ! // ! // ! // return longDiff; ! // ! //// if (longDiff <= maxUlps) { ! // ! //// return true; ! // ! //// } ! // ! //// return false; ! // ! // } ! // ! // /** ! // * Provides a proper basis for comparing floating point numbers. ! // */ ! // ! // public static void assertEquals ! // ( float expected, ! // float actual ! // ) ! // { ! // assertEquals ! // ( "", ! // expected, ! // actual ! // ); ! // } ! // ! // /** ! // * Provides a proper basis for comparing floating point numbers. ! // */ ! // ! // public static void assertEquals ! // ( String message, ! // float expected, ! // float actual ! // ) ! // { ! // ! // if( expected == actual ) return; ! // ! // final int maxUlps = 10; ! // ! // int ulps = getUlps( expected, actual ); ! // ! // if( ulps <= maxUlps ) { ! // ! // return; ! // ! // } ! // ! // fail( "Expecting "+expected+", not "+actual+ ! // ": abs(difference)="+Math.abs( expected - actual )+ ! // ": ulps="+ulps ! // ); ! // ! // } ! // ! // public static void assertEquals ! // ( double expected, ! // double actual ! // ) ! // { ! // assertEquals ! // ( "", ! // expected, ! // actual ! // ); ! // } ! // ! // public static void assertEquals ! // ( String message, ! // double expected, ! // double actual ! // ) ! // { ! // ! // if( expected == actual ) return; ! // ! // ! // final long maxUlps = 10L; ! // ! // long ulps = getUlps( expected, actual ); ! // ! // if( ulps <= maxUlps ) { ! // ! // return; ! // ! // } ! // ! // fail( "Expecting "+expected+", not "+actual+ ! // ": abs(difference)="+Math.abs( expected - actual )+ ! // ", ulps="+ulps ! // ); ! // ! // } ! // ! // public static void assertSameBigInteger ! // ( BigInteger expected, ! // BigInteger actual ! // ) ! // { ! // ! // assertSameBigInteger ! // ( "", ! // expected, ! // actual ! // ); ! // ! // } ! // ! // public static void assertSameBigInteger ! // ( String message, ! // BigInteger expected, ! // BigInteger actual ! // ) ! // { ! // ! // assertTrue ! // ( message+": expected "+expected+", not "+actual, ! // expected.equals( actual ) ! // ); ! // ! // } ! // ! // /** ! // * This uses {@link BigDecimal#compareTo( Object other )}, which ! // * considers that two {@link BigDecimal}s that are equal in ! // * <i>value</i> but have a different <i>scale</i> are the same. ! // * (This is NOT true of {@link BigDecimal#equals( Object other )}, ! // * which also requires the values to ave the same <i>scale</i>.) ! // */ ! // ! // public static void assertSameBigDecimal ! // ( BigDecimal expected, ! // BigDecimal actual ! // ) ! // { ! // ! // assertEquals ! // ( "", ! // expected, ! // actual ! // ); ! // ! // } ! // ! // /** ! // * This uses {@link BigDecimal#compareTo( Object other )}, which ! // * considers that two {@link BigDecimal}s that are equal in ! // * <i>value</i> but have a different <i>scale</i> are the same. ! // * (This is NOT true of {@link BigDecimal#equals( Object other )}, ! // * which also requires the values to ave the same <i>scale</i>.) ! // */ ! // ! // public static void assertSameBigDecimal ! // ( String message, ! // BigDecimal expected, ! // BigDecimal actual ! // ) ! // { ! // ! // assertTrue ! // ( message+": expected "+expected+", not "+actual, ! // expected.compareTo( actual ) == 0 ! // ); ! // ! // } ! // ! // /** ! // * Helper method verifies that the arrays are consistent in length ! // * and that their elements are consistent under {@link ! // * Object#equals( Object other )}. ! // */ ! // ! // public static void assertSameArray ! // ( Object[] expected, ! // Object[] actual ! // ) ! // { ! // assertSameArray ! // ( "", ! // expected, ! // actual ! // ); ! // } ! // ! // /** ! // * Helper method verifies that the arrays are consistent in length ! // * and that their elements are consistent under {@link ! // * Object#equals( Object other )}. ! // */ ! // ! // public static void assertSameArray ! // ( String message, ! // Object[] expected, ! // Object[] actual ! // ) ! // { ! // ! // if( expected == null && actual == null ) { ! // ! // return; ! // ! // } ! // ! // if( expected != null && actual == null ) { ! // ! // fail( message+" : expecting actual to be non-null." ! // ); ! // ! // } ! // ! // if( expected == null && actual != null ) { ! // ! // fail( message+" : expecting actual to be null." ! // ); ! // ! // } ! // ! // assertEquals ! // ( message+" : length is wrong.", ! // expected.length, ! // actual.length ! // ); ! // ! // for( int i=0; i<expected.length; i++ ) { ! // ! // if( expected[i] == null && actual[i] == null ) { ! // ! // continue; ! // ! // } ! // ! // if( expected[i] != null && actual[i] == null ) { ! // ! // fail( message+" : expecting actual["+i+"] to be non-null" ! // ); ! // ! // } ! // ! // if( expected[i] == null && actual[i] != null ) { ! // ! // fail( message+" : expecting actual["+i+"] to be null." ! // ); ! // ! // } ! // ! // assertTrue ! // ( message+" : expected["+i+"]="+expected[i]+ ! // ", but actual["+i+"]="+actual[i], ! // expected[i].equals( actual[i] ) ! // ); ! // ! // } ! // ! // } //************************************************************ |