public void Preserves_MultipleEdges_ForDirectedGraphs() { var graph = new LiteralGraph("A>1>A,A>2>B,A>1>B", true); var edgesFromA = string.Join(",", graph.GetEdges('A').Select(s => s.FromVertex + ">" + s.ToVertex)); Assert.AreEqual("A>A,A>B,A>B", edgesFromA); }
public void VerifyIsBipartite_ReturnsExpectedResult([NotNull] string relationships, bool expected) { var graph = new LiteralGraph(relationships, false); var actual = graph.IsBipartite; Assert.AreEqual(expected, actual); }
public void Ctor_AcceptsUnconnectedVertices() { var graph = new LiteralGraph("A,B,C-6-D", true); TestHelper.AssertSequence(graph.GetEdges('A')); TestHelper.AssertSequence(graph.GetEdges('B')); }
public void FindAllArticulationVertices_FindsArticulationsForUndirectedGraphs([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, false); var actual = string.Join(",", graph.FindAllArticulationVertices()); Assert.AreEqual(expected, actual); }
public void FindCheapestPath_FindsTheProperPath_ForDirectedGraphs([NotNull] string relationships, char from, char to, string expected) { var graph = new LiteralGraph(relationships, true); var actual = string.Join(",", graph.FindCheapestPath(from, to)); Assert.AreEqual(expected, actual); }
public void TopologicalSort_AlignsTheVerticesAsExpected([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, true); var result = graph.TopologicalSort().ToList(); var actual = string.Join(",", result); Assert.AreEqual(expected, actual); }
public void Graph_DescribeVertices_ReturnsExpectedDescriptions_ForDirectedGraphs([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, true); var result = string.Join("; ", graph.DescribeVertices()); Assert.AreEqual(expected, result); }
public void FindShortestPath_FillsExpectedVertices( [NotNull] string relationships, char startVertex, char endVertex, string expected) { var graph = new LiteralGraph(relationships, true); var seq = graph.FindShortestPath(startVertex, endVertex); Assert.AreEqual(expected, string.Join(",", seq)); }
public void VerifyIsBipartite_ThrowsException_ForDirectedGraphs() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <InvalidOperationException>(() => { var dummy = graph.IsBipartite; }); }
public void GetComponents_ReturnsProperComponents_ForDirectedGraphs([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, true); var result = string.Join(";", graph.GetComponents().Select(component => string.Join(",", component))); Assert.AreEqual(expected, result); }
public void GetEdges_ReturnsAllEdges([NotNull] string relationships, char vertex, string expected) { var graph = new LiteralGraph(relationships, true); var v = graph.GetEdges(vertex).Select(s => $"{s.FromVertex}{s.ToVertex}").ToArray(); var result = string.Join(",", v); Assert.AreEqual(expected, result); }
public void FillWithOneColor_FillsExpectedVertices([NotNull] string relationships, char startVertex, string expected) { var graph = new LiteralGraph(relationships, true); var result = new List <char>(); graph.FillWithOneColor(startVertex, vertex => result.Add(vertex)); Assert.AreEqual(expected, string.Join(",", result)); }
private static string Colorize([NotNull] string relationships) { var graph = new LiteralGraph(relationships, false); var result = new List <string>(); graph.Colorize((v, c) => result.Add($"{v}({c})")); return(string.Join(", ", result)); }
public void Enumeration_ReturnsAllVertices() { var graph = new LiteralGraph("A>1>B,B-1-Z,K<1<T", true); var v = graph.ToArray(); Sorting.QuickSort(v, 0, v.Length, Comparer <char> .Default); TestHelper.AssertSequence(v, 'A', 'B', 'K', 'T', 'Z'); }
public void TraverseDfs_ReportsTheCycles_InDirectedGraphs([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, true); var result = new List <string>(); graph.TraverseDfs('A', True, True, (from, to) => { result.Add($"{from.Vertex}~{to.Vertex}"); return(true); }); Assert.AreEqual(expected, string.Join(",", result)); }
public void TraverseDfs_MarksNodesWithCorrectExitTimes([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, true); var result = new List <string>(); graph.TraverseDfs('A', True, node => { result.Add($"{node.Vertex}{node.ExitTime}"); return(true); }, (from, to) => true); Assert.AreEqual(expected, string.Join(",", result)); }
public void TraverseDfs_ReturnsProperSequence_ForDirectedGraph([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, true); var result = new List <string>(); graph.TraverseDfs('A', True, node => { Assert.IsNotNull(node); result.Add($"{node.Parent?.Vertex}>{node.Vertex}"); return(true); }, (from, to) => true); Assert.AreEqual(expected, string.Join(",", result)); }
public void TraverseDfs_InterruptsOnCycle([NotNull] string relationships, char killVertex, string expected) { var graph = new LiteralGraph(relationships, true); var result = new List <string>(); graph.TraverseDfs('A', True, node => { Assert.IsNotNull(node); result.Add($"{node.Parent?.Vertex}>{node.Vertex}"); return(true); }, (from, to) => to.Vertex != killVertex); Assert.AreEqual(expected, string.Join(",", result)); }
public void TraverseBfs_ReturnsProperSequence_IfInterrupted([NotNull] string relationships, char killVertex, 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(node.Vertex != killVertex); }); Assert.AreEqual(expected, string.Join(",", result)); }
public void TraverseDfs_SelectsTheExpectedEdges_ForDirectedGraph([NotNull] string relationships, string expected) { var graph = new LiteralGraph(relationships, true); var result = new List <string>(); graph.TraverseDfs('A', node => { Assert.IsNotNull(node); result.Add(node.EntryEdge != null ? $"{node.EntryEdge}" : "()"); return(true); }, True, (from, to) => true); var actual = string.Join(",", result); Assert.AreEqual(expected, actual); }
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 Colorize_ThrowsException_ForNullApplyColor() { var graph = new LiteralGraph("A", false); Assert.Throws <ArgumentNullException>(() => graph.Colorize(null)); }
public void Colorize_ThrowsException_ForDirectedGraph() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <InvalidOperationException>(() => graph.Colorize((c, i) => { })); }
public void FillWithOneColor_ThrowsException_ForNullApplyColor() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <ArgumentNullException>(() => graph.FillWithOneColor('A', null)); }
public void FillWithOneColor_ThrowsException_ForInvalidVertex() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <ArgumentException>(() => graph.FillWithOneColor('Z', v => { })); }
public void FindCheapestPath_ThrowsException_IfFromVertexIsInvalid() { var graph = new LiteralGraph("A-1-B", false); Assert.Throws <ArgumentException>(() => graph.FindCheapestPath('Z', 'A')); }
public void FindAllArticulationVertices_ThrowsException_ForDirectedGraphs() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <InvalidOperationException>(() => graph.FindAllArticulationVertices()); }
public void TraverseDfs_ThrowsException_ForInvalidVertex() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <ArgumentException>(() => graph.TraverseDfs('Z', True, True, (node, dfsNode) => true)); }
public void TraverseDfs_ThrowsException_ForNullCycleHandler() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <ArgumentNullException>(() => graph.TraverseDfs('A', True, True, null)); }
public void TraverseDfs_ThrowsException_ForNullVisitationHandler() { var graph = new LiteralGraph("A>1>B", true); Assert.Throws <ArgumentNullException>(() => graph.TraverseDfs('A', null, True, (node, dfsNode) => true)); }