public void Should_BreadthFirstSearch_Throw_Check_Index() { //arrange var graph = new MyGraphAdj <int>(5); //act Action actLower = () => graph.BreadthFirstSearch(-1).ToArray(); Action actHigher = () => graph.BreadthFirstSearch(6).ToArray(); //assert actLower.ShouldThrow <ArgumentOutOfRangeException>(); actHigher.ShouldThrow <ArgumentOutOfRangeException>(); graph.Capacity.ShouldBeEquivalentTo(5); graph.Count.ShouldBeEquivalentTo(0); }
public void Should_RemoveVertex_With_Weighted_Edges() { //arrange var graph = new MyGraphAdj <int>(4, true); graph.AddVertex(0, 0); graph.AddVertex(1, 1); graph.AddVertex(2, 2); graph.AddVertex(3, 3); graph.AddEdge(0, 2, 1); graph.AddEdge(1, 2, 2); graph.AddEdge(2, 0, 3); graph.AddEdge(2, 1, 4); graph.AddEdge(2, 3, 5); graph.AddEdge(3, 2, 6); //act graph.Remove(2); var first = graph.BreadthFirstSearch(0).ToArray(); var second = graph.BreadthFirstSearch(1).ToArray(); var third = graph.BreadthFirstSearch(3).ToArray(); Action act = () => graph.BreadthFirstSearch(2).ToArray(); //assert first.Length.ShouldBeEquivalentTo(1); second.Length.ShouldBeEquivalentTo(1); third.Length.ShouldBeEquivalentTo(1); first[0].ShouldBeEquivalentTo(0); second[0].ShouldBeEquivalentTo(1); third[0].ShouldBeEquivalentTo(3); act.ShouldThrow <ArgumentException>(); graph.Capacity.ShouldBeEquivalentTo(4); graph.Count.ShouldBeEquivalentTo(3); }
public void Should_BreadthFirstSearch_Throw_If_Node_Is_Null() { //arrange var graph = new MyGraphAdj <int>(5); //act Action act = () => graph.BreadthFirstSearch(1).ToArray(); //assert act.ShouldThrow <ArgumentException>(); graph.Capacity.ShouldBeEquivalentTo(5); graph.Count.ShouldBeEquivalentTo(0); }
public void Should_BreadthFirstSearch_Length_One() { //arrange var graph = new MyGraphAdj <int>(6); graph.AddVertex(0, 0); //act var result = graph.BreadthFirstSearch(0).ToArray(); //assert result.Length.ShouldBeEquivalentTo(1); result[0].ShouldBeEquivalentTo(0); graph.Capacity.ShouldBeEquivalentTo(6); graph.Count.ShouldBeEquivalentTo(1); }
public void Should_RemoveEdge_With_Weight() { //arrange var graph = new MyGraphAdj <int>(6, true); 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.AddEdge(0, 5, 1); graph.AddEdge(0, 1, 2); graph.AddEdge(0, 4, 3); graph.AddEdge(1, 3, 4); graph.AddEdge(1, 4, 5); graph.AddEdge(2, 1, 6); graph.AddEdge(3, 2, 7); graph.AddEdge(3, 4, 8); var resBfs = new[] { 0, 4, 5 }; //act graph.RemoveEdge(0, 1); var result = graph.BreadthFirstSearch(0).ToArray(); //assert result.Length.ShouldBeEquivalentTo(resBfs.Length); for (int i = 0; i < result.Length; i++) { result[i].ShouldBeEquivalentTo(resBfs[i]); } graph.Capacity.ShouldBeEquivalentTo(6); graph.Count.ShouldBeEquivalentTo(6); }