brentworden 2004/05/04 06:15:47 Modified: math/src/test/org/apache/commons/math/util ContractableDoubleArrayTest.java ExpandableDoubleArrayTest.java Log: Added unit tests.
Revision Changes Path 1.9 +20 -1 jakarta-commons/math/src/test/org/apache/commons/math/util/ContractableDoubleArrayTest.java Index: ContractableDoubleArrayTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/util/ContractableDoubleArrayTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ContractableDoubleArrayTest.java 21 Feb 2004 21:35:18 -0000 1.8 +++ ContractableDoubleArrayTest.java 4 May 2004 13:15:47 -0000 1.9 @@ -35,4 +35,23 @@ ra = new ContractableDoubleArray(); } + protected ExpandableDoubleArray newInstance(int initialCapacity) { + return new ContractableDoubleArray(initialCapacity); + } + + protected ExpandableDoubleArray newInstance() { + return new ContractableDoubleArray(); + } + + protected ExpandableDoubleArray newInstance(int initialCapacity, float expansionFactor) { + if (expansionFactor < 2.5f) { + return new ContractableDoubleArray(initialCapacity, expansionFactor); + } else { + return newInstance(initialCapacity, expansionFactor, expansionFactor + 1.0f); + } + } + + protected ExpandableDoubleArray newInstance(int initialCapacity, float expansionFactor, float contractionFactor) { + return new ContractableDoubleArray(initialCapacity, expansionFactor, contractionFactor); + } } 1.10 +22 -11 jakarta-commons/math/src/test/org/apache/commons/math/util/ExpandableDoubleArrayTest.java Index: ExpandableDoubleArrayTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/util/ExpandableDoubleArrayTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ExpandableDoubleArrayTest.java 21 Feb 2004 21:35:18 -0000 1.9 +++ ExpandableDoubleArrayTest.java 4 May 2004 13:15:47 -0000 1.10 @@ -31,8 +31,8 @@ * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { - da = new ExpandableDoubleArray(); - ra = new ExpandableDoubleArray(); + da = newInstance(); + ra = newInstance(); } /* (non-Javadoc) @@ -108,7 +108,7 @@ public void testWithInitialCapacity() { - ExpandableDoubleArray eDA2 = new ExpandableDoubleArray(2); + ExpandableDoubleArray eDA2 = newInstance(2); assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); int iterations = (int) Math.pow(2.0, 15.0); @@ -127,7 +127,7 @@ public void testWithInitialCapacityAndExpansionFactor() { - ExpandableDoubleArray eDA3 = new ExpandableDoubleArray(3, 3.0f); + ExpandableDoubleArray eDA3 = newInstance(3, 3.0f); assertEquals("Initial number of elements should be 0", 0, eDA3.getNumElements() ); int iterations = (int) Math.pow(3.0, 7.0); @@ -181,12 +181,12 @@ public void testIllegalInitialCapacity() { try { - ExpandableDoubleArray eDA = new ExpandableDoubleArray(-3, 2.0f); + ExpandableDoubleArray eDA = newInstance(-3, 2.0f); fail( "That constructor should have thrown an IllegalArgumentException because " + "the initialCapacity was negative, if it didn't then" + " the range checking of initialCapacity is not working properly" ); } catch( IllegalArgumentException iae ) { } try { - ExpandableDoubleArray eDA = new ExpandableDoubleArray(0, 2.0f); + ExpandableDoubleArray eDA = newInstance(0, 2.0f); fail( "That constructor should have thrown an IllegalArgumentException because " + "the initialCapacity was ZERO if it didn't then" + " the range checking of initialCapacity is not working properly" ); @@ -196,19 +196,19 @@ public void testIllegalExpansionFactor() { try { - ExpandableDoubleArray eDA = new ExpandableDoubleArray(3, 0.66f); + ExpandableDoubleArray eDA = newInstance(3, 0.66f); fail( "That constructor should have thrown an IllegalArgumentException because " + "the expansionFactor for 0.66 which would shrink the array instead of expand the array"); } catch( IllegalArgumentException iae ) { } try { - ExpandableDoubleArray eDA = new ExpandableDoubleArray(3, 0.0f); + ExpandableDoubleArray eDA = newInstance(3, 0.0f); fail( "That constructor should have thrown an IllegalArgumentException because " + "the expansionFactor for 0.0"); } catch( IllegalArgumentException iae) { } try { - ExpandableDoubleArray eDA = new ExpandableDoubleArray(3, -4.35f); + ExpandableDoubleArray eDA = newInstance(3, -4.35f); fail( "That constructor should have thrown an IllegalArgumentException because " + "the expansionFactor for -4.35"); } catch( IllegalArgumentException iae) { @@ -236,5 +236,16 @@ } catch( Exception e ){ } } - + + protected ExpandableDoubleArray newInstance(int initialCapacity) { + return new ExpandableDoubleArray(initialCapacity); + } + + protected ExpandableDoubleArray newInstance() { + return new ExpandableDoubleArray(); + } + + protected ExpandableDoubleArray newInstance(int initialCapacity, float expansionFactor) { + return new ExpandableDoubleArray(initialCapacity, expansionFactor); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]