### Question:
BoundedPriorityQueue { public Optional<E> poll() { return deduct( queue.poll() ); } BoundedPriorityQueue( Config config, Function<E,Long> sizeOf, java.util.Comparator<E> comparator ); int count(); long bytes(); Result offer( E element ); Optional<E> poll(); Optional<E> poll( int timeout, TimeUnit unit );  }### Answer:
@Test public void shouldRespectPriority() { int count = 100; Config config = new Config( 0, count, 0 ); BoundedPriorityQueue<Integer> queue = new BoundedPriorityQueue<>( config, i -> 0L, Integer::compare ); List<Integer> list = new ArrayList<>( count ); for ( int i = 0; i < count; i++ ) { list.add( i ); } Collections.shuffle( list, tlr ); list.forEach( queue::offer ); for ( int i = 0; i < count; i++ ) { assertEquals( Optional.of( i ), queue.poll() ); } }
@Test public void shouldHaveStablePriority() { int count = 100; int priorities = 3; Config config = new Config( 0, count, 0 ); BoundedPriorityQueue<Element> queue = new BoundedPriorityQueue<>( config, i -> 0L, comparingInt( p -> p.priority ) ); List<Element> insertionOrder = new ArrayList<>( count ); for ( int i = 0; i < count; i++ ) { insertionOrder.add( new Element( tlr.nextInt( priorities ) ) ); } Collections.shuffle( insertionOrder, tlr ); insertionOrder.forEach( queue::offer ); for ( int p = 0; p < priorities; p++ ) { ArrayList<Element> filteredInsertionOrder = new ArrayList<>(); for ( Element element : insertionOrder ) { if ( element.priority == p ) { filteredInsertionOrder.add( element ); } } for ( Element element : filteredInsertionOrder ) { assertEquals( Optional.of( element ), queue.poll() ); } } }