This is the mail archive of the mauve-discuss@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: junit.framework.Assert


Hi there,

Am Montag, den 25.12.2006, 21:36 +0100 schrieb Audrius Meskauskas:
> Today I have discovered that junit.framework.Assert seems not 
> compileable, because it twice calls the non existing methods of the 
> TestHarness:
> check(double, double, double).
> 
> It seems trivial to implement the workaround. Should we fix this?

Ugh. Seems like I forgot to check this bit in when I implemented the
JUnit API in Mauve. A wonder that nobody stepped over this so far,
especially since I already checked in a bulk of tests based on the JUnit
API. Here comes the fix...

2006-12-28  Roman Kennke <kennke@aicas.com>

	* gnu/testlet/TestHarness.java
	(check(double,double,double)): New method. Tests two double values
	with a certain threshold.

/Roman

Index: gnu/testlet/TestHarness.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/TestHarness.java,v
retrieving revision 1.26
diff -u -1 -5 -r1.26 TestHarness.java
--- gnu/testlet/TestHarness.java	31 May 2006 17:21:42 -0000	1.26
+++ gnu/testlet/TestHarness.java	28 Dec 2006 15:36:55 -0000
@@ -115,30 +115,56 @@
     // and all without relying on java.lang.Double (which may
     // itself be buggy - else why would we be testing it? ;)
     // For 0, we switch to infinities, and for NaN, we rely
     // on the identity in JLS 15.21.1 that NaN != NaN is true.
     boolean ok = (result == expected ? (result != 0)
                                        || (1 / result == 1 / expected)
                                     : (result != result)
                                       && (expected != expected));
     check(ok);
     if (! ok)
       // If Double.toString() is buggy, this debug statement may
       // accidentally show the same string for two different doubles!
       debug("got " + result + " but expected " + expected);
   }
 
+  /**
+   * Checks if <code>result</code> is equal to <code>expected</code> and
+   * take a rounding delta into account.
+   * 
+   * @param result the actual result
+   * @param expected the expected value
+   * @param delta the rounding delta
+   */
+  public void check(double result, double expected, double delta)
+  {
+    boolean ok = true;
+    if (Double.isInfinite(expected))
+      {
+        if (result != expected)
+          ok = false;
+      }
+    else if (! (Math.abs(expected - result) <= delta))
+      ok = false;
+
+    check(ok);
+    if (! ok)
+      // If Double.toString() is buggy, this debug statement may
+      // accidentally show the same string for two different doubles!
+      debug("got " + result + " but expected " + expected);
+  }
+
   // These methods are like the above, but checkpoint first.
   public void check(boolean result, String name)
   {
     checkPoint(name);
     check(result);
   }
 
   public void check(Object result, Object expected, String name)
   {
     checkPoint(name);
     check(result, expected);
   }
 
   public void check(boolean result, boolean expected, String name)
   {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]