-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum_test.go
40 lines (34 loc) Β· 941 Bytes
/
sum_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
package calc
import "testing"
/*
* κ°λ¨ν ν
μ€νΈ ν¨μ
func TestSum(t *testing.T) {
r := Sum(1, 2)
if r != 3 {
t.Error("3μ΄ μλλλ€. r=", r)
}
}*/
//1. test ν¨μλ testνλ €λ ν¨μμμ Testλ₯Ό νμ λΆμ¬μΌν¨
//2. Test λ€μμ ν¨μμ΄λ¦μ΄ μ€κ³ , ν¨μμ΄λ¦μ 첫 κΈμλ νμ λλ¬Έμλ‘ λ§λ€μ΄μΌν¨
//3. νμ *testing.T νμ
μ 맀κ°λ³μλ₯Ό λ°μ
type TestData struct {
arg1 int
arg2 int
res int
}
var testdata = []TestData{
{2, 6, 8},
{1, 2, 3},
{-8, 3, -5},
{22, -15, 7},
{6, -6, 0},
{0, 0, 0},
} //κ°λ¨ν ν
μ€νΈ λ°μ΄ν°μ§λ§, ν¨μμμ λ°μν μ μλ λ€μν μμΈ μν©μ κ³ λ €ν΄μ κΈ°μ
ν΄μΌν¨
func TestSum(t *testing.T) {
for _, d := range testdata {
r := Sum(d.arg1, d.arg2)
if r != d.res {
t.Errorf("%d+%dμ κ²°κ³Όλ %dκ° μλλλ€. r=%d", d.arg1, d.arg2, d.res, r)
}
}
}