Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 17357 invoked from network); 26 Dec 2005 19:59:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Dec 2005 19:59:48 -0000 Received: (qmail 92584 invoked by uid 500); 26 Dec 2005 19:59:46 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 92544 invoked by uid 500); 26 Dec 2005 19:59:46 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 92533 invoked by uid 500); 26 Dec 2005 19:59:45 -0000 Received: (qmail 92530 invoked by uid 99); 26 Dec 2005 19:59:45 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Dec 2005 11:59:45 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 26 Dec 2005 11:59:45 -0800 Received: (qmail 17236 invoked by uid 65534); 26 Dec 2005 19:59:24 -0000 Message-ID: <20051226195924.17233.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r359090 - /jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java Date: Mon, 26 Dec 2005 19:59:24 -0000 To: commons-cvs@jakarta.apache.org From: psteitz@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: psteitz Date: Mon Dec 26 11:59:22 2005 New Revision: 359090 URL: http://svn.apache.org/viewcvs?rev=359090&view=rev Log: Added assertContains methods. Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java?rev=359090&r1=359089&r2=359090&view=diff ============================================================================== --- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java (original) +++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/TestUtils.java Mon Dec 26 11:59:22 2005 @@ -24,8 +24,10 @@ import java.io.ObjectOutputStream; import junit.framework.Assert; +import junit.framework.AssertionFailedError; import org.apache.commons.math.complex.Complex; +import org.apache.commons.math.complex.ComplexFormat; /** * @version $Revision$ $Date$ @@ -95,7 +97,6 @@ public static Object serializeAndRecover(Object o){ Object result = null; - File tmp = null; FileOutputStream fo = null; FileInputStream fi = null; @@ -109,7 +110,7 @@ so.flush(); fo.close(); - // deserialize the Book + // deserialize the Object fi = new FileInputStream(tmp); ObjectInputStream si = new ObjectInputStream(fi); result = si.readObject(); @@ -130,8 +131,7 @@ } } } - - + if (tmp != null) { tmp.delete(); } @@ -168,4 +168,82 @@ Assert.assertEquals(msg, 0.0, x, relativeError); } } + + /** + * Fails iff values does not contain a number within epsilon of z. + * + * @param msg message to return with failure + * @param values complex array to search + * @param z value sought + * @param epsilon tolerance + */ + public static void assertContains(String msg, Complex[] values, + Complex z, double epsilon) { + int i = 0; + boolean found = false; + while (!found && i < values.length) { + try { + assertEquals(values[i], z, epsilon); + found = true; + } catch (AssertionFailedError er) { + // no match + } + i++; + } + if (!found) { + Assert.fail(msg + + " Unable to find " + ComplexFormat.formatComplex(z)); + } + } + + /** + * Fails iff values does not contain a number within epsilon of z. + * + * @param values complex array to search + * @param z value sought + * @param epsilon tolerance + */ + public static void assertContains(Complex[] values, + Complex z, double epsilon) { + assertContains(null, values, z, epsilon); + } + + /** + * Fails iff values does not contain a number within epsilon of x. + * + * @param msg message to return with failure + * @param values double array to search + * @param x value sought + * @param epsilon tolerance + */ + public static void assertContains(String msg, double[] values, + double x, double epsilon) { + int i = 0; + boolean found = false; + while (!found && i < values.length) { + try { + assertEquals(values[i], x, epsilon); + found = true; + } catch (AssertionFailedError er) { + // no match + } + i++; + } + if (!found) { + Assert.fail(msg + " Unable to find" + x); + } + } + + /** + * Fails iff values does not contain a number within epsilon of x. + * + * @param values double array to search + * @param x value sought + * @param epsilon tolerance + */ + public static void assertContains(double[] values, double x, + double epsilon) { + assertContains(null, values, x, epsilon); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org