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
| func TestAdd(t *testing.T) { sum:=Add(1,2) if sum == 3 { t.Log("the result is ok") } else { t.Fatal("the result is wrong") }
sum=Add(2,4) if sum == 6 { t.Log("the result is ok") } else { t.Fatal("the result is wrong") } }
type TestTable struct { xarg int yarg int }
func TestAdd(t *testing.T){ tables := []TestTable{ {1,2}, {2,4}, {4,8}, {5,10}, {6,12}, }
for _, table := range tables{ result := Add(table.xarg, table.yarg) if result == (table.xarg + table.yarg){ t.Log("the result is ok") } else { t.Fatal("the result is wrong") } } }
|