@Test
 public void countWith() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(
       integers.size(), integers.countWith(Predicates2.instanceOf(), Integer.class));
   Assert.assertEquals(0, integers.countWith(Predicates2.instanceOf(), String.class));
 }
  @Test
  public void rejectWith_value() {
    ImmutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);

    switch (map.size()) {
      case 1:
        Verify.assertEmpty(
            map.rejectWith(Predicates2.<Integer>lessThan(), 2, UnifiedSet.<Integer>newSet()));
        break;
      case 2:
        Verify.assertContainsAll(
            map.rejectWith(Predicates2.<Integer>lessThan(), 2, UnifiedSet.<Integer>newSet()), 2);
        break;
      case 3:
        Verify.assertContainsAll(
            map.rejectWith(Predicates2.<Integer>lessThan(), 2, UnifiedSet.<Integer>newSet()), 2, 3);
        break;
      case 4:
        Verify.assertContainsAll(
            map.rejectWith(Predicates2.<Integer>lessThan(), 2, UnifiedSet.<Integer>newSet()),
            2,
            3,
            4);
        break;
      default:
        Verify.assertEmpty(map);
        break;
    }
  }
 @Test
 public void detectIndexWithSmallList() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.toReverseList(1, 5));
   Assert.assertEquals(4, Iterate.detectIndexWith(list, Predicates2.equal(), 1));
   Assert.assertEquals(0, Iterate.detectIndexWith(list, Predicates2.equal(), 5));
   Assert.assertEquals(-1, Iterate.detectIndexWith(list, Predicates2.equal(), 10));
 }
 @Test
 public void countWith() {
   ArrayList<Integer> list = this.getIntegerList();
   Assert.assertEquals(
       5, ArrayListIterate.countWith(list, Predicates2.instanceOf(), Integer.class));
   Assert.assertEquals(
       0, ArrayListIterate.countWith(list, Predicates2.instanceOf(), Double.class));
 }
 @Test
 public void noneSatisfyWithOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   Assert.assertFalse(
       ArrayListIterate.noneSatisfyWith(list, Predicates2.instanceOf(), Integer.class));
   Predicate2<Integer, Integer> greaterThanPredicate = Predicates2.greaterThan();
   Assert.assertTrue(ArrayListIterate.noneSatisfyWith(list, greaterThanPredicate, 150));
 }
 @Test
 public void allSatisfyWith() {
   ArrayList<Integer> list = this.getIntegerList();
   Assert.assertTrue(
       ArrayListIterate.allSatisfyWith(list, Predicates2.instanceOf(), Integer.class));
   Predicate2<Integer, Integer> greaterThanPredicate = Predicates2.greaterThan();
   Assert.assertFalse(ArrayListIterate.allSatisfyWith(list, greaterThanPredicate, 2));
 }
 @Test
 public void anySatisfyWithOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   Assert.assertTrue(
       ArrayListIterate.anySatisfyWith(list, Predicates2.instanceOf(), Integer.class));
   Assert.assertFalse(
       ArrayListIterate.anySatisfyWith(list, Predicates2.instanceOf(), Double.class));
 }
 @Test
 public void anySatisfyWith() {
   ArrayList<Integer> list = this.getIntegerList();
   Assert.assertTrue(
       ArrayListIterate.anySatisfyWith(list, Predicates2.instanceOf(), Integer.class));
   Assert.assertFalse(
       ArrayListIterate.anySatisfyWith(list, Predicates2.instanceOf(), Double.class));
 }
 @Test
 public void detectWith() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(
       Integer.valueOf(1), integers.detectWith(Predicates2.equal(), Integer.valueOf(1)));
   Assert.assertNull(
       integers.detectWith(Predicates2.equal(), Integer.valueOf(integers.size() + 1)));
 }
 @Test
 public void detectWithIfNone() {
   ArrayList<Integer> list = this.getIntegerList();
   Assert.assertEquals(
       Integer.valueOf(7), ArrayListIterate.detectWithIfNone(list, Predicates2.equal(), 6, 7));
   Assert.assertEquals(
       Integer.valueOf(2), ArrayListIterate.detectWithIfNone(list, Predicates2.equal(), 2, 7));
 }
 @Test
 public void countWithOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   Assert.assertEquals(
       101, ArrayListIterate.countWith(list, Predicates2.instanceOf(), Integer.class));
   Assert.assertEquals(
       0, ArrayListIterate.countWith(list, Predicates2.instanceOf(), Double.class));
 }
 @Test
 public void detectWithIfNone() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Integer sum = Integer.valueOf(integers.size() + 1);
   Function0<Integer> function = new PassThruFunction0<Integer>(sum);
   Assert.assertEquals(
       Integer.valueOf(1),
       integers.detectWithIfNone(Predicates2.equal(), Integer.valueOf(1), function));
   Assert.assertEquals(sum, integers.detectWithIfNone(Predicates2.equal(), sum, function));
 }
 @Test
 public void detectWith() {
   ArrayList<Integer> list = this.getIntegerList();
   Assert.assertEquals(
       Integer.valueOf(1), ArrayListIterate.detectWith(list, Predicates2.equal(), 1));
   //noinspection CachedNumberConstructorCall,UnnecessaryBoxing
   ArrayList<Integer> list2 =
       this.newArrayList(1, new Integer(2), 2); // test relies on having a unique instance of "2"
   Assert.assertSame(list2.get(1), ArrayListIterate.detectWith(list2, Predicates2.equal(), 2));
 }
Ejemplo n.º 14
0
  @Test
  public void partitionWith() {
    ImmutableBag<String> strings = this.newBag();
    PartitionImmutableBag<String> partition =
        strings.partitionWith(Predicates2.<String>greaterThan(), "0");
    Assert.assertEquals(strings, partition.getSelected());
    Verify.assertIterableEmpty(partition.getRejected());

    Verify.assertIterableSize(
        strings.size() - 1,
        strings.partitionWith(Predicates2.<String>greaterThan(), "1").getSelected());
  }
  @Override
  @Test
  public void rejectMap() {
    ImmutableSortedMap<Integer, String> map = this.classUnderTest();
    ImmutableSortedMap<Integer, String> actual = map.reject(Predicates2.alwaysFalse());
    Verify.assertInstanceOf(ImmutableEmptySortedMap.class, actual);
    Assert.assertSame(ImmutableEmptySortedMap.INSTANCE, actual);

    ImmutableSortedMap<Integer, String> revMap =
        this.classUnderTest(Comparators.<Integer>reverseNaturalOrder());
    ImmutableSortedMap<Integer, String> revActual = revMap.reject(Predicates2.alwaysTrue());
    Verify.assertInstanceOf(ImmutableEmptySortedMap.class, revActual);
    Assert.assertSame(revMap.comparator(), revActual.comparator());
  }
 @Test
 public void rejectWith() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(
       this.<Integer>newMutable().withAll(integers).reject(IntegerPredicates.isOdd()),
       integers.rejectWith(Predicates2.in(), iList(1, 3, 5, 7, 9)));
 }
 @Test
 public void selectAndRejectWith() {
   Twin<MutableList<String>> twin =
       this.unmodifiableCollection.selectAndRejectWith(Predicates2.equal(), METALLICA);
   Verify.assertSize(1, twin.getOne());
   Verify.assertSize(3, twin.getTwo());
 }
 @Override
 public void partitionWith() {
   PartitionImmutableBag<String> partition =
       this.newBag().partitionWith(Predicates2.<String>lessThan(), "0");
   Verify.assertIterableEmpty(partition.getSelected());
   Verify.assertIterableEmpty(partition.getRejected());
 }
 @Test
 public void rejectWith() {
   ArrayList<Integer> list = this.getIntegerList();
   ArrayList<Integer> results =
       ArrayListIterate.rejectWith(list, Predicates2.instanceOf(), Integer.class);
   Verify.assertEmpty(results);
 }
 @Test
 public void rejectWith() {
   Assert.assertEquals(
       FastList.newListWith(3, 4, 5, 6, 7),
       this.lazyIterable.rejectWith(
           Predicates2.<Integer>lessThan(), 3, FastList.<Integer>newList()));
 }
 @Test
 public void testSelectWith() {
   Verify.assertSize(
       1,
       this.unmodifiableStackString.selectWith(
           Predicates2.equal(), "2", FastList.<String>newList()));
 }
 @Test
 public void rejectWithOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   ArrayList<Integer> results =
       ArrayListIterate.rejectWith(list, Predicates2.instanceOf(), Integer.class);
   Verify.assertEmpty(results);
 }
 @Test
 public void testRejectWith() {
   Verify.assertSize(
       3,
       this.unmodifiableStackString.rejectWith(
           Predicates2.equal(), 3, FastList.<String>newList()));
 }
 @Test
 public void selectWith() {
   Assert.assertEquals(
       FastList.newListWith(1, 2),
       this.lazyIterable.selectWith(
           Predicates2.<Integer>lessThan(), 3, FastList.<Integer>newList()));
 }
 @Test
 public void partitionWith() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   PartitionImmutableCollection<Integer> partition =
       integers.partitionWith(Predicates2.in(), integers.select(IntegerPredicates.isOdd()));
   Assert.assertEquals(integers.select(IntegerPredicates.isOdd()), partition.getSelected());
   Assert.assertEquals(integers.select(IntegerPredicates.isEven()), partition.getRejected());
 }
 @Test
 public void selectAndRejectWith() {
   ArrayList<Integer> list = this.getIntegerList();
   Twin<MutableList<Integer>> result =
       ArrayListIterate.selectAndRejectWith(list, Predicates2.in(), Lists.immutable.of(1));
   Verify.assertSize(1, result.getOne());
   Verify.assertSize(4, result.getTwo());
 }
Ejemplo n.º 27
0
  @Test
  public void rejectWithToTarget() {
    ImmutableBag<String> strings = this.newBag();
    Assert.assertEquals(strings, strings.reject(Predicates.lessThan("0")));

    Verify.assertEmpty(
        strings.rejectWith(Predicates2.<String>greaterThan(), "0", FastList.<String>newList()));
  }
 @Test
 public void selectAndRejectWithOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   Twin<MutableList<Integer>> result =
       ArrayListIterate.selectAndRejectWith(list, Predicates2.in(), Lists.immutable.of(1));
   Verify.assertSize(1, result.getOne());
   Verify.assertSize(100, result.getTwo());
 }
  @Test
  public void partitionWith_value() {
    MutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3);
    PartitionMutableCollection<Integer> partition =
        map.partitionWith(Predicates2.in(), map.select(IntegerPredicates.isEven()));

    Assert.assertEquals(this.expectSelect(map.size()), partition.getSelected().toSet());
    Assert.assertEquals(this.expectReject(map.size()), partition.getRejected().toSet());
  }
Ejemplo n.º 30
0
  @Test
  public void selectWithToTarget() {
    ImmutableBag<String> strings = this.newBag();

    Assert.assertEquals(
        strings,
        strings
            .selectWith(Predicates2.<String>greaterThan(), "0", FastList.<String>newList())
            .toBag());
  }