Search in sources :

Example 21 with LongIterable

use of org.eclipse.collections.api.LongIterable in project mapdb by jankotek.

the class AbstractLongIterableTestCase method reject.

@Test
public void reject() {
    LongIterable iterable = this.classUnderTest();
    int size = iterable.size();
    Verify.assertSize(size <= 3 ? 0 : size - 3, iterable.reject(LongPredicates.lessThan(4L)));
    Verify.assertSize(size <= 2 ? 0 : size - 2, iterable.reject(LongPredicates.lessThan(3L)));
    LongIterable iterable1 = this.newWith(0L, 1L, 2L, 2L, 3L, 3L, 3L);
    Assert.assertEquals(this.newMutableCollectionWith(2L, 2L, 3L, 3L, 3L), iterable1.reject(LongPredicates.lessThan(2L)));
    Assert.assertEquals(this.newMutableCollectionWith(0L, 1L), iterable1.reject(LongPredicates.greaterThan(1L)));
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) Test(org.junit.Test)

Example 22 with LongIterable

use of org.eclipse.collections.api.LongIterable in project mapdb by jankotek.

the class AbstractLongIterableTestCase method injectInto.

@Test
public void injectInto() {
    LongIterable iterable1 = this.newWith(0L, 2L, 31L);
    Long sum1 = iterable1.injectInto(Long.valueOf(0L), (Long result, long value) -> Long.valueOf((long) (result + value + 1)));
    Assert.assertEquals(Long.valueOf(36L), sum1);
    LongIterable iterable2 = this.newWith(1L, 2L, 31L);
    Long sum2 = iterable2.injectInto(Long.valueOf(0L), (Long result, long value) -> Long.valueOf((long) (result + value + 1)));
    Assert.assertEquals(Long.valueOf(37L), sum2);
    LongIterable iterable3 = this.newWith(0L, 1L, 2L, 31L);
    Long sum3 = iterable3.injectInto(Long.valueOf(0L), (Long result, long value) -> Long.valueOf((long) (result + value + 1)));
    Assert.assertEquals(Long.valueOf(38L), sum3);
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) Test(org.junit.Test)

Example 23 with LongIterable

use of org.eclipse.collections.api.LongIterable in project mapdb by jankotek.

the class AbstractLongIterableTestCase method longIterator_throws_non_empty_collection.

@Test(expected = NoSuchElementException.class)
public void longIterator_throws_non_empty_collection() {
    LongIterable iterable = this.newWith(1L, 2L, 3L);
    LongIterator iterator = iterable.longIterator();
    while (iterator.hasNext()) {
        iterator.next();
    }
    iterator.next();
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) LongIterator(org.eclipse.collections.api.iterator.LongIterator) Test(org.junit.Test)

Example 24 with LongIterable

use of org.eclipse.collections.api.LongIterable in project mapdb by jankotek.

the class AbstractLongIterableTestCase method asLazy.

@Test
public void asLazy() {
    LongIterable iterable = this.classUnderTest();
    Assert.assertEquals(iterable.toBag(), iterable.asLazy().toBag());
    Verify.assertInstanceOf(LazyLongIterable.class, iterable.asLazy());
    LongIterable iterable1 = this.newWith(1L, 2L, 2L, 3L, 3L, 3L);
    Assert.assertEquals(iterable1.toBag(), iterable1.asLazy().toBag());
    Verify.assertInstanceOf(LazyLongIterable.class, iterable1.asLazy());
    LongIterable iterable2 = this.newWith(1L, 2L, 2L, 3L, 3L, 3L);
    Assert.assertEquals(iterable2.toBag(), iterable2.asLazy().toBag());
    Verify.assertInstanceOf(LazyLongIterable.class, iterable2.asLazy());
    LongIterable iterable3 = this.newWith();
    Assert.assertEquals(iterable3.toBag(), iterable3.asLazy().toBag());
    Verify.assertInstanceOf(LazyLongIterable.class, iterable3.asLazy());
    LongIterable iterable4 = this.newWith(1L);
    Assert.assertEquals(iterable4.toBag(), iterable4.asLazy().toBag());
    Verify.assertInstanceOf(LazyLongIterable.class, iterable4.asLazy());
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) Test(org.junit.Test)

Example 25 with LongIterable

use of org.eclipse.collections.api.LongIterable in project mapdb by jankotek.

the class AbstractLongIterableTestCase method toArray.

@Test
public void toArray() {
    Assert.assertEquals(this.classUnderTest().size(), this.classUnderTest().toArray().length);
    LongIterable iterable = this.newWith(1L, 2L);
    Assert.assertTrue(Arrays.equals(new long[] { 1L, 2L }, iterable.toArray()) || Arrays.equals(new long[] { 2L, 1L }, iterable.toArray()));
    Assert.assertTrue(Arrays.equals(new long[] { 0L, 1L }, this.newWith(0L, 1L).toArray()) || Arrays.equals(new long[] { 1L, 0L }, this.newWith(0L, 1L).toArray()));
    Assert.assertTrue(Arrays.equals(new long[] { 1L, 31L }, this.newWith(1L, 31L).toArray()) || Arrays.equals(new long[] { 31L, 1L }, this.newWith(1L, 31L).toArray()));
    Assert.assertTrue(Arrays.equals(new long[] { 31L, 35L }, this.newWith(31L, 35L).toArray()) || Arrays.equals(new long[] { 35L, 31L }, this.newWith(31L, 35L).toArray()));
    Assert.assertArrayEquals(new long[] {}, this.newWith().toArray());
    Assert.assertArrayEquals(new long[] { 32L }, this.newWith(32L).toArray());
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) Test(org.junit.Test)

Aggregations

LongIterable (org.eclipse.collections.api.LongIterable)29 Test (org.junit.Test)29 LazyLongIterable (org.eclipse.collections.api.LazyLongIterable)24 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 LongIterator (org.eclipse.collections.api.iterator.LongIterator)5 Arrays (java.util.Arrays)4 NoSuchElementException (java.util.NoSuchElementException)4 RichIterable (org.eclipse.collections.api.RichIterable)4 LongToObjectFunction (org.eclipse.collections.api.block.function.primitive.LongToObjectFunction)4 LongHashBag (org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag)4 LongPredicates (org.eclipse.collections.impl.block.factory.primitive.LongPredicates)4 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)4 Verify (org.eclipse.collections.impl.test.Verify)4 Assert (org.junit.Assert)4 ImmutableLongLongMap (org.eclipse.collections.api.map.primitive.ImmutableLongLongMap)2 LongLongMap (org.eclipse.collections.api.map.primitive.LongLongMap)2