@Test void sizeTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(); Assert.assertEquals(hopscotchCollection.size(), 0); hopscotchCollection.addAll(testVals); Assert.assertEquals(hopscotchCollection.size(), testVals.size()); hopscotchCollection.add(notInTestVals); Assert.assertEquals(hopscotchCollection.size(), testVals.size() + 1); hopscotchCollection.removeEach(notInTestVals); Assert.assertEquals(hopscotchCollection.size(), testVals.size()); hopscotchCollection.clear(); Assert.assertEquals(hopscotchCollection.size(), 0); }
@Test void clearTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(testVals); hopscotchCollection.clear(); Assert.assertEquals(hopscotchCollection.size(), 0); Assert.assertEquals(SVUtils.iteratorSize(hopscotchCollection.iterator()), 0); }
@Test void addTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(testVals.size()); testVals.stream().forEach(hopscotchCollection::add); Assert.assertEquals(hopscotchCollection.size(), testVals.size()); Assert.assertTrue(hopscotchCollection.containsAll(testVals)); }
@Test void resizeTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(1); final int N_ENTRIES = 1000000; for (int idx = 0; idx != N_ENTRIES; ++idx) { hopscotchCollection.add(idx); } Assert.assertEquals(hopscotchCollection.size(), N_ENTRIES); Assert.assertEquals(hopscotchCollection.stream().mapToInt(i -> i).min().orElse(-1), 0); Assert.assertEquals( hopscotchCollection.stream().mapToInt(i -> i).max().orElse(-1), N_ENTRIES - 1); }
@Test void iteratorTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(testVals); Assert.assertEquals(SVUtils.iteratorSize(hopscotchCollection.iterator()), testVals.size()); final Integer KEY_TO_REMOVE = 1; final Iterator<Integer> itr1 = hopscotchCollection.iterator(); while (itr1.hasNext()) { if (itr1.next().equals(KEY_TO_REMOVE)) itr1.remove(); } final int onesCount = (int) testVals.stream().filter(i -> i.equals(KEY_TO_REMOVE)).count(); Assert.assertEquals(hopscotchCollection.size(), testVals.size() - onesCount); Assert.assertEquals( SVUtils.iteratorSize(hopscotchCollection.iterator()), hopscotchCollection.size()); final Iterator<Integer> itr2 = hopscotchCollection.iterator(); while (itr2.hasNext()) { itr2.next(); itr2.remove(); } Assert.assertTrue(hopscotchCollection.isEmpty()); Assert.assertEquals( SVUtils.iteratorSize(hopscotchCollection.iterator()), hopscotchCollection.size()); }
@Test void createFromCollectionTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(testVals); Assert.assertEquals(hopscotchCollection.size(), testVals.size()); Assert.assertTrue(hopscotchCollection.containsAll(testVals)); }