Search in sources :

Example 51 with BooleanIterable

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

the class AbstractBooleanIterableTestCase method asLazy.

@Test
public void asLazy() {
    BooleanIterable iterable = this.classUnderTest();
    Assert.assertEquals(iterable.toBag(), iterable.asLazy().toBag());
    Verify.assertInstanceOf(LazyBooleanIterable.class, iterable.asLazy());
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) Test(org.junit.Test)

Example 52 with BooleanIterable

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

the class AbstractBooleanIterableTestCase method appendString.

@Test
public void appendString() {
    StringBuilder appendable = new StringBuilder();
    this.newWith().appendString(appendable);
    Assert.assertEquals("", appendable.toString());
    this.newWith().appendString(appendable, "/");
    Assert.assertEquals("", appendable.toString());
    this.newWith().appendString(appendable, "[", "/", "]");
    Assert.assertEquals("[]", appendable.toString());
    StringBuilder appendable1 = new StringBuilder();
    this.newWith(true).appendString(appendable1);
    Assert.assertEquals("true", appendable1.toString());
    StringBuilder appendable2 = new StringBuilder();
    BooleanIterable iterable = this.newWith(true, false);
    iterable.appendString(appendable2);
    Assert.assertTrue("true, false".equals(appendable2.toString()) || "false, true".equals(appendable2.toString()));
    StringBuilder appendable3 = new StringBuilder();
    iterable.appendString(appendable3, "/");
    Assert.assertTrue("true/false".equals(appendable3.toString()) || "false/true".equals(appendable3.toString()));
    StringBuilder appendable4 = new StringBuilder();
    iterable.appendString(appendable4, "[", ", ", "]");
    Assert.assertEquals(iterable.toString(), appendable4.toString());
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) Test(org.junit.Test)

Example 53 with BooleanIterable

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

the class AbstractBooleanIterableTestCase method count.

@Test
public void count() {
    Assert.assertEquals(2L, this.newWith(true, false, true).count(BooleanPredicates.isTrue()));
    Assert.assertEquals(0L, this.newWith().count(BooleanPredicates.isFalse()));
    BooleanIterable iterable = this.newWith(true, false, false, true, true, true);
    Assert.assertEquals(4L, iterable.count(BooleanPredicates.isTrue()));
    Assert.assertEquals(2L, iterable.count(BooleanPredicates.isFalse()));
    Assert.assertEquals(6L, iterable.count(BooleanPredicates.or(BooleanPredicates.isTrue(), BooleanPredicates.isFalse())));
    BooleanIterable iterable1 = this.classUnderTest();
    int size = iterable1.size();
    int halfSize = size / 2;
    Assert.assertEquals((size & 1) == 1 ? halfSize + 1 : halfSize, iterable1.count(BooleanPredicates.isTrue()));
    Assert.assertEquals(halfSize, iterable1.count(BooleanPredicates.isFalse()));
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) Test(org.junit.Test)

Example 54 with BooleanIterable

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

the class AbstractBooleanIterableTestCase method detectIfNone.

@Test
public void detectIfNone() {
    BooleanIterable iterable = this.classUnderTest();
    int size = iterable.size();
    Assert.assertEquals(size < 2, iterable.detectIfNone(BooleanPredicates.isFalse(), true));
    Assert.assertTrue(iterable.detectIfNone(BooleanPredicates.and(BooleanPredicates.isTrue(), BooleanPredicates.isFalse()), true));
    BooleanIterable iterable1 = this.newWith(true, true, true);
    Assert.assertFalse(iterable1.detectIfNone(BooleanPredicates.isFalse(), false));
    Assert.assertTrue(iterable1.detectIfNone(BooleanPredicates.isFalse(), true));
    Assert.assertTrue(iterable1.detectIfNone(BooleanPredicates.isTrue(), false));
    Assert.assertTrue(iterable1.detectIfNone(BooleanPredicates.isTrue(), true));
    BooleanIterable iterable2 = this.newWith(false, false, false);
    Assert.assertTrue(iterable2.detectIfNone(BooleanPredicates.isTrue(), true));
    Assert.assertFalse(iterable2.detectIfNone(BooleanPredicates.isTrue(), false));
    Assert.assertFalse(iterable2.detectIfNone(BooleanPredicates.isFalse(), true));
    Assert.assertFalse(iterable2.detectIfNone(BooleanPredicates.isFalse(), false));
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) 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