add unit test for multiroute. fix long standing bugs with routing uncovered by said unit test.

This commit is contained in:
Jack Kanarish
2018-01-04 16:06:54 -05:00
parent 3a2f3b7526
commit 0a0cf3f720
2 changed files with 110 additions and 3 deletions

View File

@@ -92,7 +92,7 @@ namespace ICD.Common.Utils
// Found a path to the destination
if (comparer.Equals(node, destination))
return GetPath(destination, nodeParents).Reverse();
return GetPath(destination, root, nodeParents, comparer).Reverse();
}
}
@@ -166,7 +166,7 @@ namespace ICD.Common.Utils
destinationsToBeProcessed.Where(destination => comparer.Equals(closureNode, destination)))
{
destinationsProcessed.Add(destination);
pathsToReturn.Add(destination, GetPath(destination, nodeParents).Reverse());
pathsToReturn.Add(destination, GetPath(destination, root, nodeParents, comparer).Reverse().ToArray());
}
foreach (T destination in destinationsProcessed)
@@ -187,15 +187,20 @@ namespace ICD.Common.Utils
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="start"></param>
/// /// <param name="end"></param>
/// <param name="nodeParents"></param>
/// <returns></returns>
private static IEnumerable<T> GetPath<T>(T start, IDictionary<T, T> nodeParents)
private static IEnumerable<T> GetPath<T>(T start, T end, IDictionary<T, T> nodeParents, IEqualityComparer<T> comparer)
{
IcdHashSet<T> visited = new IcdHashSet<T>();
while (true)
{
yield return start;
if (comparer.Equals(start, end))
break;
visited.Add(start);
T next;