public void Enqueue_AddsRecordsInaTimelyFashion_WhenCalled(PriorityEventType firstEvent, PriorityEventType lastEvent, int numberOfIterations) { PriorityQueue <PriorityQueueDeviceEvents> testQueue = new PriorityQueue <PriorityQueueDeviceEvents>(); Random random = new Random(); Stopwatch sw = new Stopwatch(); sw.Start(); for (int index = 0; index < numberOfIterations; index++) { int randomEvent = random.Next((int)firstEvent, (int)lastEvent); if (Enum.IsDefined(typeof(PriorityEventType), randomEvent)) { PriorityQueueDeviceEvents priorityEvent = new PriorityQueueDeviceEvents((PriorityEventType)randomEvent, index); testQueue.Enqueue(priorityEvent); } } Assert.True(testQueue.Count() == numberOfIterations); for (int i = 0; i < numberOfIterations; i++) { _ = testQueue.Dequeue(); } sw.Stop(); Assert.True(testQueue.Count() == 0); Assert.True(sw.ElapsedMilliseconds < 1000); }
public void Enqueue_ReordersElementsByPriority_WhenCalled(PriorityEventType highPriority, PriorityEventType lowPriority) { PriorityQueue <PriorityQueueDeviceEvents> testQueue = new PriorityQueue <PriorityQueueDeviceEvents>(); PriorityQueueDeviceEvents hiPriorityEvent = new PriorityQueueDeviceEvents(highPriority, (int)highPriority); testQueue.Enqueue(hiPriorityEvent); PriorityQueueDeviceEvents lowPriorityEvent = new PriorityQueueDeviceEvents(lowPriority, (int)lowPriority); testQueue.Enqueue(lowPriorityEvent); PriorityQueueDeviceEvents head = testQueue.Peek(); Assert.Equal(hiPriorityEvent, head); }
public PriorityQueueDeviceEvents(PriorityEventType evenType, int priority) { this.eventType = evenType; this.Priority = priority; }