public void TraverseBfs_ReturnsProperSequence_ForDirectedGraph([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, true); var result = new List <string>(); graph.TraverseBfs('A', node => { Assert.IsNotNull(node); result.Add($"{node.Parent?.Vertex}>{node.Vertex}"); return(true); }); Assert.AreEqual(expected, string.Join(",", result)); }
public void TraverseBfs_SelectsTheExpectedEdges_ForUndirectedGraph([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, false); var result = new List <string>(); graph.TraverseBfs('A', node => { Assert.IsNotNull(node); if (node.EntryEdge != null) { result.Add($"{node.EntryEdge}"); } return(true); }); Assert.AreEqual(expected, string.Join(",", result)); }
public void TraverseBfs_ThrowsException_ForNullCompletionHandler() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <ArgumentNullException>(() => graph.TraverseBfs('A', null)); }
public void TraverseBfs_ThrowsException_ForInvalidVertex() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <ArgumentException>(() => graph.TraverseBfs('Z', node => true)); }