-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Ts-Pytham/GenericCollecti…
- Loading branch information
Showing
7 changed files
with
248 additions
and
22 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
GenericCollectionsExtension.Tests/Stack/PriorityStackTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
namespace GenericCollectionsExtension.Tests.Stack; | ||
|
||
public class PriorityStackTests | ||
{ | ||
[Fact] | ||
public void CapacityLessThanZero() | ||
{ | ||
Assert.Throws<ArgumentOutOfRangeException>(() => | ||
{ | ||
var stack = new PriorityStack<int>(-1); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void CapacityGreaterThanZero() | ||
{ | ||
Action test = () => | ||
{ | ||
var stack = new PriorityStack<int>(1); | ||
}; | ||
|
||
Assert.IsType<Action>(test); | ||
} | ||
|
||
[InlineData(new[] { "ho", "la", "ma" }, new[] { 1, 10, 2 }, "la")] | ||
[InlineData(new[] { "Pytham", "MrDave", "Holly" }, new[] { 20, 10, 50 }, "Holly")] | ||
[InlineData(new[] { "Do", "Re", "Mi" }, new[] { 0, 0, 0 }, "Mi")] | ||
public void CheckPriority(string[] items, int[] priority, string value) | ||
{ | ||
int len = items.Length; | ||
var stack = new PriorityStack<string>(); | ||
|
||
for (int i = 0; i != len; ++i) | ||
{ | ||
stack.Push(items[i], priority[i]); | ||
} | ||
|
||
Assert.Equal(value, stack.Peek()); | ||
} | ||
|
||
[Fact] | ||
public void PriorityNegative() | ||
{ | ||
var stack = new PriorityStack<string>(); | ||
|
||
var test = () => | ||
{ | ||
stack.Push("Hello", -1); | ||
}; | ||
|
||
Assert.Throws<NegativeNumberException>(test); | ||
} | ||
|
||
[Theory] | ||
[InlineData(new[] { 10f, 0f, 3f }, new[] { 0, 0, 0}, 3f)] | ||
[InlineData(new[] { 20f, 3.5f, 2.99f }, new[] { 50, 10, 0 }, 20f)] | ||
[InlineData(new[] { 1.11f, 2.53f, 3.1415f }, new[] { 10, 20, 5 }, 2.53f)] | ||
[InlineData(new[] { 1.1f, 3f, -0.5f }, new[] { 47, 0, 65 }, -0.5f)] | ||
public void Pop(float[] items, int[] priority, float pop) | ||
{ | ||
int len = items.Length; | ||
var stack = new PriorityStack<float>(); | ||
|
||
for (int i = 0; i != len; ++i) | ||
{ | ||
stack.Push(items[i], priority[i]); | ||
} | ||
|
||
Assert.True(stack.Pop() == pop); | ||
Assert.True(stack.Count == len - 1); | ||
} | ||
|
||
[Theory] | ||
[InlineData(new[] { 10f, 0f, 3f }, new[] { 0, 0, 0 }, 3f)] | ||
[InlineData(new[] { 20f, 3.5f, 2.99f }, new[] { 50, 10, 0 }, 20f)] | ||
[InlineData(new[] { 1.11f, 2.53f, 3.1415f }, new[] { 10, 20, 5 }, 2.53f)] | ||
[InlineData(new[] { 1.1f, 3f, -0.5f }, new[] { 47, 0, 65 }, -0.5f)] | ||
public void Peek(float[] items, int[] priority, float peek) | ||
{ | ||
int len = items.Length; | ||
var stack = new PriorityStack<float>(); | ||
|
||
for (int i = 0; i != len; ++i) | ||
{ | ||
stack.Push(items[i], priority[i]); | ||
} | ||
|
||
Assert.True(stack.Peek() == peek); | ||
Assert.True(stack.Count == len); | ||
} | ||
|
||
[Theory] | ||
[InlineData(new[] { 10f, 0f, 3f }, new[] { 0, 0, 0 }, 3f)] | ||
[InlineData(new[] { 20f, 3.5f, 2.99f }, new[] { 50, 10, 0 }, 20f)] | ||
[InlineData(new[] { 1.11f, 2.53f, 3.1415f }, new[] { 10, 20, 5 }, 2.53f)] | ||
[InlineData(new[] { 1.1f, 3f, -0.5f }, new[] { 47, 0, 65 }, -0.5f)] | ||
public void TryPeek(float[] items, int[] priority, float peek) | ||
{ | ||
int len = items.Length; | ||
var stack = new PriorityStack<float>(); | ||
|
||
for (int i = 0; i != len; ++i) | ||
{ | ||
stack.Push(items[i], priority[i]); | ||
} | ||
Assert.True(stack.TryPeek(out float result)); | ||
Assert.True(peek == result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
global using GenericCollectionsExtension.Exceptions; | ||
global using GenericCollectionsExtension.Queue; | ||
global using GenericCollectionsExtension.Stack; | ||
global using GenericCollectionsExtension.List; | ||
global using GenericCollectionsExtension.Tree; | ||
global using Xunit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.