public void testIterator() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Collection<Integer> coll = getIteratorCollection(pq.iterator()); assertEquals(3, coll.size()); assertTrue(coll.contains(Integer.valueOf(5))); assertTrue(coll.contains(Integer.valueOf(3))); assertTrue(coll.contains(Integer.valueOf(6))); assertFalse(coll.contains(Integer.valueOf(4))); }
public void testIterator_RemoveUnsupported() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); try { iter.remove(); fail("missing UnsupportedOperationException"); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } }
public void testIterator_ConcurrentModification_add() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); pq.add(Integer.valueOf(4), 4.0); assertTrue(iter.hasNext()); try { iter.next(); fail("missing ConcurrentModificationException"); } catch (ConcurrentModificationException e) { log.info("catched expected exception.", e); } iter = pq.iterator(); // but a new iterator must work again assertTrue(iter.hasNext()); assertNotNull(iter.next()); }
public void testIterator_ConcurrentModification_poll() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); pq.poll(); assertTrue(iter.hasNext()); try { iter.next(); fail("missing ConcurrentModificationException"); } catch (ConcurrentModificationException e) { log.info("catched expected exception.", e); } iter = pq.iterator(); // but a new iterator must work again assertTrue(iter.hasNext()); assertNotNull(iter.next()); }
public void testIterator_ConcurrentModification_remove() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); assertTrue(pq.remove(Integer.valueOf(5))); assertTrue(iter.hasNext()); try { iter.next(); fail("missing ConcurrentModificationException"); } catch (ConcurrentModificationException e) { log.info("catched expected exception.", e); } iter = pq.iterator(); // but a new iterator must work again assertTrue(iter.hasNext()); assertNotNull(iter.next()); assertFalse(pq.remove(Integer.valueOf(5))); // cannot be removed, so it's no change assertTrue(iter.hasNext()); assertNotNull(iter.next()); }
pq.add(Integer.valueOf(6), 6.0); Collection<Integer> coll = getIteratorCollection(pq.iterator()); assertEquals(3, coll.size()); assertTrue(coll.contains(Integer.valueOf(5))); coll = getIteratorCollection(pq.iterator()); assertEquals(2, coll.size()); assertFalse(coll.contains(Integer.valueOf(5))); coll = getIteratorCollection(pq.iterator()); assertEquals(2, coll.size()); coll = getIteratorCollection(pq.iterator()); assertEquals(2, coll.size()); assertTrue(coll.contains(Integer.valueOf(3)));
public void testAdd_Null() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); try { pq.add(null, 1.0); fail("missing NullPointerException."); } catch (NullPointerException e) { log.info("catched expected exception. ", e); } assertEquals(0, pq.size()); assertEquals(0, iteratorElementCount(pq.iterator())); }
public void testAdd() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); assertEquals(0, pq.size()); pq.add(Integer.valueOf(1), 1.0); assertEquals(1, pq.size()); pq.add(Integer.valueOf(2), 2.0); assertEquals(2, pq.size()); pq.add(Integer.valueOf(3), 2.0); // different element with same priority assertEquals(3, pq.size()); pq.add(Integer.valueOf(3), 3.0); // same element with different priority assertEquals(3, pq.size()); // should not be added! assertEquals(3, iteratorElementCount(pq.iterator())); }