(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func TestUndirectedGraph(t *testing.T) { |
| 9 | g := NewUndirected() |
| 10 | |
| 11 | for i := 0; i < 10; i++ { |
| 12 | v := VertexId(i) |
| 13 | g.AddVertex(v) |
| 14 | } |
| 15 | |
| 16 | if len(g.edges) != 10 { |
| 17 | fmt.Println(g) |
| 18 | t.Error() |
| 19 | } |
| 20 | |
| 21 | for i := 0; i < 10; i++ { |
| 22 | g.AddEdge(VertexId(i), VertexId(i%2), 1) |
| 23 | } |
| 24 | |
| 25 | if g.IsEdge(0, 8) == false || g.IsEdge(0, 9) == true || g.CheckVertex(2) != true { |
| 26 | fmt.Println(g) |
| 27 | t.Error() |
| 28 | } |
| 29 | |
| 30 | // AddEdge should fail for already existing Edge |
| 31 | err := g.AddEdge(0, 2, 1) |
| 32 | if err == nil { |
| 33 | fmt.Println(g) |
| 34 | t.Error() |
| 35 | } |
| 36 | |
| 37 | // AddVertex should fail for already existing vertex |
| 38 | err = g.AddVertex(0) |
| 39 | if err == nil { |
| 40 | fmt.Println(g) |
| 41 | t.Error() |
| 42 | } |
| 43 | |
| 44 | g.RemoveVertex(VertexId(9)) |
| 45 | |
| 46 | if g.IsVertex(VertexId(9)) { |
| 47 | fmt.Println(g.edges[9] == nil) |
| 48 | t.Error() |
| 49 | } |
| 50 | |
| 51 | // RemoveVertex should fail for unknown vertex |
| 52 | err = g.RemoveVertex(VertexId(9)) |
| 53 | |
| 54 | if err == nil { |
| 55 | fmt.Println(g.edges[9] == nil) |
| 56 | t.Error() |
| 57 | } |
| 58 | |
| 59 | g.RemoveEdge(0, 8) |
| 60 | |
| 61 | if g.IsEdge(VertexId(0), VertexId(8)) == true || g.edgesCount != 7 { |
| 62 | fmt.Println(g.IsEdge(VertexId(0), VertexId(8)), g.edgesCount) |
| 63 | t.Error() |
| 64 | } |
| 65 |
nothing calls this directly
no test coverage detected