mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
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)
|
|
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)
|
|
assert.Equal(t, tc.want, got)
|
|
})
|
|
}
|
|
}
|