You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/27 19:38:07 UTC
[commons-collections] branch master updated: fix: fix
COLLECTIONS-773 by adding an assertion for specifying ensureCapacity (#198)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
The following commit(s) were added to refs/heads/master by this push:
new 36b9fa5 fix: fix COLLECTIONS-773 by adding an assertion for specifying ensureCapacity (#198)
36b9fa5 is described below
commit 36b9fa53d295b8a105c5c98f5da47ec7fe634c40
Author: Martin Monperrus <ma...@gnieh.org>
AuthorDate: Fri Nov 27 19:37:59 2020 +0000
fix: fix COLLECTIONS-773 by adding an assertion for specifying ensureCapacity (#198)
---
.../org/apache/commons/collections4/map/HashedMapTest.java | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/test/java/org/apache/commons/collections4/map/HashedMapTest.java b/src/test/java/org/apache/commons/collections4/map/HashedMapTest.java
index f26bbbc..5dae0a3 100644
--- a/src/test/java/org/apache/commons/collections4/map/HashedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/HashedMapTest.java
@@ -54,12 +54,23 @@ public class HashedMapTest<K, V> extends AbstractIterableMapTest<K, V> {
}
public void testInternalState() {
- final HashedMap<K, V> map = new HashedMap<>(42, 0.75f);
+ final HashedMap<Integer, Integer> map = new HashedMap<>(42, 0.75f);
assertEquals(0.75f, map.loadFactor, 0.1f);
assertEquals(0, map.size);
assertEquals(64, map.data.length);
assertEquals(48, map.threshold);
assertEquals(0, map.modCount);
+
+ // contract: the capacity is ensured when too many elements are added
+ final HashedMap<Integer, Integer> tmpMap = new HashedMap<>();
+ // we need to put at least the "threshold" number of elements
+ // in order to double the capacity
+ for (int i = 1; i <= map.threshold; i++) {
+ tmpMap.put(i, i);
+ }
+ map.putAll(tmpMap);
+ // the threshold has changed due to calling ensureCapacity
+ assertEquals(96, map.threshold);
}
// public void testCreate() throws Exception {