testutil: Add Flatten method to Snake

This commit is contained in:
Sasha Koshka 2025-08-20 12:42:54 -04:00
parent 9278bdcb43
commit 423f547da3

View File

@ -64,6 +64,18 @@ func (sn Snake) Check(data []byte) (ok bool, n int) {
return true, n
}
// Flatten returns the snake flattened to a byte array. The result of this
// function always satisfies the snake.
func (sn Snake) Flatten() []byte {
flat := []byte { }
for _, sector := range sn {
for _, variation := range sector {
flat = append(flat, variation...)
}
}
return flat
}
func (sn Snake) String() string {
if len(sn) == 0 || len(sn[0]) == 0 || len(sn[0][0]) == 0 {
return "EMPTY"