76 lines
1.1 KiB
Go
76 lines
1.1 KiB
Go
package math
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestMax(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
values []int
|
|
exp int
|
|
}{
|
|
{
|
|
name: "multiple unique",
|
|
values: []int{3, 2, 4, 1},
|
|
exp: 4,
|
|
},
|
|
{
|
|
name: "single",
|
|
values: []int{5},
|
|
exp: 5,
|
|
},
|
|
{
|
|
name: "empty",
|
|
},
|
|
{
|
|
name: "multiple duplicates",
|
|
values: []int{2, 2, 2, 1},
|
|
exp: 2,
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
act := Max(tc.values...)
|
|
if tc.exp != act {
|
|
t.Fatalf("want %v but got %v", tc.exp, act)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMin(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
values []int
|
|
exp int
|
|
}{
|
|
{
|
|
name: "multiple unique",
|
|
values: []int{3, 2, 4, 1},
|
|
exp: 1,
|
|
},
|
|
{
|
|
name: "single",
|
|
values: []int{5},
|
|
exp: 5,
|
|
},
|
|
{
|
|
name: "empty",
|
|
},
|
|
{
|
|
name: "multiple duplicates",
|
|
values: []int{2, 1, 1, 1},
|
|
exp: 1,
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
act := Min(tc.values...)
|
|
if tc.exp != act {
|
|
t.Fatalf("want %v but got %v", tc.exp, act)
|
|
}
|
|
})
|
|
}
|
|
}
|