Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java?rev=1083514&r1=1083513&r2=1083514&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java Sun Mar 20 17:24:14 2011 @@ -18,21 +18,23 @@ package org.apache.commons.math.transfor import org.apache.commons.math.analysis.*; import org.apache.commons.math.util.FastMath; -import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; /** - * Testcase for fast sine transformer. + * Test case for fast sine transformer. * <p> * FST algorithm is exact, the small tolerance number is used only * to account for round-off errors. * * @version $Revision$ $Date$ */ -public final class FastSineTransformerTest extends TestCase { +public final class FastSineTransformerTest { /** * Test of transformer for the ad hoc data. */ + @Test public void testAdHocData() { FastSineTransformer transformer = new FastSineTransformer(); double result[], tolerance = 1E-12; @@ -44,30 +46,31 @@ public final class FastSineTransformerTe result = transformer.transform(x); for (int i = 0; i < result.length; i++) { - assertEquals(y[i], result[i], tolerance); + Assert.assertEquals(y[i], result[i], tolerance); } result = transformer.inversetransform(y); for (int i = 0; i < result.length; i++) { - assertEquals(x[i], result[i], tolerance); + Assert.assertEquals(x[i], result[i], tolerance); } FastFourierTransformer.scaleArray(x, FastMath.sqrt(x.length / 2.0)); result = transformer.transform2(y); for (int i = 0; i < result.length; i++) { - assertEquals(x[i], result[i], tolerance); + Assert.assertEquals(x[i], result[i], tolerance); } result = transformer.inversetransform2(x); for (int i = 0; i < result.length; i++) { - assertEquals(y[i], result[i], tolerance); + Assert.assertEquals(y[i], result[i], tolerance); } } /** * Test of transformer for the sine function. */ + @Test public void testSinFunction() { UnivariateRealFunction f = new SinFunction(); FastSineTransformer transformer = new FastSineTransformer(); @@ -75,22 +78,23 @@ public final class FastSineTransformerTe min = 0.0; max = 2.0 * FastMath.PI; result = transformer.transform(f, min, max, N); - assertEquals(N >> 1, result[2], tolerance); + Assert.assertEquals(N >> 1, result[2], tolerance); for (int i = 0; i < N; i += (i == 1 ? 2 : 1)) { - assertEquals(0.0, result[i], tolerance); + Assert.assertEquals(0.0, result[i], tolerance); } min = -FastMath.PI; max = FastMath.PI; result = transformer.transform(f, min, max, N); - assertEquals(-(N >> 1), result[2], tolerance); + Assert.assertEquals(-(N >> 1), result[2], tolerance); for (int i = 0; i < N; i += (i == 1 ? 2 : 1)) { - assertEquals(0.0, result[i], tolerance); + Assert.assertEquals(0.0, result[i], tolerance); } } /** * Test of parameters for the transformer. */ + @Test public void testParameters() throws Exception { UnivariateRealFunction f = new SinFunction(); FastSineTransformer transformer = new FastSineTransformer(); @@ -98,21 +102,21 @@ public final class FastSineTransformerTe try { // bad interval transformer.transform(f, 1, -1, 64); - fail("Expecting IllegalArgumentException - bad interval"); + Assert.fail("Expecting IllegalArgumentException - bad interval"); } catch (IllegalArgumentException ex) { // expected } try { // bad samples number transformer.transform(f, -1, 1, 0); - fail("Expecting IllegalArgumentException - bad samples number"); + Assert.fail("Expecting IllegalArgumentException - bad samples number"); } catch (IllegalArgumentException ex) { // expected } try { // bad samples number transformer.transform(f, -1, 1, 100); - fail("Expecting IllegalArgumentException - bad samples number"); + Assert.fail("Expecting IllegalArgumentException - bad samples number"); } catch (IllegalArgumentException ex) { // expected }
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealFieldTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealFieldTest.java?rev=1083514&r1=1083513&r2=1083514&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealFieldTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealFieldTest.java Sun Mar 20 17:24:14 2011 @@ -16,29 +16,28 @@ */ package org.apache.commons.math.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import org.apache.commons.math.TestUtils; +import org.junit.Assert; import org.junit.Test; public class BigRealFieldTest { @Test public void testZero() { - assertEquals(BigReal.ZERO, BigRealField.getInstance().getZero()); + Assert.assertEquals(BigReal.ZERO, BigRealField.getInstance().getZero()); } @Test public void testOne() { - assertEquals(BigReal.ONE, BigRealField.getInstance().getOne()); + Assert.assertEquals(BigReal.ONE, BigRealField.getInstance().getOne()); } @Test public void testSerial() { // deserializing the singleton should give the singleton itself back BigRealField field = BigRealField.getInstance(); - assertTrue(field == TestUtils.serializeAndRecover(field)); + Assert.assertTrue(field == TestUtils.serializeAndRecover(field)); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealTest.java?rev=1083514&r1=1083513&r2=1083514&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealTest.java Sun Mar 20 17:24:14 2011 @@ -16,38 +16,36 @@ */ package org.apache.commons.math.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; import org.apache.commons.math.TestUtils; +import org.junit.Assert; import org.junit.Test; public class BigRealTest { @Test public void testConstructor() { - assertEquals(1.625, new BigReal(new BigDecimal("1.625")).doubleValue(), 1.0e-15); - assertEquals(-5.0, new BigReal(new BigInteger("-5")).doubleValue(), 1.0e-15); - assertEquals(-5.0, new BigReal(new BigInteger("-5"), MathContext.DECIMAL64).doubleValue(), 1.0e-15); - assertEquals(0.125, new BigReal(new BigInteger("125"), 3).doubleValue(), 1.0e-15); - assertEquals(0.125, new BigReal(new BigInteger("125"), 3, MathContext.DECIMAL64).doubleValue(), 1.0e-15); - assertEquals(1.625, new BigReal(new char[] { '1', '.', '6', '2', '5' }).doubleValue(), 1.0e-15); - assertEquals(1.625, new BigReal(new char[] { 'A', 'A', '1', '.', '6', '2', '5', '9' }, 2, 5).doubleValue(), 1.0e-15); - assertEquals(1.625, new BigReal(new char[] { 'A', 'A', '1', '.', '6', '2', '5', '9' }, 2, 5, MathContext.DECIMAL64).doubleValue(), 1.0e-15); - assertEquals(1.625, new BigReal(new char[] { '1', '.', '6', '2', '5' }, MathContext.DECIMAL64).doubleValue(), 1.0e-15); - assertEquals(1.625, new BigReal(1.625).doubleValue(), 1.0e-15); - assertEquals(1.625, new BigReal(1.625, MathContext.DECIMAL64).doubleValue(), 1.0e-15); - assertEquals(-5.0, new BigReal(-5).doubleValue(), 1.0e-15); - assertEquals(-5.0, new BigReal(-5, MathContext.DECIMAL64).doubleValue(), 1.0e-15); - assertEquals(-5.0, new BigReal(-5l).doubleValue(), 1.0e-15); - assertEquals(-5.0, new BigReal(-5l, MathContext.DECIMAL64).doubleValue(), 1.0e-15); - assertEquals(1.625, new BigReal("1.625").doubleValue(), 1.0e-15); - assertEquals(1.625, new BigReal("1.625", MathContext.DECIMAL64).doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal(new BigDecimal("1.625")).doubleValue(), 1.0e-15); + Assert.assertEquals(-5.0, new BigReal(new BigInteger("-5")).doubleValue(), 1.0e-15); + Assert.assertEquals(-5.0, new BigReal(new BigInteger("-5"), MathContext.DECIMAL64).doubleValue(), 1.0e-15); + Assert.assertEquals(0.125, new BigReal(new BigInteger("125"), 3).doubleValue(), 1.0e-15); + Assert.assertEquals(0.125, new BigReal(new BigInteger("125"), 3, MathContext.DECIMAL64).doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal(new char[] { '1', '.', '6', '2', '5' }).doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal(new char[] { 'A', 'A', '1', '.', '6', '2', '5', '9' }, 2, 5).doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal(new char[] { 'A', 'A', '1', '.', '6', '2', '5', '9' }, 2, 5, MathContext.DECIMAL64).doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal(new char[] { '1', '.', '6', '2', '5' }, MathContext.DECIMAL64).doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal(1.625).doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal(1.625, MathContext.DECIMAL64).doubleValue(), 1.0e-15); + Assert.assertEquals(-5.0, new BigReal(-5).doubleValue(), 1.0e-15); + Assert.assertEquals(-5.0, new BigReal(-5, MathContext.DECIMAL64).doubleValue(), 1.0e-15); + Assert.assertEquals(-5.0, new BigReal(-5l).doubleValue(), 1.0e-15); + Assert.assertEquals(-5.0, new BigReal(-5l, MathContext.DECIMAL64).doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal("1.625").doubleValue(), 1.0e-15); + Assert.assertEquals(1.625, new BigReal("1.625", MathContext.DECIMAL64).doubleValue(), 1.0e-15); } @Test @@ -56,64 +54,69 @@ public class BigRealTest { BigReal second = new BigReal(1.0 / 3.0); BigReal third = new BigReal(1.0 / 2.0); - assertEquals(0, first.compareTo(first)); - assertEquals(0, first.compareTo(third)); - assertEquals(1, first.compareTo(second)); - assertEquals(-1, second.compareTo(first)); + Assert.assertEquals(0, first.compareTo(first)); + Assert.assertEquals(0, first.compareTo(third)); + Assert.assertEquals(1, first.compareTo(second)); + Assert.assertEquals(-1, second.compareTo(first)); } + @Test public void testAdd() { BigReal a = new BigReal("1.2345678"); BigReal b = new BigReal("8.7654321"); - assertEquals(9.9999999, a.add(b).doubleValue(), 1.0e-15); + Assert.assertEquals(9.9999999, a.add(b).doubleValue(), 1.0e-15); } + @Test public void testSubtract() { BigReal a = new BigReal("1.2345678"); BigReal b = new BigReal("8.7654321"); - assertEquals( -7.5308643, a.subtract(b).doubleValue(), 1.0e-15); + Assert.assertEquals( -7.5308643, a.subtract(b).doubleValue(), 1.0e-15); } + @Test public void testDivide() { BigReal a = new BigReal("1.0000000000"); BigReal b = new BigReal("0.0009765625"); - assertEquals(1024.0, a.divide(b).doubleValue(), 1.0e-15); + Assert.assertEquals(1024.0, a.divide(b).doubleValue(), 1.0e-15); } + @Test public void testMultiply() { BigReal a = new BigReal("1024.0"); BigReal b = new BigReal("0.0009765625"); - assertEquals(1.0, a.multiply(b).doubleValue(), 1.0e-15); + Assert.assertEquals(1.0, a.multiply(b).doubleValue(), 1.0e-15); } @Test public void testDoubleValue() { - assertEquals(0.5, new BigReal(0.5).doubleValue(), 1.0e-15); + Assert.assertEquals(0.5, new BigReal(0.5).doubleValue(), 1.0e-15); } @Test public void testBigDecimalValue() { BigDecimal pi = new BigDecimal("3.1415926535897932384626433832795028841971693993751"); - assertEquals(pi, new BigReal(pi).bigDecimalValue()); - assertEquals(new BigDecimal(0.5), new BigReal(1.0 / 2.0).bigDecimalValue()); + Assert.assertEquals(pi, new BigReal(pi).bigDecimalValue()); + Assert.assertEquals(new BigDecimal(0.5), new BigReal(1.0 / 2.0).bigDecimalValue()); } @Test public void testEqualsAndHashCode() { BigReal zero = new BigReal(0.0); BigReal nullReal = null; - assertTrue(zero.equals(zero)); - assertFalse(zero.equals(nullReal)); - assertFalse(zero.equals(Double.valueOf(0))); + Assert.assertTrue(zero.equals(zero)); + Assert.assertFalse(zero.equals(nullReal)); + Assert.assertFalse(zero.equals(Double.valueOf(0))); BigReal zero2 = new BigReal(0.0); - assertTrue(zero.equals(zero2)); - assertEquals(zero.hashCode(), zero2.hashCode()); + Assert.assertTrue(zero.equals(zero2)); + Assert.assertEquals(zero.hashCode(), zero2.hashCode()); BigReal one = new BigReal(1.0); - assertFalse((one.equals(zero) || zero.equals(one))); - assertTrue(one.equals(BigReal.ONE)); + Assert.assertFalse((one.equals(zero) || zero.equals(one))); + Assert.assertTrue(one.equals(BigReal.ONE)); } + @Test public void testSerial() { BigReal[] Reals = { new BigReal(3.0), BigReal.ONE, BigReal.ZERO, @@ -121,7 +124,7 @@ public class BigRealTest { new BigReal(-2.5) }; for (BigReal Real : Reals) { - assertEquals(Real, TestUtils.serializeAndRecover(Real)); + Assert.assertEquals(Real, TestUtils.serializeAndRecover(Real)); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java?rev=1083514&r1=1083513&r2=1083514&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/ContinuedFractionTest.java Sun Mar 20 17:24:14 2011 @@ -16,20 +16,16 @@ */ package org.apache.commons.math.util; -import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + /** * @version $Revision$ $Date$ */ -public class ContinuedFractionTest extends TestCase { - /** - * Constructor for ContinuedFractionTest. - * @param name - */ - public ContinuedFractionTest(String name) { - super(name); - } +public class ContinuedFractionTest { + @Test public void testGoldenRatio() throws Exception { ContinuedFraction cf = new ContinuedFraction() { @@ -45,6 +41,6 @@ public class ContinuedFractionTest exten }; double gr = cf.evaluate(0.0, 10e-9); - assertEquals(1.61803399, gr, 10e-9); + Assert.assertEquals(1.61803399, gr, 10e-9); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java?rev=1083514&r1=1083513&r2=1083514&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java Sun Mar 20 17:24:14 2011 @@ -19,34 +19,37 @@ package org.apache.commons.math.util; import java.math.BigDecimal; -import junit.framework.TestCase; import org.apache.commons.math.MathException; import org.apache.commons.math.TestUtils; import org.apache.commons.math.exception.NullArgumentException; +import org.junit.Assert; +import org.junit.Test; /** * @version $Revision$ $Date$ */ -public class DefaultTransformerTest extends TestCase { +public class DefaultTransformerTest { /** * */ + @Test public void testTransformDouble() throws Exception { double expected = 1.0; Double input = Double.valueOf(expected); DefaultTransformer t = new DefaultTransformer(); - assertEquals(expected, t.transform(input), 1.0e-4); + Assert.assertEquals(expected, t.transform(input), 1.0e-4); } /** * */ + @Test public void testTransformNull() throws Exception { DefaultTransformer t = new DefaultTransformer(); try { t.transform(null); - fail("Expecting NullArgumentException"); + Assert.fail("Expecting NullArgumentException"); } catch (NullArgumentException e) { // expected } @@ -55,49 +58,54 @@ public class DefaultTransformerTest exte /** * */ + @Test public void testTransformInteger() throws Exception { double expected = 1.0; Integer input = Integer.valueOf(1); DefaultTransformer t = new DefaultTransformer(); - assertEquals(expected, t.transform(input), 1.0e-4); + Assert.assertEquals(expected, t.transform(input), 1.0e-4); } /** * */ + @Test public void testTransformBigDecimal() throws Exception { double expected = 1.0; BigDecimal input = new BigDecimal("1.0"); DefaultTransformer t = new DefaultTransformer(); - assertEquals(expected, t.transform(input), 1.0e-4); + Assert.assertEquals(expected, t.transform(input), 1.0e-4); } /** * */ + @Test public void testTransformString() throws Exception { double expected = 1.0; String input = "1.0"; DefaultTransformer t = new DefaultTransformer(); - assertEquals(expected, t.transform(input), 1.0e-4); + Assert.assertEquals(expected, t.transform(input), 1.0e-4); } /** * */ + @Test public void testTransformObject(){ Boolean input = Boolean.TRUE; DefaultTransformer t = new DefaultTransformer(); try { t.transform(input); - fail("Expecting MathException"); + Assert.fail("Expecting MathException"); } catch (MathException e) { // expected } } + @Test public void testSerial() { - assertEquals(new DefaultTransformer(), TestUtils.serializeAndRecover(new DefaultTransformer())); + Assert.assertEquals(new DefaultTransformer(), TestUtils.serializeAndRecover(new DefaultTransformer())); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DoubleArrayAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DoubleArrayAbstractTest.java?rev=1083514&r1=1083513&r2=1083514&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DoubleArrayAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/DoubleArrayAbstractTest.java Sun Mar 20 17:24:14 2011 @@ -17,37 +17,35 @@ package org.apache.commons.math.util; import org.apache.commons.math.stat.StatUtils; +import org.junit.Assert; +import org.junit.Test; -import junit.framework.TestCase; /** * This class contains test cases for the ExpandableDoubleArray. * * @version $Revision$ $Date$ */ -public abstract class DoubleArrayAbstractTest extends TestCase { +public abstract class DoubleArrayAbstractTest { protected DoubleArray da = null; // Array used to test rolling protected DoubleArray ra = null; - public DoubleArrayAbstractTest(String name) { - super(name); - } - + @Test public void testAdd1000() { for (int i = 0; i < 1000; i++) { da.addElement(i); } - assertEquals( + Assert.assertEquals( "Number of elements should be equal to 1000 after adding 1000 values", 1000, da.getNumElements()); - assertEquals( + Assert.assertEquals( "The element at the 56th index should be 56", 56.0, da.getElement(56), @@ -55,6 +53,7 @@ public abstract class DoubleArrayAbstrac } + @Test public void testGetValues() { double[] controlArray = { 2.0, 4.0, 6.0 }; @@ -64,7 +63,7 @@ public abstract class DoubleArrayAbstrac double[] testArray = da.getElements(); for (int i = 0; i < da.getNumElements(); i++) { - assertEquals( + Assert.assertEquals( "The testArray values should equal the controlArray values, index i: " + i + " does not match", @@ -75,6 +74,7 @@ public abstract class DoubleArrayAbstrac } + @Test public void testAddElementRolling() { ra.addElement(0.5); ra.addElement(1.0); @@ -84,16 +84,16 @@ public abstract class DoubleArrayAbstrac ra.addElement(1.0); ra.addElementRolling(2.0); - assertEquals( + Assert.assertEquals( "There should be 6 elements in the eda", 6, ra.getNumElements()); - assertEquals( + Assert.assertEquals( "The max element should be 2.0", 2.0, StatUtils.max(ra.getElements()), Double.MIN_VALUE); - assertEquals( + Assert.assertEquals( "The min element should be 1.0", 1.0, StatUtils.min(ra.getElements()), @@ -103,12 +103,13 @@ public abstract class DoubleArrayAbstrac ra.addElementRolling(i); } - assertEquals( + Assert.assertEquals( "We just inserted 1024 rolling elements, num elements should still be 6", 6, ra.getNumElements()); } + @Test public void testMinMax() { da.addElement(2.0); da.addElement(22.0); @@ -121,8 +122,8 @@ public abstract class DoubleArrayAbstrac da.addElement(122.0); da.addElement(1212.0); - assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE); - assertEquals( + Assert.assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE); + Assert.assertEquals( "Max should be 1212.0", 1212.0, StatUtils.max(da.getElements()),
