package jetbrains.mps.internalCollections.test.basicOperations; /*Generated by MPS */ import junit.framework.TestCase; import jetbrains.mps.internal.collections.runtime.ArrayUtils; import jetbrains.mps.internal.collections.runtime.Sequence; import java.util.List; import jetbrains.mps.internal.collections.runtime.ListSequence; import java.util.ArrayList; import java.util.Iterator; import junit.framework.Assert; import jetbrains.mps.internal.collections.runtime.IterableUtils; public class MultiForeachTest_Test extends TestCase { public void test_nested() throws Exception { Iterable<Integer> sint = ArrayUtils.fromIntegerArray(new int[]{1, 2, 3}); Iterable<String> sstr = Sequence.fromArray(new String[]{"a", "b", "c"}); List<String> res = ListSequence.fromList(new ArrayList<String>()); { Iterator<Integer> foo_it = Sequence.fromIterable(sint).iterator(); Iterator<String> bar_it = Sequence.fromIterable(sstr).iterator(); int foo_var; String bar_var; while (foo_it.hasNext() && bar_it.hasNext()) { foo_var = foo_it.next(); bar_var = bar_it.next(); { Iterator<Integer> foo2_it = Sequence.fromIterable(sint).iterator(); Iterator<String> bar2_it = Sequence.fromIterable(sstr).iterator(); int foo2_var; String bar2_var; while (foo2_it.hasNext() && bar2_it.hasNext()) { foo2_var = foo2_it.next(); bar2_var = bar2_it.next(); ListSequence.fromList(res).addElement(bar_var + foo_var + bar2_var + foo2_var); } } } } Assert.assertEquals("a1a1a1b2a1c3b2a1b2b2b2c3c3a1c3b2c3c3", IterableUtils.join(ListSequence.fromList(res), "")); } public void test_repeated() throws Exception { Iterable<Integer> sint = ArrayUtils.fromIntegerArray(new int[]{1, 2, 3}); Iterable<String> sstr = Sequence.fromArray(new String[]{"a", "b", "c"}); List<String> res = ListSequence.fromList(new ArrayList<String>()); { Iterator<Integer> foo_it = Sequence.fromIterable(sint).iterator(); Iterator<String> bar_it = Sequence.fromIterable(sstr).iterator(); int foo_var; String bar_var; while (foo_it.hasNext() && bar_it.hasNext()) { foo_var = foo_it.next(); bar_var = bar_it.next(); ListSequence.fromList(res).addElement(bar_var + foo_var); } } { Iterator<Integer> foo_it = Sequence.fromIterable(sint).iterator(); Iterator<String> bar_it = Sequence.fromIterable(sstr).iterator(); int foo_var; String bar_var; while (foo_it.hasNext() && bar_it.hasNext()) { foo_var = foo_it.next(); bar_var = bar_it.next(); ListSequence.fromList(res).addElement(bar_var + foo_var); } } Assert.assertEquals("a1b2c3a1b2c3", IterableUtils.join(ListSequence.fromList(res), "")); } public void test_secondShort() throws Exception { Iterable<Integer> sint = ArrayUtils.fromIntegerArray(new int[]{1, 2, 3}); Iterable<String> sstr = Sequence.fromArray(new String[]{"a", "b"}); List<String> res = ListSequence.fromList(new ArrayList<String>()); { Iterator<Integer> foo_it = Sequence.fromIterable(sint).iterator(); Iterator<String> bar_it = Sequence.fromIterable(sstr).iterator(); int foo_var; String bar_var; while (foo_it.hasNext() && bar_it.hasNext()) { foo_var = foo_it.next(); bar_var = bar_it.next(); ListSequence.fromList(res).addElement(bar_var + foo_var); } } Assert.assertEquals("a1b2", IterableUtils.join(ListSequence.fromList(res), "")); } public void test_iterate_wildcard() throws Exception { List<Foo> foos = ListSequence.fromListAndArray(new ArrayList<Foo>(), new Foo()); List<? extends Foo> subfoos = ListSequence.fromListAndArray(new ArrayList<Bar>(), new Bar()); List<Bar> bars = ListSequence.fromListAndArray(new ArrayList<Bar>(), new Bar()); List<? super Bar> superbars = ListSequence.fromListAndArray(new ArrayList<Foo>(), new Foo()); int i = 1; { Iterator<Foo> a_it = ListSequence.fromList(foos).iterator(); Iterator<Bar> b_it = ListSequence.fromList(bars).iterator(); Foo a_var; Bar b_var; while (a_it.hasNext() && b_it.hasNext()) { a_var = a_it.next(); b_var = b_it.next(); { Iterator<? extends Foo> sa_it = ListSequence.fromList(subfoos).iterator(); Iterator<? super Bar> sb_it = ListSequence.fromList(superbars).iterator(); Foo sa_var; Object sb_var; while (sa_it.hasNext() && sb_it.hasNext()) { sa_var = sa_it.next(); sb_var = sb_it.next(); i++; } } } } Assert.assertSame(2, i); } public MultiForeachTest_Test() { } }