Search in sources :

Example 1 with LongIterable

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

the class AbstractLongIterableTestCase method allSatisfy.

@Test
public void allSatisfy() {
    Assert.assertFalse(this.newWith(1L, 0L, 2L).allSatisfy(LongPredicates.greaterThan(0L)));
    Assert.assertTrue(this.newWith(1L, 2L, 3L).allSatisfy(LongPredicates.greaterThan(0L)));
    Assert.assertFalse(this.newWith(1L, 0L, 31L, 32L).allSatisfy(LongPredicates.greaterThan(0L)));
    Assert.assertFalse(this.newWith(1L, 0L, 31L, 32L).allSatisfy(LongPredicates.greaterThan(0L)));
    Assert.assertTrue(this.newWith(1L, 2L, 31L, 32L).allSatisfy(LongPredicates.greaterThan(0L)));
    Assert.assertFalse(this.newWith(32L).allSatisfy(LongPredicates.equal(33L)));
    Assert.assertFalse(this.newWith(-32L + 100).allSatisfy(LongPredicates.equal(33L + 100)));
    LongIterable iterable = this.newWith(0L, 1L, 2L);
    Assert.assertFalse(iterable.allSatisfy(value -> 3L < value));
    Assert.assertTrue(iterable.allSatisfy(LongPredicates.lessThan(3L)));
    LongIterable iterable1 = this.classUnderTest();
    int size = iterable1.size();
    Assert.assertEquals(size == 0, iterable1.allSatisfy(LongPredicates.greaterThan(3L)));
    Assert.assertEquals(size < 3, iterable1.allSatisfy(LongPredicates.lessThan(3L)));
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) Arrays(java.util.Arrays) Test(org.junit.Test) Verify(org.eclipse.collections.impl.test.Verify) LongHashBag(org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag) LongIterator(org.eclipse.collections.api.iterator.LongIterator) RichIterable(org.eclipse.collections.api.RichIterable) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) LongIterable(org.eclipse.collections.api.LongIterable) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) LongToObjectFunction(org.eclipse.collections.api.block.function.primitive.LongToObjectFunction) LongPredicates(org.eclipse.collections.impl.block.factory.primitive.LongPredicates) Assert(org.junit.Assert) NoSuchElementException(java.util.NoSuchElementException) LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) Test(org.junit.Test)

Example 2 with LongIterable

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

the class AbstractLongIterableTestCase method detectIfNone.

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

Example 3 with LongIterable

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

the class AbstractLongIterableTestCase 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(1L).appendString(appendable1);
    Assert.assertEquals("1", appendable1.toString());
    StringBuilder appendable2 = new StringBuilder();
    LongIterable iterable = this.newWith(1L, 2L);
    iterable.appendString(appendable2);
    Assert.assertTrue("1, 2".equals(appendable2.toString()) || "2, 1".equals(appendable2.toString()));
    StringBuilder appendable3 = new StringBuilder();
    iterable.appendString(appendable3, "/");
    Assert.assertTrue("1/2".equals(appendable3.toString()) || "2/1".equals(appendable3.toString()));
    StringBuilder appendable4 = new StringBuilder();
    iterable.appendString(appendable4, "[", ", ", "]");
    Assert.assertEquals(iterable.toString(), appendable4.toString());
    StringBuilder appendable5 = new StringBuilder();
    this.newWith(31L).appendString(appendable5);
    Assert.assertEquals("31", appendable5.toString());
    StringBuilder appendable6 = new StringBuilder();
    this.newWith(32L).appendString(appendable6);
    Assert.assertEquals("32", appendable6.toString());
    StringBuilder appendable7 = new StringBuilder();
    LongIterable iterable1 = this.newWith(0L, 31L);
    iterable1.appendString(appendable7);
    Assert.assertTrue(appendable7.toString(), "0, 31".equals(appendable7.toString()) || "31, 0".equals(appendable7.toString()));
    StringBuilder appendable8 = new StringBuilder();
    LongIterable iterable2 = this.newWith(31L, 32L);
    iterable2.appendString(appendable8, "/");
    Assert.assertTrue(appendable8.toString(), "31/32".equals(appendable8.toString()) || "32/31".equals(appendable8.toString()));
    StringBuilder appendable9 = new StringBuilder();
    LongIterable iterable4 = this.newWith(32L, 33L);
    iterable4.appendString(appendable9, "[", "/", "]");
    Assert.assertTrue(appendable9.toString(), "[32/33]".equals(appendable9.toString()) || "[33/32]".equals(appendable9.toString()));
    StringBuilder appendable10 = new StringBuilder();
    LongIterable iterable5 = this.newWith(0L, 1L);
    iterable5.appendString(appendable10);
    Assert.assertTrue(appendable10.toString(), "0, 1".equals(appendable10.toString()) || "1, 0".equals(appendable10.toString()));
    StringBuilder appendable11 = new StringBuilder();
    iterable5.appendString(appendable11, "/");
    Assert.assertTrue(appendable11.toString(), "0/1".equals(appendable11.toString()) || "1/0".equals(appendable11.toString()));
    StringBuilder appendable12 = new StringBuilder();
    iterable5.appendString(appendable12, "[", "/", "]");
    Assert.assertTrue(appendable12.toString(), "[0/1]".equals(appendable12.toString()) || "[1/0]".equals(appendable12.toString()));
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) Test(org.junit.Test)

Example 4 with LongIterable

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

the class AbstractLongIterableTestCase method contains.

@Test
public void contains() {
    LongIterable iterable = this.newWith(14L, 2L, 30L, 31L, 32L, 35L, 0L, 1L);
    Assert.assertFalse(iterable.contains(29L));
    Assert.assertFalse(iterable.contains(49L));
    long[] numbers = { 14L, 2L, 30L, 31L, 32L, 35L, 0L, 1L };
    for (long number : numbers) {
        Assert.assertTrue(iterable.contains(number));
    }
    Assert.assertFalse(iterable.contains(-1L));
    Assert.assertFalse(iterable.contains(29L));
    Assert.assertFalse(iterable.contains(49L));
    LongIterable iterable1 = this.newWith(0L, 1L, 1L, 2L, 2L, 2L);
    Assert.assertTrue(iterable1.contains(0L));
    Assert.assertTrue(iterable1.contains(1L));
    Assert.assertTrue(iterable1.contains(2L));
    Assert.assertFalse(iterable1.contains(3L));
    LongIterable iterable2 = this.classUnderTest();
    for (long each = 1; each <= iterable2.size(); each++) {
        Assert.assertTrue(iterable2.contains(each));
    }
    Assert.assertFalse(iterable2.contains(iterable2.size() + 1));
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) Test(org.junit.Test)

Example 5 with LongIterable

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

the class AbstractLongIterableTestCase method toSortedArray.

@Test
public void toSortedArray() {
    LongIterable iterable = this.classUnderTest();
    int size = iterable.size();
    long[] array = new long[size];
    for (int i = 0; i < size; i++) {
        array[i] = i + 1;
    }
    Assert.assertArrayEquals(array, iterable.toSortedArray());
    Assert.assertArrayEquals(new long[] { 1L, 3L, 7L, 9L }, this.newWith(3L, 1L, 9L, 7L).toSortedArray());
}
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)60 Test (org.junit.Test)54 LazyLongIterable (org.eclipse.collections.api.LazyLongIterable)46 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)13 LongIterator (org.eclipse.collections.api.iterator.LongIterator)10 Arrays (java.util.Arrays)8 NoSuchElementException (java.util.NoSuchElementException)8 RichIterable (org.eclipse.collections.api.RichIterable)8 LongToObjectFunction (org.eclipse.collections.api.block.function.primitive.LongToObjectFunction)8 LongHashBag (org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag)8 LongPredicates (org.eclipse.collections.impl.block.factory.primitive.LongPredicates)8 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)8 Verify (org.eclipse.collections.impl.test.Verify)8 Assert (org.junit.Assert)8 ImmutableLongLongMap (org.eclipse.collections.api.map.primitive.ImmutableLongLongMap)2 LongLongMap (org.eclipse.collections.api.map.primitive.LongLongMap)2 MutableLongCollection (org.eclipse.collections.api.collection.primitive.MutableLongCollection)1 IndexMap (org.neo4j.kernel.impl.api.index.IndexMap)1