public void Should_BidirectionalSearch_Throw_If_Node_Is_Null() { //arrange var graph = new MyGraph <int>(5); graph.AddVertex(0, 0); //act Action actFrom = () => graph.BidirectionalSearch(1, 0).ToArray(); Action actTo = () => graph.BidirectionalSearch(0, 1).ToArray(); //assert actFrom.ShouldThrow <ArgumentException>(); actTo.ShouldThrow <ArgumentException>(); graph.Capacity.ShouldBeEquivalentTo(5); graph.Count.ShouldBeEquivalentTo(1); }
public void Should_BidirectionalSearch_False() { //arrange var graph = new MyGraph <int>(15); graph.AddVertex(0, 0); graph.AddVertex(1, 1); graph.AddVertex(2, 2); graph.AddVertex(3, 3); graph.AddVertex(4, 4); graph.AddVertex(5, 5); graph.AddVertex(6, 6); graph.AddVertex(8, 8); graph.AddVertex(9, 9); graph.AddVertex(10, 10); graph.AddVertex(11, 11); graph.AddVertex(12, 12); graph.AddVertex(13, 13); graph.AddVertex(14, 14); graph.AddEdge(0, 4); graph.AddEdge(1, 4); graph.AddEdge(2, 5); graph.AddEdge(3, 5); graph.AddEdge(4, 0); graph.AddEdge(4, 1); graph.AddEdge(4, 6); graph.AddEdge(5, 2); graph.AddEdge(5, 3); graph.AddEdge(5, 6); graph.AddEdge(6, 4); graph.AddEdge(6, 5); graph.AddEdge(8, 9); graph.AddEdge(8, 10); graph.AddEdge(9, 8); graph.AddEdge(9, 11); graph.AddEdge(9, 12); graph.AddEdge(10, 8); graph.AddEdge(10, 13); graph.AddEdge(10, 14); graph.AddEdge(11, 9); graph.AddEdge(12, 9); graph.AddEdge(13, 10); graph.AddEdge(14, 10); //act var result = graph.BidirectionalSearch(1, 14); //assert result.ShouldBeEquivalentTo(null); graph.Capacity.ShouldBeEquivalentTo(15); graph.Count.ShouldBeEquivalentTo(14); }
public void Should_BidirectionalSearch_Throw_If_Out_Of_Range() { //arrange var graph = new MyGraph <int>(5); //act Action actLowerFrom = () => graph.BidirectionalSearch(-1, 1); Action actHigherFrom = () => graph.BidirectionalSearch(6, 1); Action actLowerTo = () => graph.BidirectionalSearch(1, -1); Action actHigherTo = () => graph.BidirectionalSearch(1, 6); //assert actLowerFrom.ShouldThrow <ArgumentOutOfRangeException>(); actHigherFrom.ShouldThrow <ArgumentOutOfRangeException>(); actLowerTo.ShouldThrow <ArgumentOutOfRangeException>(); actHigherTo.ShouldThrow <ArgumentOutOfRangeException>(); graph.Capacity.ShouldBeEquivalentTo(5); graph.Count.ShouldBeEquivalentTo(0); }
public void Should_BidirectionalSearch_Length_One() { //arrange var graph = new MyGraph <int>(1); graph.AddVertex(0, 0); //act var result = graph.BidirectionalSearch(0, 0); //assert result[0].Count().ShouldBeEquivalentTo(1); result[1].Count().ShouldBeEquivalentTo(1); result[0].ElementAt(0).ShouldBeEquivalentTo(0); result[1].ElementAt(0).ShouldBeEquivalentTo(0); graph.Capacity.ShouldBeEquivalentTo(1); graph.Count.ShouldBeEquivalentTo(1); }
public void Should_BidirectionalSearch() { //arrange var graph = new MyGraph <int>(15); graph.AddVertex(0, 0); graph.AddVertex(1, 1); graph.AddVertex(2, 2); graph.AddVertex(3, 3); graph.AddVertex(4, 4); graph.AddVertex(5, 5); graph.AddVertex(6, 6); graph.AddVertex(7, 7); graph.AddVertex(8, 8); graph.AddVertex(9, 9); graph.AddVertex(10, 10); graph.AddVertex(11, 11); graph.AddVertex(12, 12); graph.AddVertex(13, 13); graph.AddVertex(14, 14); graph.AddEdge(0, 4); graph.AddEdge(1, 4); graph.AddEdge(2, 5); graph.AddEdge(3, 5); graph.AddEdge(4, 0); graph.AddEdge(4, 1); graph.AddEdge(4, 6); graph.AddEdge(5, 2); graph.AddEdge(5, 3); graph.AddEdge(5, 6); graph.AddEdge(6, 4); graph.AddEdge(6, 5); graph.AddEdge(6, 7); graph.AddEdge(7, 6); graph.AddEdge(7, 8); graph.AddEdge(8, 7); graph.AddEdge(8, 9); graph.AddEdge(8, 10); graph.AddEdge(9, 8); graph.AddEdge(9, 11); graph.AddEdge(9, 12); graph.AddEdge(10, 8); graph.AddEdge(10, 13); graph.AddEdge(10, 14); graph.AddEdge(11, 9); graph.AddEdge(12, 9); graph.AddEdge(13, 10); graph.AddEdge(14, 10); var fromSearch = new[] { 1, 4, 0, 6, 5, 7 }; var toSearch = new[] { 14, 10, 8, 13, 7, 9 }; //act var result = graph.BidirectionalSearch(1, 14); //assert result[0].Count().ShouldBeEquivalentTo(fromSearch.Length); result[1].Count().ShouldBeEquivalentTo(toSearch.Length); for (int i = 0; i < fromSearch.Length; i++) { fromSearch[i].ShouldBeEquivalentTo(result[0].ElementAt(i)); } for (int i = 0; i < toSearch.Length; i++) { toSearch[i].ShouldBeEquivalentTo(result[1].ElementAt(i)); } graph.Capacity.ShouldBeEquivalentTo(15); graph.Count.ShouldBeEquivalentTo(15); }
public bool RouteBetweenNodes(MyGraph <int> graph, int fromIndex, int toIndex) => graph.BidirectionalSearch(fromIndex, toIndex) != null;