< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TestIsEmpty()0%2100%
TestDequeueWhenEmpty()0%2100%
TestPeekWhenEmpty()0%2100%
TestPeek()0%2100%
TestPriority()0%6200%
TestEnumerator()0%6200%
TestIterator()0%12300%

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]
 010  public void TestIsEmpty() {
 011    PriorityQueue<float> queue = new PriorityQueue<float>();
 012    Assert.True(queue.IsEmpty());
 013    queue.Enqueue(item: 1.0f, priority: 1.0f);
 014    Assert.False(queue.IsEmpty());
 015  }
 16
 17  [Test]
 018  public void TestDequeueWhenEmpty() {
 019    PriorityQueue<float> queue = new PriorityQueue<float>();
 020    Assert.Throws<InvalidOperationException>(() => { queue.Dequeue(); });
 021  }
 22
 23  [Test]
 024  public void TestPeekWhenEmpty() {
 025    PriorityQueue<float> queue = new PriorityQueue<float>();
 026    Assert.Throws<InvalidOperationException>(() => { queue.Peek(); });
 027  }
 28
 29  [Test]
 030  public void TestPeek() {
 031    PriorityQueue<string> queue = new PriorityQueue<string>();
 032    queue.Enqueue(item: "a", priority: 3.0f);
 033    queue.Enqueue(item: "b", priority: 1.0f);
 034    queue.Enqueue(item: "c", priority: 5.0f);
 035    queue.Enqueue(item: "d", priority: 3.2f);
 036    Assert.AreEqual("b", queue.Peek());
 037  }
 38
 39  [Test]
 040  public void TestPriority() {
 041    PriorityQueue<string> queue = new PriorityQueue<string>();
 042    queue.Enqueue(item: "a", priority: 3.0f);
 043    queue.Enqueue(item: "b", priority: 1.0f);
 044    queue.Enqueue(item: "c", priority: 5.0f);
 045    queue.Enqueue(item: "d", priority: 3.2f);
 46
 047    List<string> expectedOrder = new List<string> { "b", "a", "d", "c" };
 048    int index = 0;
 049    while (!queue.IsEmpty()) {
 050      Assert.AreEqual(expectedOrder[index], queue.Dequeue());
 051      ++index;
 052    }
 053  }
 54
 55  [Test]
 056  public void TestEnumerator() {
 057    PriorityQueue<string> queue = new PriorityQueue<string>();
 058    queue.Enqueue(item: "a", priority: 3.0f);
 059    queue.Enqueue(item: "b", priority: 1.0f);
 060    queue.Enqueue(item: "c", priority: 5.0f);
 061    queue.Enqueue(item: "d", priority: 3.2f);
 62
 063    List<string> expectedOrder = new List<string> { "b", "a", "d", "c" };
 064    IEnumerator<string> enumerator = queue.GetEnumerator();
 065    int index = 0;
 066    while (enumerator.MoveNext()) {
 067      Assert.AreEqual(expectedOrder[index], enumerator.Current);
 068      ++index;
 069    }
 070  }
 71
 72  [Test]
 073  public void TestIterator() {
 074    PriorityQueue<string> queue = new PriorityQueue<string>();
 075    queue.Enqueue(item: "a", priority: 3.0f);
 076    queue.Enqueue(item: "b", priority: 1.0f);
 077    queue.Enqueue(item: "c", priority: 5.0f);
 078    queue.Enqueue(item: "d", priority: 3.2f);
 79
 080    List<string> expectedOrder = new List<string> { "b", "a", "d", "c" };
 081    int index = 0;
 082    foreach (var item in queue) {
 083      Assert.AreEqual(expectedOrder[index], item);
 084      ++index;
 085    }
 086  }
 87}