Ejemplo n.º 1
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.º 2
0
 public static void Main(string[] args)
 {
     var comparerDesc = new StringComparerDescending();
     var comparerAsc = new StringComparerAscending();
     var priorityQueue = new PriorityQueue<string>();
     priorityQueue.Enqueue("E");
     Console.WriteLine(priorityQueue);
     priorityQueue.Enqueue("B");
     Console.WriteLine(priorityQueue);
     priorityQueue.Enqueue("G");
     Console.WriteLine(priorityQueue);
     priorityQueue.Enqueue("Z");
     Console.WriteLine(priorityQueue);
     priorityQueue.Enqueue("M");
     Console.WriteLine(priorityQueue);
     priorityQueue.Enqueue("D");
     Console.WriteLine(priorityQueue);
     priorityQueue.Enqueue("A");
     Console.WriteLine(priorityQueue);
     priorityQueue.Dequeue();
     Console.WriteLine(priorityQueue);
     priorityQueue.Dequeue();
     Console.WriteLine(priorityQueue);
     priorityQueue.Dequeue();
     Console.WriteLine(priorityQueue);
     priorityQueue.Dequeue();
     Console.WriteLine(priorityQueue);
     priorityQueue.Dequeue();
     Console.WriteLine(priorityQueue);
     priorityQueue.Dequeue();
     Console.WriteLine(priorityQueue);
     priorityQueue.Dequeue();
     Console.WriteLine(priorityQueue);
 }
Ejemplo n.º 3
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.");
        }