fixed an index error triggering ArrayIndexOutOfBoundException for an add after a clear

if size has grown

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@796021 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-07-20 21:27:12 +00:00
parent 36e2a9ee50
commit b6d4e8649a
2 changed files with 12 additions and 0 deletions

View File

@ -375,6 +375,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
*/ */
public synchronized void clear() { public synchronized void clear() {
numElements = 0; numElements = 0;
startIndex = 0;
internalArray = new double[initialCapacity]; internalArray = new double[initialCapacity];
} }

View File

@ -75,6 +75,17 @@ public class DescriptiveStatisticsTest extends TestCase {
// expected // expected
} }
} }
public void test20090720() {
DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(100);
for (int i = 0; i < 161; i++) {
descriptiveStatistics.addValue(1.2);
}
descriptiveStatistics.clear();
descriptiveStatistics.addValue(1.2);
assertEquals(1, descriptiveStatistics.getN());
}
public void testRemoval() { public void testRemoval() {
final DescriptiveStatistics dstat = createDescriptiveStatistics(); final DescriptiveStatistics dstat = createDescriptiveStatistics();