Slide 13
Slide 13 text
TABLE DRIVEN TESTS
func TestAdd(t *testing.T) {
cases := []struct{ A, B, Expected int }{
{ 1, 1, 2 },
{ 1, -1, 0 },
{ 1, 0, 1 },
{ 0, 0, 0 },
}
for _, tc := range cases {
actual := tc.A + tc.B
if actual != expected {
t.Errorf(
“%d + %d = %d, expected %d”,
tc.A, tc.B, actual, tc.Expected)
}
}
}