public bool DoTest() { Random random = new Random(Guid.NewGuid().GetHashCode()); List <int> nums = new List <int>(); for (int i = 0; i < INIT_NUM; i++) { nums.Add(random.Next(NUM_RANGE)); } MinPriorityQueue <int> testPq = new MinPriorityQueue <int>(nums.GetEnumerator()); for (int i = 0; i < INSERT_NUM; i++) { testPq.Insert(random.Next(NUM_RANGE)); } List <int> orginNums = new List <int>(); List <int> sortedNums = new List <int>(); while (!testPq.IsEmpty()) { int top = testPq.DelTop(); orginNums.Add(top); sortedNums.Add(top); } sortedNums.Sort(); for (int i = 0; i < orginNums.Count; i++) { if (orginNums[i] != sortedNums[i]) { return(false); } } return(true); }
public void MinPQ_Basic() { var pq = new MinPriorityQueue <int>(); pq.Insert(2, null); pq.Insert(6, null); pq.Insert(1, null); Assert.AreEqual(1, (int)(pq.DelTop().Item1)); pq.Insert(9, null); pq.Insert(7, null); pq.Insert(1, null); Assert.AreEqual(1, (int)(pq.DelTop().Item1)); pq.Insert(2, null); pq.Insert(6, null); pq.Insert(1, null); Assert.AreEqual(1, (int)(pq.DelTop().Item1)); Assert.AreEqual(2, (int)(pq.Top().Item1)); Assert.AreEqual(2, (int)(pq.DelTop().Item1)); Assert.AreEqual(2, (int)(pq.DelTop().Item1)); Assert.AreEqual(6, (int)(pq.DelTop().Item1)); }