package jetbrains.mps.internalCollections.test.compareOperations;

/*Generated by MPS */

import jetbrains.mps.internalCollections.test.closures.Util_Test;
import org.junit.jupiter.api.Test;
import jetbrains.mps.internal.collections.runtime.ISequence;
import jetbrains.mps.internal.collections.runtime.Sequence;
import java.util.Arrays;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import java.util.Iterator;
import org.junit.Assert;
import java.util.NoSuchElementException;

public class Concat_Test extends Util_Test {
  @Test
  public void test_concatMethod() throws Exception {
    ISequence<Integer> input = Sequence.fromArray(1, 2, 3);
    ISequence<Integer> test = input.concat(Sequence.fromArray(4, 5, 6));
    this.assertIterableEquals(Arrays.asList(1, 2, 3, 4, 5, 6), test);
  }
  @Test
  public void test_concatOperation() throws Exception {
    Iterable<Integer> input = this.input5();
    Iterable<Integer> test = Sequence.fromIterable(input).concat(ListSequence.fromList(Arrays.asList(6, 7, 8, 9, 10)));
    this.assertIterableEquals(this.expect10(), test);
  }
  @Test
  public void test_concatOpCovariant() throws Exception {
    Foo foo1 = new Foo();
    Foo foo2 = new Foo();
    Bar bar1 = new Bar();
    Iterable<Foo> head = ListSequence.fromListAndArray(new ArrayList<Foo>(), foo1, foo2);
    Iterable<Bar> tail = Sequence.<Bar>singleton(bar1);
    Iterable<Foo> res = Sequence.fromIterable(head).concat(Sequence.fromIterable(tail));
    assertIterableEquals(Sequence.fromArray(new Foo[]{foo1, foo2, bar1}), res);
  }
  @Test
  public void test_nextWithoutHasNext() throws Exception {
    Iterator<Integer> it = ListSequence.fromList(ListSequence.fromListAndArray(new ArrayList<Integer>(), 1, 2, 3)).concat(ListSequence.fromList(ListSequence.fromListAndArray(new ArrayList<Integer>(), 4, 5))).iterator();
    Assert.assertSame(1, it.next());
    Assert.assertSame(2, it.next());
    Assert.assertSame(3, it.next());
    Assert.assertSame(4, it.next());
    Assert.assertSame(5, it.next());
    Assert.assertFalse(it.hasNext());
    try {
      it.next();
      Assert.fail();
    } catch (NoSuchElementException e) {
      // expected exception
    }
  }
}
