@Test
  public void select_value() {
    MutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3);
    ImmutableSet<Integer> expected = this.expectSelect(map.size());

    Assert.assertEquals(expected, map.select(IntegerPredicates.isEven()).toSet());
    Assert.assertEquals(
        expected, map.select(IntegerPredicates.isEven(), UnifiedSet.<Integer>newSet()));
  }
  @Test
  public void reject_value() {
    ImmutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);

    MutableSet<Integer> rejected = map.reject(IntegerPredicates.isEven()).toSet();
    UnifiedSet<Integer> rejectedIntoTarget =
        map.reject(IntegerPredicates.isEven(), UnifiedSet.<Integer>newSet());

    ImmutableSet<Integer> expected = this.expectReject(map.size());
    Assert.assertEquals(expected, rejected);
    Assert.assertEquals(expected, rejectedIntoTarget);
  }
 @Test
 public void partition() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   PartitionImmutableCollection<Integer> partition = integers.partition(IntegerPredicates.isOdd());
   Assert.assertEquals(integers.select(IntegerPredicates.isOdd()), partition.getSelected());
   Assert.assertEquals(integers.select(IntegerPredicates.isEven()), partition.getRejected());
 }
  @Test
  public void partition_value() {
    MutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3);
    PartitionMutableCollection<Integer> partition = map.partition(IntegerPredicates.isEven());

    Assert.assertEquals(this.expectSelect(map.size()), partition.getSelected().toSet());
    Assert.assertEquals(this.expectReject(map.size()), partition.getRejected().toSet());
  }
  @Test
  public void remove_with_hashingStrategy() {
    HashingStrategy<Integer> hashingStrategy =
        HashingStrategies.nullSafeHashingStrategy(
            new HashingStrategy<Integer>() {
              public int computeHashCode(Integer object) {
                return object % 1000;
              }

              public boolean equals(Integer object1, Integer object2) {
                return object1.equals(object2);
              }
            });

    UnifiedSetWithHashingStrategy<Integer> integers =
        UnifiedSetWithHashingStrategy.newSet(hashingStrategy, 2)
            .with(COLLISION_1, COLLISION_1 + 1000, COLLISION_1 + 2000, null);

    // Testing remove null from the end of the chain
    Assert.assertTrue(integers.remove(null));

    // Adding null back and creating a deep chain.
    integers.with(null, COLLISION_1 + 3000, COLLISION_1 + 4000, COLLISION_1 + 5000);

    // Removing null from the first position of a bucket in the deep chain
    Assert.assertTrue(integers.remove(null));
    Assert.assertFalse(integers.remove(null));

    // Removing from the end of the deep chain
    Assert.assertTrue(integers.remove(COLLISION_1 + 4000));

    // Removing from the first spot of the chain
    Assert.assertTrue(integers.remove(COLLISION_1));
    Verify.assertSize(4, integers);

    // Testing removing a non existent element from a non bucket slot
    integers.add(2);
    integers.add(4);
    Assert.assertFalse(integers.remove(1002));

    // Testing removeIf
    integers.removeIf(IntegerPredicates.isEven());
    Verify.assertEmpty(integers);
  }
Пример #6
0
 @Test
 public void selectByOccurrences() {
   ImmutableBag<String> strings = this.newBag().selectByOccurrences(IntPredicates.isEven());
   ImmutableBag<Integer> collect = strings.collect(Integer::valueOf);
   Verify.assertAllSatisfy(collect, IntegerPredicates.isEven());
 }
 @Test
 public void partition() {
   PartitionIterable<Integer> partition = this.lazyIterable.partition(IntegerPredicates.isEven());
   Assert.assertEquals(iList(2, 4, 6), partition.getSelected());
   Assert.assertEquals(iList(1, 3, 5, 7), partition.getRejected());
 }