Search in sources :

Example 26 with BooleanIterable

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

the class AbstractBooleanIterableTestCase method contains.

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

Example 27 with BooleanIterable

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

the class SynchronizedBooleanIterableTest method booleanIterator.

@Override
@Test
public void booleanIterator() {
    BooleanIterable iterable = this.newWith(true, true, false, false);
    BooleanArrayList list = BooleanArrayList.newListWith(true, true, false, false);
    BooleanIterator iterator = iterable.booleanIterator();
    for (int i = 0; i < 4; i++) {
        Assert.assertTrue(iterator.hasNext());
        Assert.assertTrue(list.remove(iterator.next()));
    }
    Verify.assertEmpty(list);
    Assert.assertFalse(iterator.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator::next);
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) SynchronizedBooleanIterable(org.eclipse.collections.impl.primitive.SynchronizedBooleanIterable) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 28 with BooleanIterable

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

the class MapIterableTestCase method collectBoolean.

@Test
public void collectBoolean() {
    MapIterable<String, String> map = this.newMapWithKeysValues("One", "true", "Two", "nah", "Three", "TrUe");
    BooleanIterable actual = map.collectBoolean(Boolean::parseBoolean);
    Assert.assertEquals(BooleanHashBag.newBagWith(true, false, true), actual.toBag());
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) Test(org.junit.Test)

Example 29 with BooleanIterable

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

the class ObjectBooleanHashMapValuesTestCase method appendString.

@Override
@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()));
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) Test(org.junit.Test)

Example 30 with BooleanIterable

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

the class ImmutableBooleanEmptyListTest method select.

@Override
@Test
public void select() {
    super.select();
    BooleanIterable iterable = this.classUnderTest();
    Verify.assertEmpty(iterable.select(BooleanPredicates.isTrue()));
    BooleanIterable booleanIterable = iterable.select(BooleanPredicates.isFalse());
    Verify.assertEmpty(booleanIterable);
    Assert.assertSame(iterable, booleanIterable);
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) 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