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

62 lines
1.1 KiB
Go
Raw Normal View History

2024-12-02 19:28:55 +00:00
package two
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIncreasedWithDampener(t *testing.T) {
tt := map[string]struct {
input []int
want bool
}{
"one violation: two numbers the same": {
input: []int{72, 74, 74, 77, 78},
want: true,
},
"one violation: not in order": {
input: []int{72, 74, 75, 77, 63},
want: true,
},
"two violations: three numbers the same": {
input: []int{74, 74, 74, 77, 78},
want: false,
},
"two violations: two numbers the same and not in order": {
input: []int{72, 74, 74, 72, 78},
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 := withDampener(tc.input, cmp, 0)
2024-12-02 19:28:55 +00:00
assert.Equal(t, tc.want, got)
})
}
}
func TestDecreasedWithDampener(t *testing.T) {
tt := map[string]struct {
input []int
want bool
}{}
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 := withDampener(tc.input, cmp, 0)
2024-12-02 19:28:55 +00:00
assert.Equal(t, tc.want, got)
})
}
}