func createDirectedDepthFirstGraph() unweighted.UnweightedGraph {
	g := unweighted.NewUnweightedGraph(13)
	g.AddDirectedEdge(4, 2)
	g.AddDirectedEdge(2, 3)
	g.AddDirectedEdge(3, 2)
	g.AddDirectedEdge(6, 0)
	g.AddDirectedEdge(0, 1)
	g.AddDirectedEdge(2, 0)
	g.AddDirectedEdge(11, 12)
	g.AddDirectedEdge(12, 9)
	g.AddDirectedEdge(9, 10)
	g.AddDirectedEdge(9, 11)
	g.AddDirectedEdge(8, 9)
	g.AddDirectedEdge(10, 12)
	g.AddDirectedEdge(11, 4)
	g.AddDirectedEdge(4, 3)
	g.AddDirectedEdge(3, 5)
	g.AddDirectedEdge(7, 8)
	g.AddDirectedEdge(8, 7)
	g.AddDirectedEdge(5, 4)
	g.AddDirectedEdge(0, 5)
	g.AddDirectedEdge(6, 4)
	g.AddDirectedEdge(6, 9)
	g.AddDirectedEdge(7, 6)

	return g
}
Пример #2
0
func createTestGraph() unweighted.UnweightedGraph {
	g := unweighted.NewUnweightedGraph(7)
	g.AddUndirectedEdge(0, 2)
	g.AddUndirectedEdge(0, 3)
	g.AddUndirectedEdge(1, 3)
	g.AddUndirectedEdge(1, 4)
	g.AddUndirectedEdge(1, 5)
	g.AddUndirectedEdge(2, 6)
	g.AddUndirectedEdge(4, 6)
	return g
}
Пример #3
0
func TestNewGraphVertices(t *testing.T) {
	cases := []struct {
		in, want int
	}{
		{1, 1},
		{2, 2},
		{0, 0},
	}
	for _, c := range cases {
		graph := unweighted.NewUnweightedGraph(c.in)
		got := graph.Vertices()
		if got != c.want {
			t.Errorf("NewGraph(%v) == %v, want %v", c.in, got, c.want)
		}
	}
}
func createConnectedComponentsGraph() unweighted.UnweightedGraph {
	g := unweighted.NewUnweightedGraph(13)
	g.AddUndirectedEdge(0, 6)
	g.AddUndirectedEdge(0, 2)
	g.AddUndirectedEdge(0, 1)
	g.AddUndirectedEdge(0, 5)
	g.AddUndirectedEdge(3, 5)
	g.AddUndirectedEdge(3, 4)
	g.AddUndirectedEdge(4, 5)
	g.AddUndirectedEdge(4, 6)
	g.AddUndirectedEdge(7, 8)
	g.AddUndirectedEdge(9, 10)
	g.AddUndirectedEdge(9, 11)
	g.AddUndirectedEdge(9, 12)
	g.AddUndirectedEdge(11, 12)
	return g
}
func createBreadthFirstPathsGraph() unweighted.UnweightedGraph {
	g := unweighted.NewUnweightedGraph(13)
	g.AddUndirectedEdge(0, 6)
	g.AddUndirectedEdge(0, 2)
	g.AddUndirectedEdge(0, 1)
	g.AddUndirectedEdge(0, 5)
	g.AddUndirectedEdge(3, 5)
	g.AddUndirectedEdge(3, 4)
	g.AddUndirectedEdge(4, 5)
	g.AddUndirectedEdge(4, 6)
	g.AddUndirectedEdge(7, 8)
	g.AddUndirectedEdge(9, 10)
	g.AddUndirectedEdge(9, 11)
	g.AddUndirectedEdge(9, 12)
	g.AddUndirectedEdge(11, 12)
	return g
}
Пример #6
0
func createDepthFirstGraph() unweighted.UnweightedGraph {
	g := unweighted.NewUnweightedGraph(13)
	g.AddUndirectedEdge(0, 5)
	g.AddUndirectedEdge(4, 3)
	g.AddUndirectedEdge(0, 1)
	g.AddUndirectedEdge(9, 12)
	g.AddUndirectedEdge(6, 4)
	g.AddUndirectedEdge(5, 4)
	g.AddUndirectedEdge(0, 2)
	g.AddUndirectedEdge(11, 12)
	g.AddUndirectedEdge(9, 10)
	g.AddUndirectedEdge(0, 6)
	g.AddUndirectedEdge(7, 8)
	g.AddUndirectedEdge(9, 11)
	g.AddUndirectedEdge(5, 3)

	return g
}