package jetbrains.mps.internalCollections.test.basicOperations;

/*Generated by MPS */

import org.junit.jupiter.api.Test;
import java.util.Queue;
import jetbrains.mps.internal.collections.runtime.QueueSequence;
import java.util.LinkedList;
import org.junit.Assert;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Deque;
import jetbrains.mps.internal.collections.runtime.DequeSequence;

public class QueueDequeStack_Test {
  @Test
  public void test_queue() throws Exception {
    Queue<Integer> q = QueueSequence.fromQueue(new LinkedList<Integer>());
    QueueSequence.fromQueue(q).addLastElement(1);
    QueueSequence.fromQueue(q).addLastElement(2);
    QueueSequence.fromQueue(q).addLastElement(3);
    Queue<Integer> q2 = QueueSequence.fromQueueAndArray(new LinkedList<Integer>(), 1, 2, 3);
    Assert.assertTrue(Objects.equals(q, q2));
    Assert.assertSame(1, QueueSequence.fromQueue(q).first());
    Assert.assertSame(1, QueueSequence.fromQueue(q).removeFirstElement());
    Assert.assertSame(2, QueueSequence.fromQueue(q).first());
    Assert.assertSame(3, QueueSequence.fromQueue(q).last());
    Assert.assertSame(2, QueueSequence.fromQueue(q).removeFirstElement());
    Assert.assertSame(3, QueueSequence.fromQueue(q).removeFirstElement());
    Assert.assertTrue(QueueSequence.fromQueue(q).isEmpty());
  }
  @Test
  public void test_priorityQueue() throws Exception {
    Queue<Integer> q = QueueSequence.fromQueue(new PriorityQueue<Integer>());
    QueueSequence.fromQueue(q).addLastElement(3);
    QueueSequence.fromQueue(q).addLastElement(2);
    QueueSequence.fromQueue(q).addLastElement(1);
    Assert.assertSame(1, QueueSequence.fromQueue(q).first());
    Assert.assertSame(1, QueueSequence.fromQueue(q).removeFirstElement());
    Assert.assertSame(2, QueueSequence.fromQueue(q).first());
    Assert.assertSame(3, QueueSequence.fromQueue(q).last());
    Assert.assertSame(2, QueueSequence.fromQueue(q).removeFirstElement());
    Assert.assertSame(3, QueueSequence.fromQueue(q).removeFirstElement());
    Assert.assertTrue(QueueSequence.fromQueue(q).isEmpty());
  }
  @Test
  public void test_stack() throws Exception {
    Deque<Integer> s = DequeSequence.fromDeque(new LinkedList<Integer>());
    DequeSequence.fromDequeNew(s).addFirstElement(1);
    DequeSequence.fromDequeNew(s).addFirstElement(2);
    DequeSequence.fromDequeNew(s).addFirstElement(3);
    Assert.assertSame(3, DequeSequence.fromDequeNew(s).first());
    Assert.assertSame(3, DequeSequence.fromDequeNew(s).removeFirstElement());
    Assert.assertSame(2, DequeSequence.fromDequeNew(s).first());
    Assert.assertSame(1, DequeSequence.fromDequeNew(s).last());
    Assert.assertSame(2, DequeSequence.fromDequeNew(s).removeFirstElement());
    Assert.assertSame(1, DequeSequence.fromDequeNew(s).removeFirstElement());
    Assert.assertTrue(DequeSequence.fromDequeNew(s).isEmpty());
  }
  @Test
  public void test_stackClassic() throws Exception {
    Deque<Integer> s = DequeSequence.fromDeque(new LinkedList<Integer>());
    DequeSequence.fromDequeNew(s).pushElement(1);
    DequeSequence.fromDequeNew(s).pushElement(2);
    DequeSequence.fromDequeNew(s).pushElement(3);
    Assert.assertSame(3, DequeSequence.fromDequeNew(s).first());
    Assert.assertSame(3, DequeSequence.fromDequeNew(s).peekElement());
    Assert.assertSame(3, DequeSequence.fromDequeNew(s).popElement());
    Assert.assertSame(2, DequeSequence.fromDequeNew(s).first());
    Assert.assertSame(2, DequeSequence.fromDequeNew(s).peekElement());
    Assert.assertSame(1, DequeSequence.fromDequeNew(s).last());
    Assert.assertSame(2, DequeSequence.fromDequeNew(s).popElement());
    Assert.assertSame(1, DequeSequence.fromDequeNew(s).popElement());
    Assert.assertTrue(DequeSequence.fromDequeNew(s).isEmpty());
  }
  @Test
  public void test_deque() throws Exception {
    Deque<Integer> d = DequeSequence.fromDeque(new LinkedList<Integer>());
    DequeSequence.fromDequeNew(d).addFirstElement(1);
    DequeSequence.fromDequeNew(d).addFirstElement(2);
    DequeSequence.fromDequeNew(d).addFirstElement(3);
    Assert.assertSame(3, DequeSequence.fromDequeNew(d).first());
    Assert.assertSame(3, DequeSequence.fromDequeNew(d).removeFirstElement());
    DequeSequence.fromDequeNew(d).addLastElement(4);
    DequeSequence.fromDequeNew(d).addLastElement(5);
    DequeSequence.fromDequeNew(d).addLastElement(6);
    Assert.assertSame(2, DequeSequence.fromDequeNew(d).first());
    Assert.assertSame(2, DequeSequence.fromDequeNew(d).peekElement());
    Assert.assertSame(6, DequeSequence.fromDequeNew(d).last());
    Assert.assertSame(6, DequeSequence.fromDequeNew(d).removeLastElement());
    Assert.assertSame(2, DequeSequence.fromDequeNew(d).removeFirstElement());
    Assert.assertSame(1, DequeSequence.fromDequeNew(d).first());
    Assert.assertSame(1, DequeSequence.fromDequeNew(d).peekElement());
    Assert.assertSame(1, DequeSequence.fromDequeNew(d).removeFirstElement());
    Assert.assertSame(4, DequeSequence.fromDequeNew(d).first());
    Assert.assertSame(4, DequeSequence.fromDequeNew(d).peekElement());
    Assert.assertSame(4, DequeSequence.fromDequeNew(d).removeFirstElement());
    Assert.assertSame(5, DequeSequence.fromDequeNew(d).last());
    Assert.assertSame(5, DequeSequence.fromDequeNew(d).removeLastElement());
    Assert.assertTrue(DequeSequence.fromDequeNew(d).isEmpty());
  }
}
