aoc2024/day-02/internal/one/check_internal_test.go

70 lines
1.1 KiB
Go
Raw Normal View History

2024-12-02 19:28:55 +00:00
package one
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCheckIncreased(t *testing.T) {
tt := map[string]struct {
input []int
want bool
}{
"nominal": {
input: []int{1, 3, 6, 7, 9},
want: true,
},
"unsafe": {
input: []int{1, 3, 2, 4, 8},
want: false,
},
"two numbers the same": {
input: []int{1, 3, 3, 4, 8},
want: false,
},
}
cmp := func(nums []int, i int) bool {
return nums[i-1] >= nums[i]
}
for name, tc := range tt {
t.Run(name, func(t *testing.T) {
got := check(tc.input, cmp)
2024-12-02 19:28:55 +00:00
assert.Equal(t, tc.want, got)
})
}
}
func TestCheckDecreased(t *testing.T) {
tt := map[string]struct {
input []int
want bool
}{
"nominal": {
input: []int{7, 6, 4, 2, 1},
want: true,
},
"unsafe": {
input: []int{9, 7, 6, 2, 1},
want: false,
},
"two numbers the same": {
input: []int{8, 6, 4, 4, 1},
want: false,
},
}
cmp := func(nums []int, i int) bool {
return nums[i-1] <= nums[i]
}
for name, tc := range tt {
t.Run(name, func(t *testing.T) {
got := check(tc.input, cmp)
2024-12-02 19:28:55 +00:00
assert.Equal(t, tc.want, got)
})
}
}