Example #1
0
  @Test
  public void shouldMergeTwoPriorityQueues() {
    final PriorityQueue<Integer> source = of(3, 1, 4, 1, 5);
    final PriorityQueue<Integer> target = of(9, 2, 6, 5, 3);
    assertThat(source.merge(target)).isEqualTo(of(3, 1, 4, 1, 5, 9, 2, 6, 5, 3));

    assertThat(PriorityQueue.of(3).merge(PriorityQueue.of(toStringComparator(), 1)))
        .isEqualTo(of(3, 1));
  }
Example #2
0
 @Test
 public void shouldComputeDistinctOfNonEmptyTraversableUsingKeyExtractor() {
   final Comparator<String> comparator = (o1, o2) -> Integer.compare(o1.charAt(1), o2.charAt(1));
   assertThat(
           PriorityQueue.of(comparator, "5c", "1a", "3a", "1a", "2a", "4b", "3b")
               .distinct()
               .map(s -> s.substring(1)))
       .isEqualTo(of("a", "b", "c"));
 }
Example #3
0
 @Test
 public void shouldKeepInstanceOfPriorityQueue() {
   final PriorityQueue<Integer> queue = PriorityQueue.of(1, 3, 2);
   assertThat(queue.toPriorityQueue()).isSameAs(queue);
 }