コード例 #1
0
        public void CanThrowExceptionIfThereIsNothingToDequeue()
        {
            MyPseudoQueue ps = new MyPseudoQueue();

            ps.PseudoQueue();
            Assert.Throws <Exception>(() => ps.PseudoQueueDequeue());
        }
コード例 #2
0
        public void CanEnqueueOneNodeToPseudoQueue()
        {
            MyPseudoQueue <string> myPseudoQueue = new MyPseudoQueue <string>();
            Node <string>          node1         = new Node <string>("One");

            myPseudoQueue.Enqueue(node1);

            Assert.Equal("One", myPseudoQueue.Peek().Value);
        }
コード例 #3
0
        public void CanInstantiatePseudoQueue()
        {
            MyPseudoQueue ps = new MyPseudoQueue();

            ps.PseudoQueue();
            bool expected = ps.FirstStack.IsEmpty();

            Assert.True(expected);
        }
コード例 #4
0
        public void CanInsertNodeIntoAPseudoQueue()
        {
            MyPseudoQueue ps = new MyPseudoQueue();

            ps.PseudoQueue();
            ps.PseudoQueueEnqueue(23);
            int expected = ps.FirstStack.Top.Value;

            Assert.Equal(23, expected);
        }
コード例 #5
0
        public void DequeueWhileQueueIsEmptyWillReturnNull()
        {
            MyPseudoQueue <string> myPseudoQueue = new MyPseudoQueue <string>();
            Node <string>          node1         = new Node <string>("One");

            myPseudoQueue.Enqueue(node1);
            myPseudoQueue.Dequeue();
            Node <string> recoveredData = myPseudoQueue.Dequeue();

            Assert.Null(recoveredData);
        }
コード例 #6
0
        public void PseudoQueueIsEmptyAfterLastPop()
        {
            MyPseudoQueue ps = new MyPseudoQueue();

            ps.PseudoQueue();
            ps.PseudoQueueEnqueue(20);
            ps.PseudoQueueDequeue();
            bool actual = ps.FirstStack.IsEmpty();

            Assert.True(actual);
        }
コード例 #7
0
        public void CanDequeueASingleNodeValueFromPseudoQueue()
        {
            MyPseudoQueue ps = new MyPseudoQueue();

            ps.PseudoQueue();
            ps.PseudoQueueEnqueue(20);
            int expected = 20;
            int actual   = ps.PseudoQueueDequeue();

            Assert.Equal(actual, expected);
        }
コード例 #8
0
        public void CanEnqueueMultipleNodesToPseudoQueue()
        {
            MyPseudoQueue <string> myPseudoQueue = new MyPseudoQueue <string>();
            Node <string>          node1         = new Node <string>("One");
            Node <string>          node2         = new Node <string>("Two");
            Node <string>          node3         = new Node <string>("Three");

            myPseudoQueue.Enqueue(node1);
            myPseudoQueue.Enqueue(node2);
            myPseudoQueue.Enqueue(node3);

            Assert.Equal("Three", myPseudoQueue.Peek().Value);
        }
コード例 #9
0
        public void CanRecoverDataFromDequeuedNode()
        {
            MyPseudoQueue <string> myPseudoQueue = new MyPseudoQueue <string>();
            Node <string>          node1         = new Node <string>("One");
            Node <string>          node2         = new Node <string>("Two");
            Node <string>          node3         = new Node <string>("Three");

            myPseudoQueue.Enqueue(node1);
            myPseudoQueue.Enqueue(node2);
            myPseudoQueue.Enqueue(node3);
            Node <string> recoveredData = myPseudoQueue.Dequeue();

            Assert.Equal("Three", recoveredData.Value);
        }
コード例 #10
0
        public void CanDequeueFirstNodeValueFromPseudoQueueWithMultipleNodes()
        {
            MyPseudoQueue ps = new MyPseudoQueue();

            ps.PseudoQueue();
            ps.PseudoQueueEnqueue(5);
            ps.PseudoQueueEnqueue(10);
            ps.PseudoQueueEnqueue(15);
            ps.PseudoQueueEnqueue(20);
            int expected = 20;
            int actual   = ps.PseudoQueueDequeue();

            Assert.Equal(actual, expected);
        }
コード例 #11
0
        public void CanDequeueAllNodesFromPseudoQueue()
        {
            MyPseudoQueue <string> myPseudoQueue = new MyPseudoQueue <string>();
            Node <string>          node1         = new Node <string>("One");
            Node <string>          node2         = new Node <string>("Two");
            Node <string>          node3         = new Node <string>("Three");

            myPseudoQueue.Enqueue(node1);
            myPseudoQueue.Enqueue(node2);
            myPseudoQueue.Enqueue(node3);
            myPseudoQueue.Dequeue();
            myPseudoQueue.Dequeue();
            myPseudoQueue.Dequeue();

            Assert.Null(myPseudoQueue.Peek());
        }
コード例 #12
0
        public void CanInsertMulitpleNodesIntoAPseudoQueue()
        {
            MyPseudoQueue ps = new MyPseudoQueue();

            ps.PseudoQueue();
            ps.PseudoQueueEnqueue(20);
            ps.PseudoQueueEnqueue(15);
            ps.PseudoQueueEnqueue(10);
            ps.PseudoQueueEnqueue(5);
            int[] expected =
            {
                ps.FirstStack.Top.Next.Next.Next.Value,
                ps.FirstStack.Top.Next.Next.Value,
                ps.FirstStack.Top.Next.Value,
                ps.FirstStack.Top.Value
            };
            int[] actual = { 5, 10, 15, 20 };
            Assert.Equal(actual, expected);
        }
コード例 #13
0
        public void CanInstantiateEmptyPseudoQueue()
        {
            MyPseudoQueue <string> myPseudoQueue = new MyPseudoQueue <string>();

            Assert.Null(myPseudoQueue.Peek());
        }