Search in sources :

Example 41 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 42 with LongIterable

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

the class AbstractLongIterableTestCase method makeString.

@Test
public void makeString() {
    LongIterable iterable = this.classUnderTest();
    Assert.assertEquals("1", this.newWith(1L).makeString("/"));
    Assert.assertEquals("31", this.newWith(31L).makeString());
    Assert.assertEquals("32", this.newWith(32L).makeString());
    Assert.assertEquals(iterable.toString(), iterable.makeString("[", ", ", "]"));
    Assert.assertEquals("", this.newWith().makeString());
    Assert.assertEquals("", this.newWith().makeString("/"));
    Assert.assertEquals("[]", this.newWith().makeString("[", ", ", "]"));
    LongIterable iterable1 = this.newWith(0L, 31L);
    Assert.assertTrue(iterable1.makeString(), iterable1.makeString().equals("0, 31") || iterable1.makeString().equals("31, 0"));
    LongIterable iterable2 = this.newWith(31L, 32L);
    Assert.assertTrue(iterable2.makeString("[", "/", "]"), iterable2.makeString("[", "/", "]").equals("[31/32]") || iterable2.makeString("[", "/", "]").equals("[32/31]"));
    LongIterable iterable3 = this.newWith(32L, 33L);
    Assert.assertTrue(iterable3.makeString("/"), iterable3.makeString("/").equals("32/33") || iterable3.makeString("/").equals("33/32"));
    LongIterable iterable4 = this.newWith(1L, 2L);
    Assert.assertTrue("1, 2".equals(iterable4.makeString()) || "2, 1".equals(iterable4.makeString()));
    Assert.assertTrue("1/2".equals(iterable4.makeString("/")) || "2/1".equals(iterable4.makeString("/")));
    Assert.assertTrue("[1/2]".equals(iterable4.makeString("[", "/", "]")) || "[2/1]".equals(iterable4.makeString("[", "/", "]")));
    LongIterable iterable5 = this.newWith(0L, 1L);
    Assert.assertTrue(iterable5.makeString(), iterable5.makeString().equals("0, 1") || iterable5.makeString().equals("1, 0"));
    Assert.assertTrue(iterable5.makeString("[", "/", "]"), iterable5.makeString("[", "/", "]").equals("[0/1]") || iterable5.makeString("[", "/", "]").equals("[1/0]"));
    Assert.assertTrue(iterable5.makeString("/"), iterable5.makeString("/").equals("0/1") || iterable5.makeString("/").equals("1/0"));
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) Test(org.junit.Test)

Example 43 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 44 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 45 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)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