Ejemplo n.º 1
0
 public void Test_Constructor_ShouldSetCapacity()
 {
     var expectedCapacity = 4;
     this.priorityQueue = new PriorityQueue<char>(expectedCapacity);
     var actualCapacity = this.priorityQueue.Capacity;
     Assert.AreEqual(expectedCapacity, actualCapacity, "Constructor should set capacity to correctly.");
 }
        public void MinPriorityQueueShouldWorkCorrectly()
        {
            var queue = new PriorityQueue<int>(reversePriority: true);
            queue.Enqueue(5);
            queue.Enqueue(1);
            queue.Enqueue(18);
            queue.Enqueue(-9);

            Assert.AreEqual(-9, queue.Dequeue());
            Assert.AreEqual(1, queue.Dequeue());
            Assert.AreEqual(5, queue.Dequeue());
            Assert.AreEqual(18, queue.Dequeue());
        }
        public void MinPriorityQueueShouldWorkCorrectly()
        {
            var heap = new MinArrayHeap<int>();
            var queue = new PriorityQueue<int>(heap);
            queue.Enqueue(5);
            queue.Enqueue(1);
            queue.Enqueue(18);
            queue.Enqueue(-9);

            Assert.AreEqual(-9, queue.Dequeue());
            Assert.AreEqual(1, queue.Dequeue());
            Assert.AreEqual(5, queue.Dequeue());
            Assert.AreEqual(18, queue.Dequeue());
        }
        public void DefaultConstructorWithDefaultParametersShouldCreateMaxPriorityQueue()
        {
            var queue = new PriorityQueue<DateTime>();
            var dateA = new DateTime(2000, 1, 1);
            var dateB = new DateTime(2002, 1, 1);
            var dateC = new DateTime(1999, 1, 1);

            queue.Enqueue(dateA);
            queue.Enqueue(dateB);
            queue.Enqueue(dateC);

            Assert.AreEqual(dateB, queue.Dequeue());
            Assert.AreEqual(dateA, queue.Dequeue());
            Assert.AreEqual(dateC, queue.Dequeue());
        }
Ejemplo n.º 5
0
        public void Test_ComprarerParam_ShouldCompareProperly()
        {
            var comparer = new StringComparerDescending();
            var pq = new PriorityQueue<string>(comparer);
            int count = 100;
            var min = "zzzzzzzzzz";
            for (int i = 0; i < count; i++)
            {
                var randomString = this.GetRandomString(10);
                pq.Enqueue(randomString);
                if (min.CompareTo(randomString) > 0)
                {
                    min = randomString;
                }
            }

            for (int i = 0; i < count - 1; i++)
            {
                var dequeuedNumber = pq.Dequeue();
            }

            var actual = pq.Dequeue().ToString();
            Assert.AreEqual(min, actual, "Comparer param should work properly.");
        }
Ejemplo n.º 6
0
 public void Init()
 {
     this.priorityQueue = new PriorityQueue<char>();
 }
Ejemplo n.º 7
0
 public void Test_ToString_ShouldReturnCorrectString()
 {
     var pq = new PriorityQueue<int>();
     pq.Enqueue(52);
     pq.Enqueue(2);
     pq.Enqueue(1);
     pq.Enqueue(34);
     var expected = "1, 34, 2, 52\nCount: 4\nCapacity: 16\n----------------------";
     var actual = pq.ToString();
     Assert.AreEqual(expected, actual, "To string should return correct string");
 }
Ejemplo n.º 8
0
        public void Test_Dequeue_ShouldLeaveBiggestItemLast()
        {
            var pq = new PriorityQueue<int>();
            int count = 100000;
            var max = int.MinValue;
            for (int i = 0; i < count; i++)
            {
                var randomNumber = random.Next(0, count * 10);
                pq.Enqueue(randomNumber);
                if (max < randomNumber)
                {
                    max = randomNumber;
                }
            }

            for (int i = 0; i < count - 1; i++)
            {
                var dequeuedNumber = pq.Dequeue();
            }

            var actual = pq.Dequeue();
            Assert.AreEqual(max, actual, "Dequeue should leave biggest item last.");
        }