summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-04-20 02:28:41 +0000
committerToby Vincent <tobyv13@gmail.com>2021-04-20 02:28:41 +0000
commit808d90dba6b9c4a47a8c80acc03e75046960c688 (patch)
tree07f3915d5fe1475a68d46a801dcdc56219b96a7a /tests
parentcf192cef8e969c00b6d243f76e5a20b326ec59e1 (diff)
more work
Diffstat (limited to 'tests')
-rw-r--r--tests/CS340.PriorityQueue.Tests/CS340.PriorityQueue.Tests.csproj27
-rw-r--r--tests/CS340.PriorityQueue.Tests/PriorityQueueShould.cs84
2 files changed, 111 insertions, 0 deletions
diff --git a/tests/CS340.PriorityQueue.Tests/CS340.PriorityQueue.Tests.csproj b/tests/CS340.PriorityQueue.Tests/CS340.PriorityQueue.Tests.csproj
new file mode 100644
index 0000000..9c9f613
--- /dev/null
+++ b/tests/CS340.PriorityQueue.Tests/CS340.PriorityQueue.Tests.csproj
@@ -0,0 +1,27 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net5.0</TargetFramework>
+
+ <IsPackable>false</IsPackable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
+ <PackageReference Include="xunit" Version="2.4.1" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
+ <PackageReference Include="coverlet.collector" Version="1.3.0">
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\CS340.PriorityQueue\CS340.PriorityQueue.csproj" />
+ <ProjectReference Include="..\..\src\CS340.Interfaces\CS340.Interfaces.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/tests/CS340.PriorityQueue.Tests/PriorityQueueShould.cs b/tests/CS340.PriorityQueue.Tests/PriorityQueueShould.cs
new file mode 100644
index 0000000..beafb41
--- /dev/null
+++ b/tests/CS340.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