Slide 46
Slide 46 text
func TestCalculatorTable(t *testing.T) {
tests := []struct {
name string
first int
second int
expected int
}{
{"1+2", 1, 2, 3},
}
c := NewCalculator()
t.Cleanup(func() {
c.Unregister()
})
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if c.Sum(tc.first, tc.second) != tc.expected {
t.Fail()
}
})
}
}
tests := []struct {
name string
first int
second int
expected int
}{
{"1+2", 1, 2, 3},
{"1+7", 1, 7, 8},
{"2+7", 2, 7, 9},
}