public static DirectedEdge CreateEdge(string description) { var parts = description.Split("-"); var from = CreateNode(parts[0]); var to = CreateNode(parts[1]); return(DirectedEdge.Between(from, to)); }
public static DirectedGraph Transform(DirectedGraph originalGraph, IEnumerable <Path> primePaths, NodeIdentity start, NodeIdentity end) { ArgumentHelpers.ThrowIfNull(() => originalGraph); ArgumentHelpers.ThrowIfNull(() => primePaths); var nodes = new List <NodeIdentity> { start, end }; var edges = new List <DirectedEdge>(); var nodePathLookup = new Dictionary <NodeIdentity, Path>(); nodePathLookup.Add(start, Path.Of(start)); nodePathLookup.Add(end, Path.Of(end)); foreach (var path in primePaths) { var node = NodeIdentity.Of(Describe(path)); nodes.Add(node); nodePathLookup.Add(node, path); } foreach (var firstPathKey in nodes) { if (firstPathKey == end) { continue; } var firstPath = nodePathLookup[firstPathKey]; foreach (var secondPathKey in nodes) { if (secondPathKey == firstPathKey || secondPathKey == start) { continue; } var secondPath = nodePathLookup[secondPathKey]; var maybeEdge = firstPath.Extend(secondPath, originalGraph); if (Path.IsEmpty(maybeEdge)) { continue; } if (!ContainsAnyOtherPrimePath(primePaths, maybeEdge, firstPath, secondPath)) { edges.Add(DirectedEdge.Between(firstPathKey, secondPathKey)); } } } return(DirectedGraph.Of(edges, nodes)); }
public void ToCannotBeNull() { typeof(DirectedEdge).Invoking(_ => DirectedEdge.Between(foo, null)) .Should().Throw <ArgumentNullException>() .Which.ParamName.Should().Be("to"); }
public void FromCannotBeNull() { typeof(DirectedEdge).Invoking(_ => DirectedEdge.Between(null, foo)) .Should().Throw <ArgumentNullException>() .Which.ParamName.Should().Be("from"); }
public void FromCanBeSameAsTo() { var edge = DirectedEdge.Between(foo, foo); edge.From.Should().Be(edge.To); }
public void HasUsefulToStringOverride() { var edge = DirectedEdge.Between(foo, bar); edge.ToString().Should().Be("foo -> bar"); }