diff --git a/ICD.Common.Utils.Tests/RecursionUtilsTest.cs b/ICD.Common.Utils.Tests/RecursionUtilsTest.cs new file mode 100644 index 0000000..b788467 --- /dev/null +++ b/ICD.Common.Utils.Tests/RecursionUtilsTest.cs @@ -0,0 +1,40 @@ +using NUnit.Framework; +using System.Collections.Generic; +using System.Linq; + +namespace ICD.Common.Utils.Tests +{ + [TestFixture] + public sealed class RecursionUtilsTest + { + [Test] + public void BreadthFirstSearchTest() + { + IEnumerable GetChildren(int node) + { + switch (node) + { + case 1: + yield return 2; + yield return 3; + break; + + case 2: + yield return 4; + break; + + default: + yield break; + } + } + + int[] nodes = RecursionUtils.BreadthFirstSearch(1, GetChildren).ToArray(); + + Assert.AreEqual(4, nodes.Length); + Assert.AreEqual(1, nodes[0]); + Assert.AreEqual(2, nodes[1]); + Assert.AreEqual(3, nodes[2]); + Assert.AreEqual(4, nodes[3]); + } + } +}