summaryrefslogtreecommitdiffstats
path: root/tests/PriorityQueue.Tests/PriorityQueueShould.cs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-05-02 14:58:01 -0500
committerToby Vincent <tobyv13@gmail.com>2021-05-02 15:02:02 -0500
commitb03ade8a3c2d94c1931d09f8d09b7865826a9743 (patch)
tree1339db9c7dd814de9ec898bd167d809b9a09c1be /tests/PriorityQueue.Tests/PriorityQueueShould.cs
parent1bd4f32d974674186900cec0897567419afe0b88 (diff)
removed CS340 namespace
Signed-off-by: Toby Vincent <tobyv13@gmail.com>
Diffstat (limited to 'tests/PriorityQueue.Tests/PriorityQueueShould.cs')
-rw-r--r--tests/PriorityQueue.Tests/PriorityQueueShould.cs84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/PriorityQueue.Tests/PriorityQueueShould.cs b/tests/PriorityQueue.Tests/PriorityQueueShould.cs
new file mode 100644
index 0000000..beafb41
--- /dev/null
+++ b/tests/PriorityQueue.Tests/PriorityQueueShould.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Xunit;
+
+namespace PriorityQueue.Tests
+{
+ using Node = Node<int>;
+ using Queue = PriorityQueue<Node<int>, int>;
+
+ public class CreatePriorityQueue
+ {
+ [Theory]
+ [InlineData(false, new int[] { 3, 14, 7, 9, 99, 2, 46 }, 4, 99)]
+ [InlineData(true, new int[] { 3, 14, 7, 9, 99, 2, 46 }, 5, 2)]
+ public void Insert_WhenArray_ShouldPQ(bool isMin, int[] input, int expectedId, int expectedkey)
+ {
+ // Arrange
+ int id = 0;
+ Queue priorityQueue = new Queue(input.Length, isMin);
+ Node expected = new Node(expectedId, expectedkey);
+
+ // Act
+ foreach (var key in input)
+ priorityQueue.Insert(new Node(id++, key));
+
+ // Assert
+ Assert.Equal(expected, priorityQueue.Peek());
+ }
+
+ [Theory]
+ [InlineData(false, new int[] { 3, 14, 7, 9, 99, 2, 46 })]
+ [InlineData(true, new int[] { 3, 14, 7, 9, 99, 2, 46 })]
+ public void Extract_WhenPG_ShouldReturnLargest(bool isMin, int[] input)
+ {
+ // Arrange
+ int id = 0;
+ Node curr, next;
+ List<Node> actual = new List<Node>();
+ Queue queue = new Queue(input.Length, isMin);
+
+ Func<Node, Node, bool> compare = (first, second) =>
+ first.CompareTo(second) * (isMin ? -1 : 1) >= 0;
+
+ // Act
+ foreach (var key in input)
+ queue.Insert(new Node(id++, key));
+
+ // Assert
+ while (!queue.IsEmpty())
+ Assert.True(compare(
+ curr = queue.Extract(),
+ next = queue.Peek()
+ ));
+ }
+
+ [Theory]
+ [InlineData(false, 4, 99)]
+ [InlineData(true, 5, 2)]
+ public void ChangeKey_GivenPQ_ShouldReorderPQ(bool isMin, int expectedId, int expectedkey)
+ {
+ // Arrange
+ int id = 0;
+ int[] array = new int[] { 3, 14, 7, 9, 99, 2, 46 };
+ List<Node> actual = new List<Node>();
+ Queue priorityQueue = new Queue(array.Length, isMin);
+ foreach (var key in array)
+ priorityQueue.Insert(new Node(id++, key));
+
+ // Act
+
+ // Assert
+ Node prev = priorityQueue.Extract();
+ while (!priorityQueue.IsEmpty())
+ actual.Add(priorityQueue.Extract());
+
+ foreach (Node node in actual)
+ Assert.True(prev.Key > (prev = node).Key);
+ }
+
+
+
+ }
+} \ No newline at end of file