public void SomeCanBeRemovedFromQueue() { var rand = new Random(42); const int count = 100000; var randoms = new List <int>(count); while (randoms.Count < count) { randoms.Add(rand.Next(1000)); } var distinct = randoms.Distinct().ToList(); var duplicateCount = count - distinct.Count; Assert.True(duplicateCount > 0); var queue = new RandomMeldablePriorityQueue <int>(); foreach (var r in randoms) { queue.Enqueue(r); } Assert.Equal(distinct.Count, queue.Count); const int toBeRemoved = 10; for (int i = 0; i < toBeRemoved; i++) { var item = distinct.Last(); distinct.RemoveAt(distinct.Count - 1); Assert.True(queue.Remove(item)); } var sorted = new List <int>(distinct.Count); for (int i = 0; i < distinct.Count; i++) { sorted.Add(queue.Dequeue()); } Assert.Equal(0, queue.Count); Assert.True(distinct.OrderBy(x => x).SequenceEqual(sorted)); }
public void SortsAMillion() { var rand = new Random(42); const int count = 1000000; var randoms = new HashSet <int>(); while (randoms.Count < count) { randoms.Add(rand.Next()); } var queue = new RandomMeldablePriorityQueue <int>(); foreach (var r in randoms) { queue.Enqueue(r); } Assert.Equal(count, queue.Count); var copy = new int[count]; queue.CopyTo(copy, 0); Assert.Equal(count, queue.Count); var sorted = new List <int>(count); for (int i = 0; i < count; i++) { sorted.Add(queue.Dequeue()); } Assert.Equal(0, queue.Count); Assert.True(randoms.OrderBy(x => x).SequenceEqual(sorted)); Assert.True(copy.SequenceEqual(sorted)); }