Search in sources :

Example 21 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.

the class AbstractBooleanIterableTestCase method allSatisfy.

@Test
public void allSatisfy() {
    BooleanIterable booleanIterable = this.classUnderTest();
    int size = booleanIterable.size();
    Assert.assertEquals(size <= 1, booleanIterable.allSatisfy(BooleanPredicates.isTrue()));
    Assert.assertEquals(size == 0, booleanIterable.allSatisfy(BooleanPredicates.isFalse()));
    Assert.assertTrue(this.newWith().allSatisfy(BooleanPredicates.isTrue()));
    Assert.assertTrue(this.newWith().allSatisfy(BooleanPredicates.isFalse()));
    Assert.assertTrue(this.newWith(false, false).allSatisfy(BooleanPredicates.isFalse()));
    Assert.assertFalse(this.newWith(true, false).allSatisfy(BooleanPredicates.isTrue()));
    Assert.assertTrue(this.newWith(true, true, true).allSatisfy(BooleanPredicates.isTrue()));
    Assert.assertTrue(this.newWith(false, false, false).allSatisfy(BooleanPredicates.isFalse()));
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) Test(org.junit.Test)

Example 22 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.

the class AbstractBooleanIterableTestCase method iterator_throws_non_empty_collection.

@Test(expected = NoSuchElementException.class)
public void iterator_throws_non_empty_collection() {
    BooleanIterable iterable = this.newWith(true, true, true);
    BooleanIterator iterator = iterable.booleanIterator();
    while (iterator.hasNext()) {
        Assert.assertTrue(iterator.next());
    }
    iterator.next();
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 23 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.

the class AbstractBooleanIterableTestCase method anySatisfy.

@Test
public void anySatisfy() {
    BooleanIterable booleanIterable = this.classUnderTest();
    int size = booleanIterable.size();
    Assert.assertEquals(size >= 1, booleanIterable.anySatisfy(BooleanPredicates.isTrue()));
    Assert.assertEquals(size >= 2, booleanIterable.anySatisfy(BooleanPredicates.isFalse()));
    Assert.assertFalse(this.newWith(true, true).anySatisfy(BooleanPredicates.isFalse()));
    Assert.assertFalse(this.newWith().anySatisfy(BooleanPredicates.isFalse()));
    Assert.assertFalse(this.newWith().anySatisfy(BooleanPredicates.isTrue()));
    Assert.assertTrue(this.newWith(true).anySatisfy(BooleanPredicates.isTrue()));
    Assert.assertFalse(this.newWith(false).anySatisfy(BooleanPredicates.isTrue()));
    Assert.assertTrue(this.newWith(false, false, false).anySatisfy(BooleanPredicates.isFalse()));
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) Test(org.junit.Test)

Example 24 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.

the class AbstractBooleanIterableTestCase method containsAllArray.

@Test
public void containsAllArray() {
    BooleanIterable iterable = this.classUnderTest();
    int size = iterable.size();
    Assert.assertEquals(size >= 1, iterable.containsAll(true));
    Assert.assertEquals(size >= 2, iterable.containsAll(true, false, true));
    Assert.assertEquals(size >= 2, iterable.containsAll(true, false));
    Assert.assertEquals(size >= 1, iterable.containsAll(true, true));
    Assert.assertEquals(size >= 2, iterable.containsAll(false, false));
    BooleanIterable emptyCollection = this.newWith();
    Assert.assertFalse(emptyCollection.containsAll(true));
    Assert.assertFalse(emptyCollection.containsAll(false));
    Assert.assertFalse(emptyCollection.containsAll(false, true, false));
    Assert.assertFalse(this.newWith(true, true).containsAll(false, true, false));
    BooleanIterable trueCollection = this.newWith(true, true, true, true);
    Assert.assertFalse(trueCollection.containsAll(true, false));
    BooleanIterable falseCollection = this.newWith(false, false, false, false);
    Assert.assertFalse(falseCollection.containsAll(true, false));
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) Test(org.junit.Test)

Example 25 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.

the class AbstractBooleanIterableTestCase method injectInto.

@Test
public void injectInto() {
    BooleanIterable iterable = this.newWith(true, false, true);
    MutableInteger result = iterable.injectInto(new MutableInteger(0), (object, value) -> object.add(value ? 1 : 0));
    Assert.assertEquals(new MutableInteger(2), result);
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) MutableInteger(org.eclipse.collections.impl.math.MutableInteger) Test(org.junit.Test)

Aggregations

BooleanIterable (org.eclipse.collections.api.BooleanIterable)54 Test (org.junit.Test)47 LazyBooleanIterable (org.eclipse.collections.api.LazyBooleanIterable)27 BooleanIterator (org.eclipse.collections.api.iterator.BooleanIterator)11 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)8 MutableBooleanBag (org.eclipse.collections.api.bag.primitive.MutableBooleanBag)4 MutableBooleanIterator (org.eclipse.collections.api.iterator.MutableBooleanIterator)4 MutableBooleanList (org.eclipse.collections.api.list.primitive.MutableBooleanList)2 ReverseBooleanIterable (org.eclipse.collections.impl.lazy.primitive.ReverseBooleanIterable)2 NoSuchElementException (java.util.NoSuchElementException)1 MutableBooleanCollection (org.eclipse.collections.api.collection.primitive.MutableBooleanCollection)1 BooleanHashBag (org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag)1 BooleanPredicates (org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates)1 FastList (org.eclipse.collections.impl.list.mutable.FastList)1 MutableInteger (org.eclipse.collections.impl.math.MutableInteger)1 AbstractBooleanIterable (org.eclipse.collections.impl.primitive.AbstractBooleanIterable)1 SynchronizedBooleanIterable (org.eclipse.collections.impl.primitive.SynchronizedBooleanIterable)1 BooleanHashSet (org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet)1 Verify (org.eclipse.collections.impl.test.Verify)1 Assert (org.junit.Assert)1