internal/testutil/snake: Test recursiveness

This commit is contained in:
Sasha Koshka 2025-10-29 15:12:03 -04:00
parent fb374c5cd5
commit 67881a455a

View File

@ -37,7 +37,7 @@ func TestSnakeA(test *testing.T) {
}
func TestSnakeB(test *testing.T) {
snake := O().AddL(1, 6).AddS(
snake := O().AddO(L(1), L(6)).AddS(
L(1),
L(2),
).AddL(9).AddS(
@ -64,3 +64,26 @@ func TestSnakeB(test *testing.T) {
ok, n = Check(snake, []byte { 1, 6, 1, 2, 9, 3, 2, 1, 1, 2, 3})
if ok { test.Fatal("false positive:", n) }
}
func TestSnakeC(test *testing.T) {
snake := S(
L(1, 2, 3),
S(L(6), L(7), L(8)),
)
test.Log(snake)
ok, n := Check(snake, []byte { 1, 2, 3, 6, 7, 8 })
if !ok { test.Fatal("false negative:", n) }
ok, n = Check(snake, []byte { 6, 7, 8, 1, 2, 3 })
if !ok { test.Fatal("false negative:", n) }
ok, n = Check(snake, []byte { 7, 8, 6, 1, 2, 3 })
if !ok { test.Fatal("false negative:", n) }
ok, n = Check(snake, []byte { 1, 2, 3, 8, 6, 7 })
if !ok { test.Fatal("false negative:", n) }
ok, n = Check(snake, []byte { 2, 1, 3, 6, 7, 8 })
if ok { test.Fatal("false positive:", n) }
ok, n = Check(snake, []byte { 6, 1, 2, 3, 7, 8 })
if ok { test.Fatal("false positive:", n) }
}