< Summary

Class:PriorityQueueTest
Assembly:bamlab.test.editmode
File(s):/github/workspace/Assets/Tests/EditMode/PriorityQueueTest.cs
Covered lines:62
Uncovered lines:0
Coverable lines:62
Total lines:87
Line coverage:100% (62 of 62)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:7
Method coverage:100% (7 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TestIsEmpty()0%110100%
TestDequeueWhenEmpty()0%110100%
TestPeekWhenEmpty()0%110100%
TestPeek()0%110100%
TestPriority()0%220100%
TestEnumerator()0%220100%
TestIterator()0%330100%

File(s)

/github/workspace/Assets/Tests/EditMode/PriorityQueueTest.cs

#LineLine coverage
 1using NUnit.Framework;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7
 8public class PriorityQueueTest {
 9  [Test]
 110  public void TestIsEmpty() {
 111    PriorityQueue<float> queue = new PriorityQueue<float>();
 112    Assert.True(queue.IsEmpty());
 113    queue.Enqueue(item: 1.0f, priority: 1.0f);
 114    Assert.False(queue.IsEmpty());
 115  }
 16
 17  [Test]
 118  public void TestDequeueWhenEmpty() {
 119    PriorityQueue<float> queue = new PriorityQueue<float>();
 320    Assert.Throws<InvalidOperationException>(() => { queue.Dequeue(); });
 121  }
 22
 23  [Test]
 124  public void TestPeekWhenEmpty() {
 125    PriorityQueue<float> queue = new PriorityQueue<float>();
 326    Assert.Throws<InvalidOperationException>(() => { queue.Peek(); });
 127  }
 28
 29  [Test]
 130  public void TestPeek() {
 131    PriorityQueue<string> queue = new PriorityQueue<string>();
 132    queue.Enqueue(item: "a", priority: 3.0f);
 133    queue.Enqueue(item: "b", priority: 1.0f);
 134    queue.Enqueue(item: "c", priority: 5.0f);
 135    queue.Enqueue(item: "d", priority: 3.2f);
 136    Assert.AreEqual("b", queue.Peek());
 137  }
 38
 39  [Test]
 140  public void TestPriority() {
 141    PriorityQueue<string> queue = new PriorityQueue<string>();
 142    queue.Enqueue(item: "a", priority: 3.0f);
 143    queue.Enqueue(item: "b", priority: 1.0f);
 144    queue.Enqueue(item: "c", priority: 5.0f);
 145    queue.Enqueue(item: "d", priority: 3.2f);
 46
 147    List<string> expectedOrder = new List<string> { "b", "a", "d", "c" };
 148    int index = 0;
 949    while (!queue.IsEmpty()) {
 450      Assert.AreEqual(expectedOrder[index], queue.Dequeue());
 451      ++index;
 452    }
 153  }
 54
 55  [Test]
 156  public void TestEnumerator() {
 157    PriorityQueue<string> queue = new PriorityQueue<string>();
 158    queue.Enqueue(item: "a", priority: 3.0f);
 159    queue.Enqueue(item: "b", priority: 1.0f);
 160    queue.Enqueue(item: "c", priority: 5.0f);
 161    queue.Enqueue(item: "d", priority: 3.2f);
 62
 163    List<string> expectedOrder = new List<string> { "b", "a", "d", "c" };
 164    IEnumerator<string> enumerator = queue.GetEnumerator();
 165    int index = 0;
 966    while (enumerator.MoveNext()) {
 467      Assert.AreEqual(expectedOrder[index], enumerator.Current);
 468      ++index;
 469    }
 170  }
 71
 72  [Test]
 173  public void TestIterator() {
 174    PriorityQueue<string> queue = new PriorityQueue<string>();
 175    queue.Enqueue(item: "a", priority: 3.0f);
 176    queue.Enqueue(item: "b", priority: 1.0f);
 177    queue.Enqueue(item: "c", priority: 5.0f);
 178    queue.Enqueue(item: "d", priority: 3.2f);
 79
 180    List<string> expectedOrder = new List<string> { "b", "a", "d", "c" };
 181    int index = 0;
 1582    foreach (var item in queue) {
 483      Assert.AreEqual(expectedOrder[index], item);
 484      ++index;
 485    }
 186  }
 87}