use of jcog.bag.impl.HijackBag in project narchy by automenta.
the class BagTest method testPutMinMaxAndUniqueness.
public static void testPutMinMaxAndUniqueness(Bag<Integer, PriReference<Integer>> a) {
float pri = 0.5f;
// insert enough to fully cover all slots. strings have bad hashcode when input iteratively so this may need to be a high multiple
int n = a.capacity() * 16;
for (int i = 0; i < n; i++) {
a.put(new PLink((i), pri));
}
// commit but dont forget
a.commit(null);
assertEquals(a.capacity(), a.size());
if (a instanceof ArrayBag)
assertSorted((ArrayBag) a);
// a.print();
// System.out.println(n + " " + a.size());
List<Integer> keys = new FasterList(a.capacity());
a.forEachKey(keys::add);
assertEquals(a.size(), keys.size());
assertEquals(new HashSet(keys).size(), keys.size());
assertEquals(pri, a.priMin(), 0.01f);
assertEquals(a.priMin(), a.priMax(), 0.08f);
if (a instanceof HijackBag)
assertTrue(((HijackBag) a).density() > 0.75f);
}
Aggregations