package jetbrains.mps.baseLanguage.tuples.test; /*Generated by MPS */ import junit.framework.TestCase; import jetbrains.mps.baseLanguage.tuples.runtime.Tuples; import jetbrains.mps.baseLanguage.tuples.runtime.MultiTuple; import junit.framework.Assert; import jetbrains.mps.baseLanguage.tuples.util.A; import jetbrains.mps.internal.collections.runtime.Sequence; import jetbrains.mps.internal.collections.runtime.IWhereFilter; import java.util.List; import jetbrains.mps.internal.collections.runtime.ListSequence; import java.util.ArrayList; import jetbrains.mps.internal.collections.runtime.ArrayUtils; import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes; import jetbrains.mps.baseLanguage.tuples.util.MPS11114; import jetbrains.mps.internal.collections.runtime.MapSequence; import jetbrains.mps.baseLanguage.tuples.util.Sum; import jetbrains.mps.baseLanguage.tuples.util.Foo; public class IndexedTuples_Test extends TestCase { public void test_empty() throws Exception { Tuples._0 empty = MultiTuple.from(); empty = MultiTuple.from(); Tuples._0 emptyToo = empty; } public void test_creatingAndAssigning() throws Exception { Tuples._2<Integer, String> pair = MultiTuple.<Integer,String>from(1, "a"); Assert.assertSame(1, (int) pair._0()); Assert.assertEquals("a", pair._1()); Tuples._2<Integer, String> anotherPair = pair; Assert.assertTrue(((Object) anotherPair) == ((Object) pair)); Assert.assertTrue(MultiTuple.eq(anotherPair, pair)); Assert.assertEquals(pair, anotherPair); Assert.assertSame(1, (int) anotherPair._0()); Assert.assertEquals("a", anotherPair._1()); pair._0(111); pair._1("aaaa"); Assert.assertSame(111, (int) anotherPair._0()); Assert.assertEquals("aaaa", anotherPair._1()); Assert.assertSame(111, (int) pair._0()); Assert.assertEquals("aaaa", pair._1()); } public void test_writeVar() throws Exception { int a; { Tuples._1<Integer> _tmp_3wrel6_b0c0 = MultiTuple.<Integer>from(1); a = _tmp_3wrel6_b0c0._0(); } Assert.assertSame(1, a); char c = 'a'; { Tuples._2<Integer, Character> _tmp_3wrel6_e0c0 = MultiTuple.<Integer,Character>from(2, 'b'); a = _tmp_3wrel6_e0c0._0(); c = _tmp_3wrel6_e0c0._1(); } Assert.assertSame(2, a); Assert.assertSame('b', c); } public void test_swapVars() throws Exception { String foo = "bar"; String bar = "foo"; { Tuples._2<String, String> _tmp_3wrel6_c0d0 = MultiTuple.<String,String>from(bar, foo); foo = _tmp_3wrel6_c0d0._0(); bar = _tmp_3wrel6_c0d0._1(); } Assert.assertEquals("foo", foo); Assert.assertEquals("bar", bar); } public void test_multiValueReturn() throws Exception { Tuples._2<String, Character> pair = this.toTuple("abc", 'd'); Assert.assertEquals("abc", pair._0()); Assert.assertSame('d', (char) pair._1()); } public void test_equalsOperator() throws Exception { Tuples._2<Integer, Character> tpl1 = MultiTuple.<Integer,Character>from(1, 'a'); Tuples._2<Integer, Character> tpl2 = MultiTuple.<Integer,Character>from(1, 'a'); Assert.assertTrue(MultiTuple.eq(tpl1, tpl2)); Assert.assertFalse(!(MultiTuple.eq(tpl1, tpl2))); tpl2._0(2); tpl1._1('b'); Assert.assertTrue(!(MultiTuple.eq(tpl1, tpl2))); Assert.assertFalse(MultiTuple.eq(tpl1, tpl2)); } public void test_mps5466() throws Exception { Iterable<Tuples._2<String, Boolean>> seq = A.foo(); Assert.assertSame(1, Sequence.fromIterable(seq).where(new IWhereFilter<Tuples._2<String, Boolean>>() { public boolean accept(Tuples._2<String, Boolean> it) { return it._1() != true; } }).count()); } public void test_listOfTuples() throws Exception { List<Tuples._2<Integer, String>> lot = ListSequence.fromListAndArray(new ArrayList<Tuples._2<Integer, String>>(), MultiTuple.<Integer,String>from(1, "A"), MultiTuple.<Integer,String>from(2, "B"), MultiTuple.<Integer,String>from(3, "C")); Assert.assertSame(3, ListSequence.fromList(lot).count()); Assert.assertEquals("B", ListSequence.fromList(lot).getElement(1)._1()); } public void test_arrayOfTuples() throws Exception { Tuples._3<String, Integer, Boolean>[] arr1 = ArrayUtils.asArray(MultiTuple.<String,Integer,Boolean>from("foo", 1, false), MultiTuple.<String,Integer,Boolean>from("bar", 2, true), MultiTuple.<String,Integer,Boolean>from("baz", 3, false)); Assert.assertSame(3, arr1.length); Assert.assertEquals("foo", arr1[0]._0()); Assert.assertTrue((boolean) arr1[1]._2()); Assert.assertEquals("baz", arr1[2]._0()); Assert.assertSame(3, (int) arr1[2]._1()); Tuples._3<String, Integer, Boolean>[] arr2 = (Tuples._3<String, Integer, Boolean>[]) ArrayUtils.newArrayInstance(Tuples._3.class, 3); Assert.assertSame(3, arr2.length); for (int idx = 0; idx < arr1.length; idx++) { arr2[idx] = arr1[idx]; } Assert.assertEquals("bar", arr2[1]._0()); Assert.assertFalse((boolean) arr2[2]._2()); Assert.assertEquals("baz", arr2[2]._0()); Assert.assertSame(2, (int) arr2[1]._1()); } public void test_tupleDecl() throws Exception { Tuples._2<String, Long> sit; sit = MultiTuple.<String,Long>from("A", -1L); Assert.assertEquals("A", sit._0()); } public void test_mps7408() throws Exception { MPS7408 foo = new MPS7408(); Tuples._2<_FunctionTypes._return_P0_E0<? extends Boolean>, _FunctionTypes._void_P0_E0> asd = MultiTuple.<_FunctionTypes._return_P0_E0<? extends Boolean>,_FunctionTypes._void_P0_E0>from(new _FunctionTypes._return_P0_E0<Boolean>() { public Boolean invoke() { return true; } }, new _FunctionTypes._void_P0_E0() { public void invoke() { } }); foo.waitFor(asd); Assert.assertSame(1, ListSequence.fromList(foo.jobs).count()); } public void test_mps7409() throws Exception { Tuples._1<_FunctionTypes._return_P0_E0<? extends Boolean>> t = MultiTuple.<_FunctionTypes._return_P0_E0<? extends Boolean>>from(new _FunctionTypes._return_P0_E0<Boolean>() { public Boolean invoke() { return false; } }); Assert.assertFalse(t._0().invoke()); } public void test_mps8674() throws Exception { Tuples._2<Integer, String> t = MultiTuple.<Integer,String>from(0, null); Assert.assertNotNull(t); Assert.assertSame(0, (int) t._0()); Assert.assertNull(t._1()); } public void test_mps11114() throws Exception { for (Tuples._2<Integer, String> tt : MPS11114.returnTuples()) { Assert.assertNotNull(tt); } } public void test_mps11134() throws Exception { Tuples._2<Integer, Integer> pair = MultiTuple.<Integer,Integer>from(1, 1); Assert.assertSame((int) pair._0(), (int) pair._1()); Tuples._2<Integer, Integer> pair2 = MultiTuple.<Integer,Integer>from(9999 + 1, 10001 - 1); Assert.assertTrue((int) pair2._0() == 10000); Assert.assertTrue(10000 == (int) pair2._1()); } public void test_mps6985() throws Exception { Tuples._2<Integer, Integer> pair; pair = MapSequence.fromMap(new Sum().map).get(42); } public void test_mps11447() throws Exception { Tuples._2<Object, Object> pair; pair = new Nulls().returnsNulls(); Assert.assertNull(pair._0()); Assert.assertNull(pair._1()); } public void test_nulls() throws Exception { Tuples._2<Integer, String> pair = null; Assert.assertNull(pair); pair = MultiTuple.<Integer,String>from(1, "1"); Assert.assertNotNull(pair); Tuples._2<Integer, String> pair2; pair2 = null; Assert.assertNull(pair2); pair2 = MultiTuple.<Integer,String>from(2, "2"); Assert.assertNotNull(pair2); } public void test_mps16045() throws Exception { String s = Foo.getTuple()._0(); Assert.assertEquals("bar", s); int i = (int) Foo.getTuple()._1(); Assert.assertSame(22, i); } public IndexedTuples_Test() { } public Tuples._2<String, Character> toTuple(String s, char c) { return MultiTuple.<String,Character>from(s, c); } }