Example #1
0
        public void DequeueTest()
        {
            // arrange
            var       queue    = new PriorityQueueLinkedList <int>();
            const int expected = 21;

            // act
            queue.Enqueue(21);
            queue.Enqueue(100);
            queue.Enqueue(3);

            queue.Dequeue();
            var result = queue.Dequeue();

            Assert.AreEqual(expected, result);

            // arrange
            var queue2 = new PriorityQueueBinaryTree <int>();

            // act
            queue2.Enqueue(21);
            queue2.Enqueue(100);
            queue2.Enqueue(3);

            queue2.Dequeue();
            result = queue2.Dequeue();

            Assert.AreEqual(expected, result);
        }
Example #2
0
        public void IsEmptyTestWithNoItems()
        {
            // arrange
            var queue = new PriorityQueueLinkedList <int>();

            Assert.IsTrue(queue.IsEmpty);

            // arrange
            var queue2 = new PriorityQueueBinaryTree <int>();

            Assert.IsTrue(queue2.IsEmpty);
        }
Example #3
0
        public void DequeueWithNoItemsShouldThrowException()
        {
            // arrange
            var queue = new PriorityQueueLinkedList <int>();

            // act
            queue.Dequeue();

            // arrange
            var queue2 = new PriorityQueueBinaryTree <int>();

            // act
            queue2.Dequeue();
        }
        public void Test()
        {
            var queue = new PriorityQueueLinkedList <int>();

            queue.Enqueue(1);
            queue.Enqueue(3);
            queue.Enqueue(5);
            Assert.AreEqual("531", queue.GetValues());

            queue.Enqueue(4);
            Assert.AreEqual("5431", queue.GetValues());

            Assert.AreEqual(5, queue.Dequeue());
            Assert.AreEqual("431", queue.GetValues());

            queue.Enqueue(0);
            Assert.AreEqual("4310", queue.GetValues());
        }
Example #5
0
        public void GivenAnArrayOfObjectsUnordered()
        {
            // arrange
            var queue = new PriorityQueueLinkedList <DummyStringComparer2>();

            var t1 = new DummyStringComparer2 {
                StringOfX = "xxx"
            };
            var t2 = new DummyStringComparer2 {
                StringOfX = "x"
            };
            var t3 = new DummyStringComparer2 {
                StringOfX = "xxxxx"
            };
            var t4 = new DummyStringComparer2 {
                StringOfX = "xx"
            };
            var t5 = new DummyStringComparer2 {
                StringOfX = "xxxx"
            };

            DummyStringComparer2[] expected = { t2, t4, t1, t5, t3 };
            queue.Enqueue(t1);
            queue.Enqueue(t2);
            queue.Enqueue(t3);
            queue.Enqueue(t4);
            queue.Enqueue(t5);

            // act/assert
            Assert.IsTrue(queue.ToArray().SequenceEqual(expected));

            // arrange
            var queue2 = new PriorityQueueBinaryTree <DummyStringComparer2>();

            queue2.Enqueue(t1);
            queue2.Enqueue(t2);
            queue2.Enqueue(t3);
            queue2.Enqueue(t4);
            queue2.Enqueue(t5);

            // act/assert
            Assert.IsTrue(queue2.ToArray().SequenceEqual(expected));
        }
Example #6
0
        public void GivenIntegersUnordered()
        {
            // arrange
            var queue    = new PriorityQueueLinkedList <int>();
            var expected = new[] { 3, 21, 100 };

            // act
            queue.Enqueue(3);
            queue.Enqueue(100);
            queue.Enqueue(21);

            Assert.IsTrue(queue.ToArray().SequenceEqual(expected));

            // arrange
            var queue2 = new PriorityQueueBinaryTree <int>();

            // act
            queue2.Enqueue(3);
            queue2.Enqueue(100);
            queue2.Enqueue(21);

            Assert.IsTrue(queue2.ToArray().SequenceEqual(expected));
        }