RecursionUtils tests

This commit is contained in:
Chris Cameron
2017-09-26 13:53:04 -04:00
parent f87470da41
commit cba949eb92

View File

@@ -1,4 +1,5 @@
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -7,10 +8,7 @@ namespace ICD.Common.Utils.Tests
[TestFixture] [TestFixture]
public sealed class RecursionUtilsTest public sealed class RecursionUtilsTest
{ {
[Test] private IEnumerable<int> Graph(int node)
public void BreadthFirstSearchTest()
{
IEnumerable<int> GetChildren(int node)
{ {
switch (node) switch (node)
{ {
@@ -28,7 +26,12 @@ namespace ICD.Common.Utils.Tests
} }
} }
int[] nodes = RecursionUtils.BreadthFirstSearch(1, GetChildren).ToArray(); [Test]
public void BreadthFirstSearchTest()
{
Assert.Throws<ArgumentNullException>(() => RecursionUtils.BreadthFirstSearch(1, null).ToArray());
int[] nodes = RecursionUtils.BreadthFirstSearch(1, Graph).ToArray();
Assert.AreEqual(4, nodes.Length); Assert.AreEqual(4, nodes.Length);
Assert.AreEqual(1, nodes[0]); Assert.AreEqual(1, nodes[0]);
@@ -36,5 +39,22 @@ namespace ICD.Common.Utils.Tests
Assert.AreEqual(3, nodes[2]); Assert.AreEqual(3, nodes[2]);
Assert.AreEqual(4, nodes[3]); Assert.AreEqual(4, nodes[3]);
} }
[Test]
public void BreadthFirstSearchPath()
{
Assert.Throws<ArgumentNullException>(() => 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<int> noPath = RecursionUtils.BreadthFirstSearchPath(3, 4, Graph);
Assert.IsNull(noPath);
}
} }
} }