8000 testing · Abhicodeitout/GolangTraining@53841fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 53841fc

Browse files
committed
testing
1 parent 67f6eb2 commit 53841fc

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

24_testing/00_under-development/01/sample.txt

Lines changed: 0 additions & 29 deletions
This file was deleted.

24_testing/math.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package math
2+
3+
func Adder(xs ...int) int {
4+
res := 0
5+
for _, v := range xs {
6+
res += v
7+
}
8+
return res
9+
}

24_testing/math_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package math
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
"testing/quick"
7+
)
8+
9+
func TestAdder(t *testing.T) {
10+
result := Adder(4, 7)
11+
if result != 11 {
12+
t.Fatal("4 + 7 did not equal 11")
13+
}
14+
}
15+
16+
func BenchmarkAdder(b *testing.B) {
17+
for i := 0; i < b.N; i++ {
18+
Adder(4, 7)
19+
}
20+
}
21+
22+
func ExampleAdder() {
23+
fmt.Println(Adder(4, 7))
24+
// Output:
25+
// 11
26+
}
27+
28+
func ExampleAdder_multiple() {
29+
fmt.Println(Adder(3, 6, 7, 4, 61))
30+
// Output:
31+
// 81
32+
}
33+
34+
func TestAdderBlackbox(t *testing.T) {
35+
err := quick.Check(a, nil)
36+
if err != nil {
37+
t.Fatal(err)
38+
}
39+
}
40+
41+
func a(x, y int) bool {
42+
return Adder(x, y) == x+y
43+
}

0 commit comments

Comments
 (0)
0