From 67881a455a5dc0339df470043e0125bc3dde215c Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 29 Oct 2025 15:12:03 -0400 Subject: [PATCH] internal/testutil/snake: Test recursiveness --- internal/testutil/snake/snake_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/testutil/snake/snake_test.go b/internal/testutil/snake/snake_test.go index 9d34679..66a17e6 100644 --- a/internal/testutil/snake/snake_test.go +++ b/internal/testutil/snake/snake_test.go @@ -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) } +}