@Test public void detectIndexOver100() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.toReverseList(1, 101)); Assert.assertEquals(100, ArrayListIterate.detectIndex(list, Predicates.equal(1))); Assert.assertEquals(0, Iterate.detectIndex(list, Predicates.equal(101))); Assert.assertEquals(-1, Iterate.detectIndex(list, Predicates.equal(200))); }
@Test public void detectIndexSmallList() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.toReverseList(1, 5)); Assert.assertEquals(4, ArrayListIterate.detectIndex(list, Predicates.equal(1))); Assert.assertEquals(0, Iterate.detectIndex(list, Predicates.equal(5))); Assert.assertEquals(-1, Iterate.detectIndex(list, Predicates.equal(10))); }
@Test public void detectIfNoneWithBlock() { Function0<Integer> function = new PassThruFunction0<Integer>(9); Assert.assertEquals( Integer.valueOf(3), this.lazyIterable.detectIfNone(Predicates.equal(3), function)); Assert.assertEquals( Integer.valueOf(9), this.lazyIterable.detectIfNone(Predicates.equal(8), function)); }
@Test public void detectIfNone() { ArrayList<Integer> list = this.getIntegerList(); Assert.assertEquals( Integer.valueOf(7), ArrayListIterate.detectIfNone(list, Predicates.equal(6), 7)); Assert.assertEquals( Integer.valueOf(2), ArrayListIterate.detectIfNone(list, Predicates.equal(2), 7)); }
@Test public void detectIfNone() { ImmutableCollection<Integer> integers = this.classUnderTest(); Function0<Integer> function = new PassThruFunction0<Integer>(integers.size() + 1); Assert.assertEquals(Integer.valueOf(1), integers.detectIfNone(Predicates.equal(1), function)); Assert.assertEquals( Integer.valueOf(integers.size() + 1), integers.detectIfNone(Predicates.equal(integers.size() + 1), function)); }
@Test public void detect() { ArrayList<Integer> list = this.getIntegerList(); Assert.assertEquals(Integer.valueOf(1), ArrayListIterate.detect(list, Predicates.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.detect(list2, Predicates.equal(2))); }
@Test public void collectIfOver100() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101)); ArrayList<Class<?>> result = ArrayListIterate.collectIf(list, Predicates.equal(101), Functions.getToClass()); Assert.assertEquals(FastList.newListWith(Integer.class), result); }
@Test public void anySatisfy() { ImmutableSortedMap<String, String> map = new ImmutableEmptySortedMap<String, String>(); Assert.assertFalse(map.anySatisfy(Predicates.instanceOf(String.class))); Assert.assertFalse(map.anySatisfy(Predicates.equal("Monkey"))); }
@Test public void noneSatisfy() { ImmutableSortedMap<String, String> map = new ImmutableEmptySortedMap<String, String>(); Assert.assertTrue(map.noneSatisfy(Predicates.instanceOf(Integer.class))); Assert.assertTrue(map.noneSatisfy(Predicates.equal("Monkey"))); }
@Test public void allSatisfy() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertTrue(integers.allSatisfy(Predicates.instanceOf(Integer.class))); Assert.assertFalse(integers.allSatisfy(Predicates.equal(0))); }
@Test public void detect() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertEquals(Integer.valueOf(1), integers.detect(Predicates.equal(1))); Assert.assertNull(integers.detect(Predicates.equal(integers.size() + 1))); }
@Test public void detectOver100() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101)); Assert.assertEquals(Integer.valueOf(1), ArrayListIterate.detect(list, Predicates.equal(1))); }
@Override public boolean contains(Object o) { return this.anySatisfy(Predicates.equal(o)); }
@Test public void allSatisfy() { Assert.assertTrue(this.lazyIterable.allSatisfy(Predicates.instanceOf(Integer.class))); Assert.assertFalse(this.lazyIterable.allSatisfy(Predicates.equal(1))); }
@Test public void detect() { Assert.assertEquals(Integer.valueOf(3), this.lazyIterable.detect(Predicates.equal(3))); Assert.assertNull(this.lazyIterable.detect(Predicates.equal(8))); }
@Test public void noneSatisfy() { ImmutableCollection<Integer> integers = this.classUnderTest(); Assert.assertTrue(integers.noneSatisfy(Predicates.instanceOf(String.class))); Assert.assertFalse(integers.noneSatisfy(Predicates.equal(1))); }
private ImmutableCollection<Integer> classUnderTestWithNull() { return this.classUnderTest().reject(Predicates.equal(1)).newWith(null); }
@Test public void detectIfNoneOver100() { ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101)); Assert.assertNull(ArrayListIterate.detectIfNone(list, Predicates.equal(102), null)); }