package util import ( "reflect" "testing" ) func TestChunkStrings(t *testing.T) { tests := []struct { name string input []string size int expected [][]string }{ {"exact multiple", []string{"a", "b", "c", "d"}, 2, [][]string{{"a", "b"}, {"c", "d"}}}, {"with a remainder", []string{"a", "b", "c"}, 2, [][]string{{"a", "b"}, {"c"}}}, {"size larger than input", []string{"a", "b"}, 5, [][]string{{"a", "b"}}}, {"size of one", []string{"a", "b"}, 1, [][]string{{"a"}, {"b"}}}, {"size of zero", []string{"a", "b"}, 0, nil}, {"negative size", []string{"a", "b"}, -1, nil}, {"empty input", []string{}, 2, nil}, {"nil input", nil, 2, nil}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { got := ChunkStrings(test.input, test.size) if !reflect.DeepEqual(got, test.expected) { t.Errorf("expected %#v got %#v", test.expected, got) } }) } } func TestChunkStringsReturnsCopies(t *testing.T) { input := []string{"a", "b", "c", "d"} chunks := ChunkStrings(input, 2) chunks[0][0] = "changed" if input[0] != "a" { t.Errorf("expected the input to be unchanged, got %#v", input) } }