public void CanQueue()
        {
            Node node = new Node(1);

            queuesWithStacks.Classes.Queue queue = new queuesWithStacks.Classes.Queue(node);
            Assert.Equal(queue.Peek(), node);
        }
        public void CanEnqueueNode()
        {
            Node node         = new Node(9);
            Node enqueuedNode = new Node(8);

            queuesWithStacks.Classes.Queue queue = new queuesWithStacks.Classes.Queue(node);
            queue.Enqueue(enqueuedNode);
            Assert.Equal(queue.Peek(), node);
        }
        public void CanPeek()
        {
            Node nodeOne = new Node(3);
            Node nodeTwo = new Node(2);

            queuesWithStacks.Classes.Queue queue = new queuesWithStacks.Classes.Queue(nodeOne);
            queue.Enqueue(nodeTwo);

            Assert.Equal(queue.Peek(), nodeOne);
        }
Example #4
0
        static void Queued()
        {
            Classes.Queue queue = new Classes.Queue(new Node(1));
            queue.Enqueue(new Node(2));
            queue.Enqueue(new Node(3));
            queue.Enqueue(new Node(4));

            Console.WriteLine("================= Queue ================");
            Console.WriteLine($"Node dequeued: {queue.Dequeue().Value}");
            Console.WriteLine($"Node dequeued: {queue.Dequeue().Value}");
            Console.WriteLine($"Node dequeued: {queue.Dequeue().Value}");
            Console.WriteLine($"Node dequeued: {queue.Dequeue().Value}");
        }
        public void CanGetNodeFromDequeue(int[] nodes, int expected, int times)
        {
            queuesWithStacks.Classes.Queue queue = new queuesWithStacks.Classes.Queue(new Node(nodes[0]));

            for (int i = 1; i < nodes.Length; i++)
            {
                queue.Enqueue(new Node(nodes[i]));
            }

            for (int i = 1; i < times; i++)
            {
                queue.Dequeue();
            }

            Assert.Equal(expected, (int)queue.Dequeue().Value);
        }
        public void NodeOrderRemainsAfterBeingDequeued(int[] nodes, int[] expected)
        {
            queuesWithStacks.Classes.Queue queue = new queuesWithStacks.Classes.Queue(new Node(nodes[0]));
            int[] arr = new int[nodes.Length];

            for (int i = 1; i < nodes.Length; i++)
            {
                queue.Enqueue(new Node(nodes[i]));
            }

            for (int i = 0; i < nodes.Length; i++)
            {
                arr[i] = (int)queue.Dequeue().Value;
            }

            Assert.Equal(expected, arr);
        }