public void TestBasicFunctionality()
        {
            var q = new PriorityQueue<int>();
            Assert.AreEqual(0, q.Count);
            Assert.AreEqual(0, q.Capacity);
            Assert.Throws<InvalidOperationException>(() => q.Peek());
            Assert.Throws<InvalidOperationException>(() => q.Dequeue());

            q.Enqueue(5);
            q.Enqueue(2);
            q.Enqueue(4);

            Assert.AreEqual(3, q.Count);
            Assert.IsTrue(q.Capacity >= 3);

            Assert.IsTrue(q.Contains(2));
            Assert.IsFalse(q.Contains(3));

            Assert.AreEqual(3, q.ToArray().Length);
            CollectionAssert.AreEqual(q.ToArray(), q);

            Assert.AreEqual(2, q.Peek());

            Assert.AreEqual(2, q.Dequeue());
            Assert.AreEqual(4, q.Dequeue());
            Assert.AreEqual(5, q.Dequeue());
        }
Beispiel #2
0
        public void Interfaces()
        {
            var pq = new PriorityQueue<int>(new int[] { 8, 4, 3, 1, 2 });
            var icoll = (System.Collections.ICollection)pq;

            var expected = new int[5];
            icoll.CopyTo(expected, 0);
            Assert.AreEqual(expected, pq.ToArray());
        }
Beispiel #3
0
        public void TestDuplication()
        {
            var numbers = new [] { -1, -1, -1, 1, 1, 2, 3, 9, 20, 15, 11 }.ToList();

            var queue = new PriorityQueue<int>(1, Comparer<int>.Create((x, y) => x - y));
            numbers.ForEach(queue.Offer);
            Assert.AreEqual(-1, queue.ToArray()[0]);

            queue = new PriorityQueue<int>(3, Comparer<int>.Create((x, y) => x - y));
            numbers.ForEach(queue.Offer);
            queue.ToList().ForEach(x => Assert.AreEqual(-1, x));

            queue = new PriorityQueue<int>(4, Comparer<int>.Create((x, y) => x - y));
            numbers.ForEach(queue.Offer);
            Assert.AreEqual(1, queue.OrderBy(x => x).Last());

            queue = new PriorityQueue<int>(100, Comparer<int>.Create((x, y) => x - y));
            numbers.ForEach(queue.Offer);
            Assert.AreEqual(20, queue.OrderBy(x => x).Last());
        }
Beispiel #4
0
        public void ToArrayTest()
        {
            PriorityQueue<int> queue = new PriorityQueue<int> { 12, 6, 3, 1, 0, 8 };
            int[] expected = { 0, 1, 6, 12, 3, 8 };

            int[] actual = queue.ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #5
0
 public void ToArrayTest([PexAssumeUnderTest]List<int> elemList)
 {
     PriorityQueue<int> queue = new PriorityQueue<int>(elemList);
     elemList.Sort();
     int[] actual = queue.ToArray();
     PexObserve.ValueForViewing<int[]>("Actual", queue.ToArray());
     CollectionAssert.AreEquivalent(elemList, queue);
 }
Beispiel #6
0
 public void GetEnumeratorTest([PexAssumeUnderTest]List<int> elemList)
 {
     PriorityQueue<int> actual = new PriorityQueue<int>(elemList, Strategy.Max);
     PexObserve.ValueForViewing<int[]>("Actual", actual.ToArray());
     //CollectionAssert.AreEqual(elemList.ToArray(), actual.ToArray());
 }