-
Notifications
You must be signed in to change notification settings - Fork 1
/
minmax_test.go
59 lines (54 loc) · 1.1 KB
/
minmax_test.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package goulash
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMinMax(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input []int
expectMin int
expectMax int
}{
{
name: "Empty slice",
input: []int{},
expectMin: 0,
expectMax: 0,
},
{
name: "Slice with odd number of elements",
input: []int{3, 4, 5, 1, 2},
expectMin: 1,
expectMax: 5,
},
{
name: "Slice with even number of elements",
input: []int{3, 0, 1, 2},
expectMin: 0,
expectMax: 3,
},
{
name: "Slice with all negative numbers",
input: []int{-3, -1, -4, -2},
expectMin: -4,
expectMax: -1,
},
{
name: "Slice with one negative number",
input: []int{2, -1, 0, 1},
expectMin: -1,
expectMax: 2,
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
actualMin, actualMax := MinMax(testCase.input...)
assert.Equal(t, testCase.expectMin, actualMin)
assert.Equal(t, testCase.expectMax, actualMax)
})
}
}