@Test void isEmptyTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(); Assert.assertTrue(hopscotchCollection.isEmpty()); hopscotchCollection.add(1); Assert.assertFalse(hopscotchCollection.isEmpty()); }
@Test void removeAllTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(testVals); Assert.assertFalse(hopscotchCollection.removeAll(Arrays.asList(notInTestVals))); Assert.assertTrue(hopscotchCollection.removeAll(Arrays.asList(testVals.get(0)))); Assert.assertTrue(hopscotchCollection.removeAll(new HashSet<Integer>(testVals))); Assert.assertTrue(hopscotchCollection.isEmpty()); }
@Test void removeEachTest() { final HopscotchCollection<Integer> hopscotchCollection = new HopscotchCollection<>(testVals); Assert.assertFalse(hopscotchCollection.removeEach(notInTestVals)); for (final Integer value : new HashSet<Integer>(testVals)) { Assert.assertTrue(hopscotchCollection.removeEach(value)); } Assert.assertTrue(hopscotchCollection.isEmpty()); }
@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()); }