batch_test.go (809B)
1 package batch_test 2 3 import ( 4 "testing" 5 6 "markhuge.com/batch" 7 ) 8 9 func TestStr(t *testing.T) { 10 input := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"} 11 expected := [][]string{ 12 {"a", "b", "c", "d"}, 13 {"e", "f", "g", "h"}, 14 {"i", "j", "k"}, 15 } 16 result := batch.Str(input, 4) 17 18 for i := range result { 19 for j := range result[i] { 20 if expected[i][j] != result[i][j] { 21 t.Fatalf("Expected %s got %s\n", expected[i][j], result[i][j]) 22 } 23 } 24 } 25 } 26 27 func TestStrJoin(t *testing.T) { 28 input := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"} 29 expected := []string{ 30 "a,b,c,d", 31 "e,f,g,h", 32 "i,j,k", 33 } 34 result := batch.StrJoin(input, 4, ",") 35 36 for i := range result { 37 if expected[i] != result[i] { 38 t.Fatalf("Expected %s, got %s", expected[i], result[i]) 39 } 40 } 41 42 }