mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-07 16:55:08 +00:00
Merge branch 'dev' of https://cs-gogs.icdpf.net/Common/Utils into dev
This commit is contained in:
@@ -6,8 +6,8 @@ using System.Linq;
|
||||
namespace ICD.Common.Utils.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public sealed class RecursionUtilsTest
|
||||
{
|
||||
public sealed class RecursionUtilsTest
|
||||
{
|
||||
private IEnumerable<int> Graph(int node)
|
||||
{
|
||||
switch (node)
|
||||
@@ -41,7 +41,7 @@ namespace ICD.Common.Utils.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BreadthFirstSearchPath()
|
||||
public void BreadthFirstSearchPathTest()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => RecursionUtils.BreadthFirstSearchPath(1, 4, null).ToArray());
|
||||
|
||||
@@ -56,5 +56,17 @@ namespace ICD.Common.Utils.Tests
|
||||
|
||||
Assert.IsNull(noPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test to ensure that when start and end node are the same, breadth first search returns that single node.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void BreadthFirstSearchPathSingleNodeTest()
|
||||
{
|
||||
int[] path = RecursionUtils.BreadthFirstSearchPath(1, 1, Graph).ToArray();
|
||||
|
||||
Assert.AreEqual(1, path.Length);
|
||||
Assert.AreEqual(1, path[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,10 @@ namespace ICD.Common.Utils
|
||||
if (comparer == null)
|
||||
throw new ArgumentNullException("comparer");
|
||||
|
||||
// Edge case - root and destination are the same
|
||||
if (comparer.Equals(root, destination))
|
||||
return new[] {root};
|
||||
|
||||
Queue<T> queue = new Queue<T>();
|
||||
queue.Enqueue(root);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user