package jetbrains.mps.internal.collections.trove.test; /*Generated by MPS */ import jetbrains.mps.internalCollections.test.closures.Util_Test; import java.util.Set; import jetbrains.mps.internal.collections.runtime.SetSequence; import gnu.trove.decorator.TByteHashSetDecorator; import gnu.trove.TByteHashSet; import junit.framework.Assert; import java.util.HashSet; import gnu.trove.decorator.TDoubleHashSetDecorator; import gnu.trove.TDoubleHashSet; import gnu.trove.decorator.TFloatHashSetDecorator; import gnu.trove.TFloatHashSet; import gnu.trove.decorator.TIntHashSetDecorator; import gnu.trove.TIntHashSet; import jetbrains.mps.internal.collections.runtime.Sequence; import jetbrains.mps.internal.collections.runtime.ISequenceClosure; import java.util.Iterator; import jetbrains.mps.baseLanguage.closures.runtime.YieldingIterator; import gnu.trove.decorator.TLongHashSetDecorator; import gnu.trove.TLongHashSet; import jetbrains.mps.internal.collections.runtime.ArrayUtils; import jetbrains.mps.internal.collections.runtime.IVisitor; import jetbrains.mps.internal.collections.runtime.ISelector; import gnu.trove.decorator.TShortHashSetDecorator; import gnu.trove.TShortHashSet; public class PrimSet_Test extends Util_Test { public void test_byteSet() throws Exception { Set<Byte> bs = SetSequence.fromSet(new TByteHashSetDecorator(new TByteHashSet())); SetSequence.fromSet(bs).addElement((byte) 192); SetSequence.fromSet(bs).addElement((byte) 168); SetSequence.fromSet(bs).addElement((byte) 1); SetSequence.fromSet(bs).addElement((byte) 1); Assert.assertSame(3, SetSequence.fromSet(bs).count()); Assert.assertEquals(SetSequence.fromSetAndArray(new HashSet<Byte>(), (byte) 192, (byte) 168, (byte) 1), bs); } public void test_doubleSet() throws Exception { Set<Double> ds = SetSequence.fromSetAndArray(new TDoubleHashSetDecorator(new TDoubleHashSet()), 1.1, 2.2, 3.3, 2.2, 1.1); Assert.assertSame(3, SetSequence.fromSet(ds).count()); Assert.assertEquals(SetSequence.fromSetAndArray(new HashSet<Double>(), 3.3, 2.2, 1.1), ds); } public void test_floatSet() throws Exception { Set<Float> fs = SetSequence.fromSet(new TFloatHashSetDecorator(new TFloatHashSet())); Set<Float> exp = SetSequence.fromSetAndArray(new HashSet<Float>(), 5.5f, 6.6f, 7.7f, 8.8f, 9.9f); SetSequence.fromSet(fs).addSequence(SetSequence.fromSet(exp)); SetSequence.fromSet(fs).addSequence(SetSequence.fromSet(exp)); Assert.assertSame(5, SetSequence.fromSet(fs).count()); Assert.assertEquals(exp, fs); } public void test_intSet() throws Exception { Set<Integer> is = SetSequence.fromSet(new TIntHashSetDecorator(new TIntHashSet())); SetSequence.fromSet(is).addSequence(Sequence.fromIterable(Sequence.fromClosure(new ISequenceClosure<Integer>() { public Iterable<Integer> iterable() { return new Iterable<Integer>() { public Iterator<Integer> iterator() { return new YieldingIterator<Integer>() { private int __CP__ = 0; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this._2_i = 1; case 3: if (!(_2_i <= 10)) { this.__CP__ = 1; break; } this.__CP__ = 4; break; case 5: _2_i++; this.__CP__ = 3; break; case 6: this.__CP__ = 5; this.yield(_2_i); return true; case 0: this.__CP__ = 2; break; case 4: this.__CP__ = 6; break; default: break __loop__; } } while (true); return false; } private int _2_i; }; } }; } }))); this.assertIterableEqualsAsSet(this.input10(), is); } public void test_longSet() throws Exception { final Set<Long> ls = SetSequence.fromSet(new TLongHashSetDecorator(new TLongHashSet())); Sequence.fromIterable(ArrayUtils.fromLongArray(new long[]{5, 4, 3, 2, 1, 2, 3, 4, 5})).visitAll(new IVisitor<Long>() { public void visit(Long i) { SetSequence.fromSet(ls).addElement(i); } }); this.assertIterableEqualsAsSet(this.input5(), SetSequence.fromSet(ls).select(new ISelector<Long, Integer>() { public Integer select(Long l) { return (int) (long) l; } })); } public void test_shortSet() throws Exception { Set<Short> shs = SetSequence.fromSet(new TShortHashSetDecorator(new TShortHashSet())); SetSequence.fromSet(shs).addElement((short) 65535); SetSequence.fromSet(shs).addElement((short) -1); Assert.assertSame(1, SetSequence.fromSet(shs).count()); } public PrimSet_Test() { } }