Search in sources :

Example 6 with ImmutableByteSet

use of org.eclipse.collections.api.set.primitive.ImmutableByteSet in project eclipse-collections by eclipse.

the class AbstractImmutableByteHashSetTestCase method reject.

@Override
@Test
public void reject() {
    super.reject();
    ImmutableByteSet set = this.newWith((byte) 0, (byte) 1, (byte) 31, (byte) 127, (byte) -1, (byte) -31, (byte) -64, (byte) -65, (byte) -128);
    Verify.assertSize(6, set.reject(BytePredicates.greaterThan((byte) 0)));
    Verify.assertSize(1, set.reject(BytePredicates.lessThan((byte) 32)));
}
Also used : ImmutableByteSet(org.eclipse.collections.api.set.primitive.ImmutableByteSet) Test(org.junit.Test)

Example 7 with ImmutableByteSet

use of org.eclipse.collections.api.set.primitive.ImmutableByteSet in project eclipse-collections by eclipse.

the class AbstractImmutableByteHashSetTestCase method testEquals.

@Override
@Test
public void testEquals() {
    super.testEquals();
    ImmutableByteSet set1 = this.newWith((byte) 1, (byte) 31, (byte) 32);
    ImmutableByteSet set2 = this.newWith((byte) 32, (byte) 31, (byte) 1);
    ImmutableByteSet set3 = this.newWith((byte) 32, (byte) 32, (byte) 31, (byte) 1);
    ImmutableByteSet set4 = this.newWith((byte) 32, (byte) 32, (byte) 31, (byte) 1, (byte) 1);
    Verify.assertEqualsAndHashCode(set1, set2);
    Verify.assertEqualsAndHashCode(set1, set3);
    Verify.assertEqualsAndHashCode(set1, set4);
    Verify.assertEqualsAndHashCode(set2, set3);
    Verify.assertEqualsAndHashCode(set2, set4);
}
Also used : ImmutableByteSet(org.eclipse.collections.api.set.primitive.ImmutableByteSet) Test(org.junit.Test)

Example 8 with ImmutableByteSet

use of org.eclipse.collections.api.set.primitive.ImmutableByteSet in project narchy by automenta.

the class CommonVariable method common.

public static Variable common(Variable A, Variable B) {
    // 1. sort
    if (A.compareTo(B) < 0) {
        Variable c = B;
        B = A;
        A = c;
    }
    Op Aop = A.op();
    assert (B.op() == Aop);
    boolean aa = A instanceof NormalizedVariable;
    boolean bb = B instanceof NormalizedVariable;
    if (aa && bb) {
        byte ai = ((NormalizedVariable) A).anonNum();
        byte bi = ((NormalizedVariable) B).anonNum();
        return new CommonVariable(Aop, ai, bi);
    }
    if (!aa && bb) {
        ImmutableByteSet ai = ((CommonVariable) A).vars;
        byte bi = ((NormalizedVariable) B).anonNum();
        if (ai.contains(bi))
            return A;
        return new CommonVariable(Aop, ai.newWith(bi));
    }
    if (aa && !bb) {
        byte ai = ((NormalizedVariable) A).anonNum();
        ImmutableByteSet bi = ((CommonVariable) B).vars;
        if (bi.contains(ai))
            return B;
        return new CommonVariable(Aop, bi.newWith(ai));
    }
    /*if (!aa && !bb)*/
    {
        ImmutableByteSet ai = ((CommonVariable) A).vars;
        ImmutableByteSet bi = ((CommonVariable) B).vars;
        ImmutableByteSet combined = ai.newWithAll(bi);
        if (combined.equals(ai))
            return A;
        return new CommonVariable(Aop, combined);
    }
}
Also used : Op(nars.Op) ImmutableByteSet(org.eclipse.collections.api.set.primitive.ImmutableByteSet)

Example 9 with ImmutableByteSet

use of org.eclipse.collections.api.set.primitive.ImmutableByteSet in project eclipse-collections by eclipse.

the class AbstractImmutableByteHashSetTestCase method select.

@Override
@Test
public void select() {
    super.select();
    ImmutableByteSet set = this.newWith((byte) 0, (byte) 1, (byte) 31, (byte) 127, (byte) -1, (byte) -31, (byte) -64, (byte) -65, (byte) -128);
    Verify.assertSize(8, set.select(BytePredicates.lessThan((byte) 32)));
    Verify.assertSize(3, set.select(BytePredicates.greaterThan((byte) 0)));
}
Also used : ImmutableByteSet(org.eclipse.collections.api.set.primitive.ImmutableByteSet) Test(org.junit.Test)

Example 10 with ImmutableByteSet

use of org.eclipse.collections.api.set.primitive.ImmutableByteSet in project eclipse-collections by eclipse.

the class AbstractImmutableByteHashSetTestCase method byteIterator_throws.

@Override
@Test(expected = NoSuchElementException.class)
public void byteIterator_throws() {
    ImmutableByteSet set = this.newWith((byte) 0, (byte) 1, (byte) 31);
    ByteIterator iterator = set.byteIterator();
    while (iterator.hasNext()) {
        iterator.next();
    }
    iterator.next();
}
Also used : ByteIterator(org.eclipse.collections.api.iterator.ByteIterator) ImmutableByteSet(org.eclipse.collections.api.set.primitive.ImmutableByteSet) Test(org.junit.Test)

Aggregations

ImmutableByteSet (org.eclipse.collections.api.set.primitive.ImmutableByteSet)13 Test (org.junit.Test)12 ByteIterator (org.eclipse.collections.api.iterator.ByteIterator)3 NoSuchElementException (java.util.NoSuchElementException)1 Op (nars.Op)1 LazyByteIterable (org.eclipse.collections.api.LazyByteIterable)1 MutableSet (org.eclipse.collections.api.set.MutableSet)1 MutableByteSet (org.eclipse.collections.api.set.primitive.MutableByteSet)1 ByteHashBag (org.eclipse.collections.impl.bag.mutable.primitive.ByteHashBag)1 BytePredicates (org.eclipse.collections.impl.block.factory.primitive.BytePredicates)1 AbstractImmutableByteCollectionTestCase (org.eclipse.collections.impl.collection.immutable.primitive.AbstractImmutableByteCollectionTestCase)1 UnifiedSet (org.eclipse.collections.impl.set.mutable.UnifiedSet)1 Verify (org.eclipse.collections.impl.test.Verify)1 Assert (org.junit.Assert)1