// AdjacencyMatrixGraphSample adjacency Matrix based graph sample 2
/*
    For directed graph, the matrix will be asymmetric.

	  u v w x y z

  u   0 1 0 1 0 0
  v   0 0 0 0 1 0
  w   0 0 0 0 1 1
  x   0 1 0 0 0 0
  y   0 0 0 1 0 0
  z   0 0 0 0 0 1
*/
AdjacencyMatrixGraphSample adjacency Matrix based graph sample 2

For directed graph, the matrix will be asymmetric.

u v w x y z


// AdjacencyMatrixGraphSample adjacency Matrix based graph sample 2 / * For directed graph the matrix will be asymmetric . u v w x y z u 0 1 0 1 0 0 v 0 0 0 0 1 0 w 0 0 0 0 1 1 x 0 1 0 0 0 0 y 0 0 0 1 0 0 z 0 0 0 0 0 1 * /
func TestAdjacencyMatrixGraphSample(t *testing.T) {
	want := [][]bool{
		{false, true, false, true, false, false},
		{false, false, false, false, true, false},
		{false, false, false, false, true, true},
		{false, true, false, false, false, false},
		{false, false, false, true, false, false},
		{false, false, false, false, false, true},
	}
	g := AdjacencyMatrixGraphSample()
	if g.Directed() != directedGraph {
		t.Errorf("new adjacency matrix graph sample, got directed %v, want %v", g.Directed(), directedGraph)
	}
	if g.NodeCount() != nodeCount {
		t.Errorf("new adjacency matrix graph sample, got node count %d, want %d", g.NodeCount(), nodeCount)
	}
	wantEdgeCount := 0
	for _, s := range want {
		for _, b := range s {
			if b {
				wantEdgeCount++
			}
		}
	}
	if g.EdgeCount() != wantEdgeCount {
		t.Errorf("new adjacency matrix graph sample, got edge count %d, want %d", g.EdgeCount(), wantEdgeCount)
	}
	g.IterateAllNodes(func(u graph.NodeID) {
		g.IterateAdjacencyNodes(u, func(v graph.NodeID) {
			if !want[u][v] {
				t.Errorf("adjacency matrix graph sample, got %v->%v, want %v !-> %v",
					u, v, u, v)
			}
		})
	})
	var iteratedEdgeCount int
	g.IterateEdges(func(edge graph.EdgeID) {
		iteratedEdgeCount++
	})
	if iteratedEdgeCount != wantEdgeCount {
		t.Errorf("new adjacency matrix graph sample, got iterated edge count %d, want %d", iteratedEdgeCount, wantEdgeCount)
	}
}
func TestAdjacencyMatrixGraphSample ( t * testing . T ) { want := [ ] [ ] bool { { false , true , false , true , false , false } , { false , false , false , false , true , false } , { false , false , false , false , true , true } , { false , true , false , false , false , false } , { false , false , false , true , false , false } , { false , false , false , false , false , true } , } g := AdjacencyMatrixGraphSample ( ) if g . Directed ( ) != directedGraph { t . Errorf ( " " , g . Directed ( ) , directedGraph ) } if g . NodeCount ( ) != nodeCount { t . Errorf ( " " , g . NodeCount ( ) , nodeCount ) } wantEdgeCount := 0 for _ , s := range want { for _ , b := range s { if b { wantEdgeCount ++ } } } if g . EdgeCount ( ) != wantEdgeCount { t . Errorf ( " " , g . EdgeCount ( ) , wantEdgeCount ) } g . IterateAllNodes ( func ( u graph . NodeID ) { g . IterateAdjacencyNodes ( u , func ( v graph . NodeID ) { if ! want [ u ] [ v ] { t . Errorf ( " " , u , v , u , v ) } } ) } ) var iteratedEdgeCount int g . IterateEdges ( func ( edge graph . EdgeID ) { iteratedEdgeCount ++ } ) if iteratedEdgeCount != wantEdgeCount { t . Errorf ( " " , iteratedEdgeCount , wantEdgeCount ) } }
AdjacencyMatrixGraphSample adjacency Matrix based graph sample 2
AdjacencyMatrixGraphSample adjacency Matrix based graph sample 2