< Summary

Class:PriorityQueue[T]
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Utils/PriorityQueue.cs
Covered lines:33
Uncovered lines:3
Coverable lines:36
Total lines:57
Line coverage:91.6% (33 of 36)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:7
Method coverage:85.7% (6 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PriorityQueue()0%110100%
IsEmpty()0%110100%
Enqueue(...)0%220100%
Dequeue()0%330100%
Peek()0%220100%
GetEnumerator()0%550100%
GetEnumerator()0%2100%

File(s)

/github/workspace/Assets/Scripts/Utils/PriorityQueue.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Linq;
 4
 5// The priority queue dequeues elements in order of increasing priority.
 6public class PriorityQueue<T> : IEnumerable<T> {
 7  // Buffer containing the data.
 78  private SortedDictionary<float, Queue<T>> _buffer = new SortedDictionary<float, Queue<T>>();
 9
 10  // Return whether the priority queue is empty.
 1411  public bool IsEmpty() {
 1412    return _buffer.Count == 0;
 1413  }
 14
 15  // Enqueue an item.
 1716  public void Enqueue(T item, float priority) {
 3417    if (!_buffer.ContainsKey(priority)) {
 1718      _buffer[priority] = new Queue<T>();
 1719    }
 1720    _buffer[priority].Enqueue(item);
 1721  }
 22
 23  // Dequeue the item with the lowest priority value.
 524  public T Dequeue() {
 625    if (IsEmpty()) {
 126      throw new System.InvalidOperationException("The priority queue is empty.");
 27    }
 28
 429    var firstPair = _buffer.First();
 430    Queue<T> queue = firstPair.Value;
 431    T item = queue.Dequeue();
 832    if (queue.Count == 0) {
 433      _buffer.Remove(firstPair.Key);
 434    }
 435    return item;
 436  }
 37
 38  // Peek the item with the lowest priority value.
 239  public T Peek() {
 340    if (IsEmpty()) {
 141      throw new System.InvalidOperationException("The priority queue is empty.");
 42    }
 143    return _buffer.First().Value.Peek();
 144  }
 45
 46  // Return an enumerator for the priority queue.
 247  public IEnumerator<T> GetEnumerator() {
 3048    foreach (var pair in _buffer) {
 4849      foreach (var item in pair.Value) {
 850        yield return item;
 851      }
 852    }
 253  }
 054  IEnumerator IEnumerable.GetEnumerator() {
 055    return GetEnumerator();
 056  }
 57}