Exemple #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);
        }
Exemple #2
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));
        }
Exemple #3
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));
        }
Exemple #4
0
        public void IsEmptyTestWithItems()
        {
            // arrange
            var queue = new PriorityQueueLinkedList <int>();

            // act
            queue.Enqueue(1);

            Assert.IsFalse(queue.IsEmpty);

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

            // act
            queue2.Enqueue(1);

            Assert.IsFalse(queue2.IsEmpty);
        }