golint: Fixup issues found in the report

This also increases the max allowed to 5% -- I'm happy to make this
lower if someone asks.
This commit is contained in:
James Shubin
2017-02-22 20:14:22 -05:00
parent b0fce6a80d
commit 98bc96c911
33 changed files with 392 additions and 392 deletions

View File

@@ -45,11 +45,11 @@ func TestPgraphT1(t *testing.T) {
G := NewGraph("g1")
if i := G.NumVertices(); i != 0 {
t.Errorf("Should have 0 vertices instead of: %d.", i)
t.Errorf("should have 0 vertices instead of: %d", i)
}
if i := G.NumEdges(); i != 0 {
t.Errorf("Should have 0 edges instead of: %d.", i)
t.Errorf("should have 0 edges instead of: %d", i)
}
v1 := NV("v1")
@@ -58,11 +58,11 @@ func TestPgraphT1(t *testing.T) {
G.AddEdge(v1, v2, e1)
if i := G.NumVertices(); i != 2 {
t.Errorf("Should have 2 vertices instead of: %d.", i)
t.Errorf("should have 2 vertices instead of: %d", i)
}
if i := G.NumEdges(); i != 1 {
t.Errorf("Should have 1 edges instead of: %d.", i)
t.Errorf("should have 1 edges instead of: %d", i)
}
}
@@ -89,7 +89,7 @@ func TestPgraphT2(t *testing.T) {
G.AddEdge(v5, v6, e5)
if i := G.NumVertices(); i != 6 {
t.Errorf("Should have 6 vertices instead of: %d.", i)
t.Errorf("should have 6 vertices instead of: %d", i)
}
}
@@ -117,19 +117,19 @@ func TestPgraphT3(t *testing.T) {
//G.AddEdge(v6, v4, e6)
out1 := G.DFS(v1)
if i := len(out1); i != 3 {
t.Errorf("Should have 3 vertices instead of: %d.", i)
t.Errorf("Found: %v", out1)
t.Errorf("should have 3 vertices instead of: %d", i)
t.Errorf("found: %v", out1)
for _, v := range out1 {
t.Errorf("Value: %v", v.GetName())
t.Errorf("value: %v", v.GetName())
}
}
out2 := G.DFS(v4)
if i := len(out2); i != 3 {
t.Errorf("Should have 3 vertices instead of: %d.", i)
t.Errorf("Found: %v", out1)
t.Errorf("should have 3 vertices instead of: %d", i)
t.Errorf("found: %v", out1)
for _, v := range out1 {
t.Errorf("Value: %v", v.GetName())
t.Errorf("value: %v", v.GetName())
}
}
}
@@ -149,10 +149,10 @@ func TestPgraphT4(t *testing.T) {
out := G.DFS(v1)
if i := len(out); i != 3 {
t.Errorf("Should have 3 vertices instead of: %d.", i)
t.Errorf("Found: %v", out)
t.Errorf("should have 3 vertices instead of: %d", i)
t.Errorf("found: %v", out)
for _, v := range out {
t.Errorf("Value: %v", v.GetName())
t.Errorf("value: %v", v.GetName())
}
}
}
@@ -182,7 +182,7 @@ func TestPgraphT5(t *testing.T) {
save := []*Vertex{v1, v2, v3}
out := G.FilterGraph("new g5", save)
if i := out.NumVertices(); i != 3 {
t.Errorf("Should have 3 vertices instead of: %d.", i)
t.Errorf("should have 3 vertices instead of: %d", i)
}
}
@@ -219,7 +219,7 @@ func TestPgraphT6(t *testing.T) {
}
if i := HeisenbergGraphCount(graphs); i != 2 {
t.Errorf("Should have 2 graphs instead of: %d.", i)
t.Errorf("should have 2 graphs instead of: %d", i)
}
}
@@ -237,31 +237,31 @@ func TestPgraphT7(t *testing.T) {
G.AddEdge(v3, v1, e3)
if i := G.NumVertices(); i != 3 {
t.Errorf("Should have 3 vertices instead of: %d.", i)
t.Errorf("should have 3 vertices instead of: %d", i)
}
G.DeleteVertex(v2)
if i := G.NumVertices(); i != 2 {
t.Errorf("Should have 2 vertices instead of: %d.", i)
t.Errorf("should have 2 vertices instead of: %d", i)
}
G.DeleteVertex(v1)
if i := G.NumVertices(); i != 1 {
t.Errorf("Should have 1 vertices instead of: %d.", i)
t.Errorf("should have 1 vertices instead of: %d", i)
}
G.DeleteVertex(v3)
if i := G.NumVertices(); i != 0 {
t.Errorf("Should have 0 vertices instead of: %d.", i)
t.Errorf("should have 0 vertices instead of: %d", i)
}
G.DeleteVertex(v2) // duplicate deletes don't error...
if i := G.NumVertices(); i != 0 {
t.Errorf("Should have 0 vertices instead of: %d.", i)
t.Errorf("should have 0 vertices instead of: %d", i)
}
}
@@ -271,26 +271,26 @@ func TestPgraphT8(t *testing.T) {
v2 := NV("v2")
v3 := NV("v3")
if VertexContains(v1, []*Vertex{v1, v2, v3}) != true {
t.Errorf("Should be true instead of false.")
t.Errorf("should be true instead of false.")
}
v4 := NV("v4")
v5 := NV("v5")
v6 := NV("v6")
if VertexContains(v4, []*Vertex{v5, v6}) != false {
t.Errorf("Should be false instead of true.")
t.Errorf("should be false instead of true.")
}
v7 := NV("v7")
v8 := NV("v8")
v9 := NV("v9")
if VertexContains(v8, []*Vertex{v7, v8, v9}) != true {
t.Errorf("Should be true instead of false.")
t.Errorf("should be true instead of false.")
}
v1b := NV("v1") // same value, different objects
if VertexContains(v1b, []*Vertex{v1, v2, v3}) != false {
t.Errorf("Should be false instead of true.")
t.Errorf("should be false instead of true.")
}
}
@@ -319,49 +319,49 @@ func TestPgraphT9(t *testing.T) {
indegree := G.InDegree() // map[*Vertex]int
if i := indegree[v1]; i != 0 {
t.Errorf("Indegree of v1 should be 0 instead of: %d.", i)
t.Errorf("indegree of v1 should be 0 instead of: %d", i)
}
if i := indegree[v2]; i != 1 {
t.Errorf("Indegree of v2 should be 1 instead of: %d.", i)
t.Errorf("indegree of v2 should be 1 instead of: %d", i)
}
if i := indegree[v3]; i != 1 {
t.Errorf("Indegree of v3 should be 1 instead of: %d.", i)
t.Errorf("indegree of v3 should be 1 instead of: %d", i)
}
if i := indegree[v4]; i != 2 {
t.Errorf("Indegree of v4 should be 2 instead of: %d.", i)
t.Errorf("indegree of v4 should be 2 instead of: %d", i)
}
if i := indegree[v5]; i != 1 {
t.Errorf("Indegree of v5 should be 1 instead of: %d.", i)
t.Errorf("indegree of v5 should be 1 instead of: %d", i)
}
if i := indegree[v6]; i != 1 {
t.Errorf("Indegree of v6 should be 1 instead of: %d.", i)
t.Errorf("indegree of v6 should be 1 instead of: %d", i)
}
outdegree := G.OutDegree() // map[*Vertex]int
if i := outdegree[v1]; i != 2 {
t.Errorf("Outdegree of v1 should be 2 instead of: %d.", i)
t.Errorf("outdegree of v1 should be 2 instead of: %d", i)
}
if i := outdegree[v2]; i != 1 {
t.Errorf("Outdegree of v2 should be 1 instead of: %d.", i)
t.Errorf("outdegree of v2 should be 1 instead of: %d", i)
}
if i := outdegree[v3]; i != 1 {
t.Errorf("Outdegree of v3 should be 1 instead of: %d.", i)
t.Errorf("outdegree of v3 should be 1 instead of: %d", i)
}
if i := outdegree[v4]; i != 1 {
t.Errorf("Outdegree of v4 should be 1 instead of: %d.", i)
t.Errorf("outdegree of v4 should be 1 instead of: %d", i)
}
if i := outdegree[v5]; i != 1 {
t.Errorf("Outdegree of v5 should be 1 instead of: %d.", i)
t.Errorf("outdegree of v5 should be 1 instead of: %d", i)
}
if i := outdegree[v6]; i != 0 {
t.Errorf("Outdegree of v6 should be 0 instead of: %d.", i)
t.Errorf("outdegree of v6 should be 0 instead of: %d", i)
}
s, err := G.TopologicalSort()
// either possibility is a valid toposort
match := reflect.DeepEqual(s, []*Vertex{v1, v2, v3, v4, v5, v6}) || reflect.DeepEqual(s, []*Vertex{v1, v3, v2, v4, v5, v6})
if err != nil || !match {
t.Errorf("Topological sort failed, error: %v.", err)
t.Errorf("topological sort failed, error: %v", err)
str := "Found:"
for _, v := range s {
str += " " + v.Res.GetName()
@@ -393,7 +393,7 @@ func TestPgraphT10(t *testing.T) {
G.AddEdge(v4, v2, e6) // cycle
if _, err := G.TopologicalSort(); err == nil {
t.Errorf("Topological sort passed, but graph is cyclic!")
t.Errorf("topological sort passed, but graph is cyclic")
}
}
@@ -403,7 +403,7 @@ func TestPgraphReachability0(t *testing.T) {
G := NewGraph("g")
result := G.Reachability(nil, nil)
if result != nil {
t.Logf("Reachability failed!")
t.Logf("reachability failed")
str := "Got:"
for _, v := range result {
str += " " + v.Res.GetName()
@@ -420,7 +420,7 @@ func TestPgraphReachability0(t *testing.T) {
expected := []*Vertex{}
if !reflect.DeepEqual(result, expected) {
t.Logf("Reachability failed!")
t.Logf("reachability failed")
str := "Got:"
for _, v := range result {
str += " " + v.Res.GetName()
@@ -451,7 +451,7 @@ func TestPgraphReachability0(t *testing.T) {
expected := []*Vertex{}
if !reflect.DeepEqual(result, expected) {
t.Logf("Reachability failed!")
t.Logf("reachability failed")
str := "Got:"
for _, v := range result {
str += " " + v.Res.GetName()
@@ -486,7 +486,7 @@ func TestPgraphReachability1(t *testing.T) {
expected := []*Vertex{v1, v2, v3, v4, v5, v6}
if !reflect.DeepEqual(result, expected) {
t.Logf("Reachability failed!")
t.Logf("reachability failed")
str := "Got:"
for _, v := range result {
str += " " + v.Res.GetName()
@@ -523,7 +523,7 @@ func TestPgraphReachability2(t *testing.T) {
// !xor test
if reflect.DeepEqual(result, expected1) == reflect.DeepEqual(result, expected2) {
t.Logf("Reachability failed!")
t.Logf("reachability failed")
str := "Got:"
for _, v := range result {
str += " " + v.Res.GetName()
@@ -558,7 +558,7 @@ func TestPgraphReachability3(t *testing.T) {
expected := []*Vertex{v1, v5, v6}
if !reflect.DeepEqual(result, expected) {
t.Logf("Reachability failed!")
t.Logf("reachability failed")
str := "Got:"
for _, v := range result {
str += " " + v.Res.GetName()
@@ -593,7 +593,7 @@ func TestPgraphReachability4(t *testing.T) {
expected := []*Vertex{v1, v6}
if !reflect.DeepEqual(result, expected) {
t.Logf("Reachability failed!")
t.Logf("reachability failed")
str := "Got:"
for _, v := range result {
str += " " + v.Res.GetName()
@@ -611,19 +611,19 @@ func TestPgraphT11(t *testing.T) {
v6 := NV("v6")
if rev := Reverse([]*Vertex{}); !reflect.DeepEqual(rev, []*Vertex{}) {
t.Errorf("Reverse of vertex slice failed.")
t.Errorf("reverse of vertex slice failed")
}
if rev := Reverse([]*Vertex{v1}); !reflect.DeepEqual(rev, []*Vertex{v1}) {
t.Errorf("Reverse of vertex slice failed.")
t.Errorf("reverse of vertex slice failed")
}
if rev := Reverse([]*Vertex{v1, v2, v3, v4, v5, v6}); !reflect.DeepEqual(rev, []*Vertex{v6, v5, v4, v3, v2, v1}) {
t.Errorf("Reverse of vertex slice failed.")
t.Errorf("reverse of vertex slice failed")
}
if rev := Reverse([]*Vertex{v6, v5, v4, v3, v2, v1}); !reflect.DeepEqual(rev, []*Vertex{v1, v2, v3, v4, v5, v6}) {
t.Errorf("Reverse of vertex slice failed.")
t.Errorf("reverse of vertex slice failed")
}
}
@@ -684,10 +684,10 @@ func ListStrCmp(a, b []string) bool {
// It also compares if grouped element groups are identical
func GraphCmp(g1, g2 *Graph) error {
if n1, n2 := g1.NumVertices(), g2.NumVertices(); n1 != n2 {
return fmt.Errorf("Graph g1 has %d vertices, while g2 has %d.", n1, n2)
return fmt.Errorf("graph g1 has %d vertices, while g2 has %d", n1, n2)
}
if e1, e2 := g1.NumEdges(), g2.NumEdges(); e1 != e2 {
return fmt.Errorf("Graph g1 has %d edges, while g2 has %d.", e1, e2)
return fmt.Errorf("graph g1 has %d edges, while g2 has %d", e1, e2)
}
var m = make(map[*Vertex]*Vertex) // g1 to g2 vertex correspondence
@@ -718,7 +718,7 @@ Loop:
continue Loop
}
}
return fmt.Errorf("Graph g1, has no match in g2 for: %v", v1.GetName())
return fmt.Errorf("fraph g1, has no match in g2 for: %v", v1.GetName())
}
// vertices (and groups) match :)
@@ -727,7 +727,7 @@ Loop:
v2 := m[v1] // lookup in map to get correspondance
// g1.Adjacency[v1] corresponds to g2.Adjacency[v2]
if e1, e2 := len(g1.Adjacency[v1]), len(g2.Adjacency[v2]); e1 != e2 {
return fmt.Errorf("Graph g1, vertex(%v) has %d edges, while g2, vertex(%v) has %d.", v1.GetName(), e1, v2.GetName(), e2)
return fmt.Errorf("graph g1, vertex(%v) has %d edges, while g2, vertex(%v) has %d", v1.GetName(), e1, v2.GetName(), e2)
}
for vv1, ee1 := range g1.Adjacency[v1] {
@@ -754,12 +754,12 @@ Loop:
// does l1 match l2 ?
if !ListStrCmp(l1, l2) { // cmp!
return fmt.Errorf("Graph g1 and g2 don't agree on: %v and %v", vv1.GetName(), vv2.GetName())
return fmt.Errorf("graph g1 and g2 don't agree on: %v and %v", vv1.GetName(), vv2.GetName())
}
// check: (2) ee1 == ee2
if ee1.Name != ee2.Name {
return fmt.Errorf("Graph g1 edge(%v) doesn't match g2 edge(%v)", ee1.Name, ee2.Name)
return fmt.Errorf("graph g1 edge(%v) doesn't match g2 edge(%v)", ee1.Name, ee2.Name)
}
}
}
@@ -1298,9 +1298,9 @@ func TestPgraphGroupingConnected1(t *testing.T) {
func TestDurationAssumptions(t *testing.T) {
var d time.Duration
if (d == 0) != true {
t.Errorf("Empty time.Duration is no longer equal to zero!")
t.Errorf("empty time.Duration is no longer equal to zero")
}
if (d > 0) != false {
t.Errorf("Empty time.Duration is now greater than zero!")
t.Errorf("empty time.Duration is now greater than zero")
}
}