@Test void findEachTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(testVals); for (final Integer value : testVals) { Assert.assertEquals( SVUtils.iteratorSize(hopscotchCollection.findEach(value)), testVals.stream().filter(i -> i.equals(value)).count()); } Assert.assertEquals(SVUtils.iteratorSize(hopscotchCollection.findEach(notInTestVals)), 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 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()); }