package jetbrains.mps.baseLanguage.collections.unittest.simple_operations;

/*Generated by MPS */

import org.junit.jupiter.api.Test;
import jetbrains.mps.internal.collections.runtime.Sequence;
import java.util.Collections;
import org.junit.Assert;
import jetbrains.mps.internal.collections.runtime.NotNullWhereFilter;
import jetbrains.mps.baseLanguage.closures.runtime.YieldingIterator;

public class SelectNotNullOperation_Test {
  @Test
  public void test_EmptySequence() throws Exception {
    Iterable<Integer> intS = Sequence.fromIterable(Collections.<Integer>emptyList());

    Assert.assertTrue(Sequence.fromIterable(intS).where(new NotNullWhereFilter()).isEmpty());
  }
  @Test
  public void test_IntegerSequence() throws Exception {
    Iterable<Integer> intS = Sequence.fromClosure(() -> {
      return (Iterable<Integer>) () -> {
        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.__CP__ = 3;
                  this.yield((Integer) 20);
                  return true;
                case 3:
                  this.__CP__ = 1;
                  this.yield(null);
                  return true;
                case 0:
                  this.__CP__ = 2;
                  break;
                default:
                  break __loop__;
              }
            } while (true);
            return false;
          }
        };
      };
    });


    Assert.assertTrue(Sequence.fromIterable(intS).contains(20));
    Assert.assertTrue(Sequence.fromIterable(intS).contains(null));

    Iterable<Integer> intSNotNull = Sequence.fromIterable(intS).where(new NotNullWhereFilter());
    Assert.assertTrue(Sequence.fromIterable(intSNotNull).contains(20));
    Assert.assertFalse(Sequence.fromIterable(intSNotNull).contains(null));

    for (Integer i : Sequence.fromIterable(intS).where(new NotNullWhereFilter())) {
      Assert.assertTrue(i != null);
    }

  }
}
