-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadd_test.go
54 lines (49 loc) · 1.21 KB
/
add_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Sedmnáctá část
// Testování aplikací naprogramovaných v jazyce Go
// https://www.root.cz/clanky/testovani-aplikaci-naprogramovanych-v-jazyce-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů ze sedmnácté části:
// https://github.com/tisnik/go-root/blob/master/article_17/README.md
//
// Demonstrační příklad číslo 6:
// Implementace jednotkových testů.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_17/test06/add_test.html
package main
import (
"fmt"
"math"
"testing"
)
type AddTest struct {
x int32
y int32
expected int32
}
func TestAdd(t *testing.T) {
var addTestInput = []AddTest{
{0, 0, 0},
{1, 0, 1},
{2, 0, 2},
{2, 1, 3},
{2, -2, 0},
{math.MaxInt32, 0, math.MaxInt32},
{math.MaxInt32, 1, math.MinInt32},
{math.MaxInt32, math.MinInt32, -1},
}
for _, i := range addTestInput {
result := add(i.x, i.y)
if result != i.expected {
msg := fmt.Sprintf("%d + %d should be %d, got %d instead",
i.x, i.y, i.expected, result)
t.Error(msg)
}
}
}