Skip to content

Commit 647ab01

Browse files
committed
Add more tests for Golang DevRank
1 parent 074c49e commit 647ab01

File tree

22 files changed

+429
-22
lines changed

22 files changed

+429
-22
lines changed

persper/analytics/go.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_graph(self):
4242
r = requests.get(graph_url)
4343
graph_data = r.json()
4444
graph_data['directed'] = True
45-
graph_data['multigraph'] = True
45+
graph_data['multigraph'] = False
4646
return CallCommitGraph(graph_data)
4747

4848
def reset_graph(self):

test/go_test_repo/D/main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
import(
3+
"fmt"
4+
"math"
5+
)
6+
type a func()
7+
8+
type Vertex struct {
9+
X, Y float64
10+
}
11+
12+
func (v Vertex) Abs() float64 {
13+
return math.Sqrt(v.X*v.X + v.Y*v.Y)
14+
}
15+
func (v *Vertex) Absp() float64{
16+
return math.Sqrt(v.X*v.X + v.Y*v.Y)
17+
}
18+
19+
func funcA () {
20+
fmt.Println("func A is called!")
21+
}
22+
23+
func main() {
24+
a := funcA
25+
a()
26+
v := Vertex{3, 4}
27+
fmt.Println(v.Abs())
28+
p := &Vertex{4,5}
29+
fmt.Println(p.Absp())
30+
}
31+

test/go_test_repo/cg.dot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
digraph go_test_repo {
2-
A -> B -> C;
2+
A -> B -> C -> D;
33
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package sm
2+
3+
func Add(a int, b int) int {
4+
return a + b
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package sm
2+
3+
import "testing"
4+
5+
func TestAdd1(t *testing.T) {
6+
r := Add(1, 2)
7+
8+
if r != 3 {
9+
t.Errorf("Add(1, 2) failed. Got %d, expected 3.", r)
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package sm
2+
3+
import "math"
4+
5+
func Sqrt(i int) int {
6+
v := math.Sqrt(float64(i))
7+
return int(v)
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package sm
2+
3+
import "testing"
4+
5+
func TestSqrt1(t *testing.T) {
6+
v := Sqrt(16)
7+
8+
if v != 4 {
9+
t.Errorf("Sqrt(16) failed. Got %v, expected 4.", v)
10+
}
11+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import ("os"
4+
"fmt"
5+
"strconv"
6+
"gitlab.com/meri.co/test/calcproj/src/simplemath")
7+
8+
var Usage = func() {
9+
fmt.Println("USAGE: calc command [arguments] ...")
10+
fmt.Println("\nThe commands are:\n\tadd\tAddition of two values.\n\tsqrt\tSquare root of a non-negative value.")
11+
}
12+
13+
func main() {
14+
args := os.Args
15+
if args == nil || len(args) < 2 {
16+
Usage()
17+
return
18+
}
19+
20+
switch args[1] {
21+
case "add":
22+
if len(args) != 4 {
23+
fmt.Println("USAGE: calc add <integer1> <integer2>")
24+
return
25+
}
26+
27+
v1, err1 := strconv.Atoi(args[2])
28+
v2, err2 := strconv.Atoi(args[3])
29+
if err1 != nil || err2 != nil {
30+
fmt.Println("USAGE: calc add <integer1> <integer2>")
31+
return
32+
}
33+
34+
ret := sm.Add(v1, v2)
35+
fmt.Println("Result: ", ret)
36+
case "sqrt":
37+
if len(args) != 3 {
38+
fmt.Println("USAGE: calc sqrt <integer>")
39+
return
40+
}
41+
42+
v, err := strconv.Atoi(args[2])
43+
if err != nil {
44+
fmt.Println("USAGE: calc sqrt <integer>")
45+
return
46+
}
47+
48+
ret := sm.Sqrt(v)
49+
fmt.Println("Result: ", ret)
50+
default:
51+
Usage()
52+
}
53+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package sm
2+
3+
func Add(a int, b int) int {
4+
return a + b
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package sm
2+
3+
import "testing"
4+
5+
func TestAdd1(t *testing.T) {
6+
r := Add(1, 2)
7+
8+
if r != 3 {
9+
t.Errorf("Add(1, 2) failed. Got %d, expected 3.", r)
10+
}
11+
}

0 commit comments

Comments
 (0)