diff --git a/ICD.Common.Utils.Tests/RecursionUtilsTest.cs b/ICD.Common.Utils.Tests/RecursionUtilsTest.cs index b788467..6531077 100644 --- a/ICD.Common.Utils.Tests/RecursionUtilsTest.cs +++ b/ICD.Common.Utils.Tests/RecursionUtilsTest.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using System; using System.Collections.Generic; using System.Linq; @@ -7,28 +8,30 @@ namespace ICD.Common.Utils.Tests [TestFixture] public sealed class RecursionUtilsTest { + private IEnumerable Graph(int node) + { + switch (node) + { + case 1: + yield return 2; + yield return 3; + break; + + case 2: + yield return 4; + break; + + default: + yield break; + } + } + [Test] public void BreadthFirstSearchTest() { - IEnumerable GetChildren(int node) - { - switch (node) - { - case 1: - yield return 2; - yield return 3; - break; + Assert.Throws(() => RecursionUtils.BreadthFirstSearch(1, null).ToArray()); - case 2: - yield return 4; - break; - - default: - yield break; - } - } - - int[] nodes = RecursionUtils.BreadthFirstSearch(1, GetChildren).ToArray(); + int[] nodes = RecursionUtils.BreadthFirstSearch(1, Graph).ToArray(); Assert.AreEqual(4, nodes.Length); Assert.AreEqual(1, nodes[0]); @@ -36,5 +39,22 @@ namespace ICD.Common.Utils.Tests Assert.AreEqual(3, nodes[2]); Assert.AreEqual(4, nodes[3]); } + + [Test] + public void BreadthFirstSearchPath() + { + Assert.Throws(() => RecursionUtils.BreadthFirstSearchPath(1, 4, null).ToArray()); + + int[] path = RecursionUtils.BreadthFirstSearchPath(1, 4, Graph).ToArray(); + + Assert.AreEqual(3, path.Length); + Assert.AreEqual(1, path[0]); + Assert.AreEqual(2, path[1]); + Assert.AreEqual(4, path[2]); + + IEnumerable noPath = RecursionUtils.BreadthFirstSearchPath(3, 4, Graph); + + Assert.IsNull(noPath); + } } }