2020-12-27 00:08:41 +00:00
|
|
|
package intmath
|
2020-11-10 23:34:05 +00:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2020-12-27 00:08:41 +00:00
|
|
|
func TestMin(t *testing.T) {
|
2020-11-10 23:34:05 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
a, b int
|
|
|
|
expect int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "first smaller",
|
|
|
|
a: 1,
|
|
|
|
b: 2,
|
|
|
|
expect: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "both equal",
|
|
|
|
a: 1,
|
|
|
|
b: 1,
|
|
|
|
expect: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "last smaller",
|
|
|
|
a: 2,
|
|
|
|
b: 1,
|
|
|
|
expect: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range testCases {
|
|
|
|
t.Run(c.name, func(t *testing.T) {
|
2020-12-27 00:08:41 +00:00
|
|
|
actual := Min(c.a, c.b)
|
2020-11-10 23:34:05 +00:00
|
|
|
if c.expect != actual {
|
|
|
|
t.Errorf("expected min(%d, %d) to return %d, but did %d", c.a, c.b, c.expect, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|