mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
Fixing bug where breadth-first search was not returning desired result when root and destination are the same
This commit is contained in:
parent
6db084853e
commit
025400bf7e
2 changed files with 16 additions and 0 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue