1 package textmagic 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestSplitSlice(t *testing.T) { 9 defer func(oldMaxInSlice int) { 10 maxInSlice = oldMaxInSlice 11 }(maxInSlice) 12 maxInSlice = 3 13 tests := []struct { 14 input []string 15 output [][]string 16 }{ 17 {[]string{}, [][]string{}}, 18 {[]string{"1"}, [][]string{{"1"}}}, 19 {[]string{"1", "2"}, [][]string{{"1", "2"}}}, 20 {[]string{"1", "2", "3"}, [][]string{{"1", "2", "3"}}}, 21 {[]string{"1", "2", "3", "4"}, [][]string{{"1", "2", "3"}, {"4"}}}, 22 {[]string{"1", "2", "3", "4", "5"}, [][]string{{"1", "2", "3"}, {"4", "5"}}}, 23 {[]string{"1", "2", "3", "4", "5", "6"}, [][]string{{"1", "2", "3"}, {"4", "5", "6"}}}, 24 {[]string{"1", "2", "3", "4", "5", "6", "7"}, [][]string{{"1", "2", "3"}, {"4", "5", "6"}, {"7"}}}, 25 } 26 for n, test := range tests { 27 if got := splitSlice(test.input); !reflect.DeepEqual(got, test.output) { 28 t.Errorf("test %d: expecting %v, got %v", n+1, test.output, got) 29 } 30 } 31 } 32 33 func TestUtos(t *testing.T) { 34 t.Parallel() 35 tests := []struct { 36 input uint64 37 output string 38 }{ 39 {0, "0"}, 40 {1, "1"}, 41 {2, "2"}, 42 {9, "9"}, 43 {10, "10"}, 44 {11, "11"}, 45 {15, "15"}, 46 {16, "16"}, 47 {17, "17"}, 48 {20, "20"}, 49 {99, "99"}, 50 {100, "100"}, 51 {999, "999"}, 52 {1000, "1000"}, 53 {9999, "9999"}, 54 {10000, "10000"}, 55 {18446744073709551615, "18446744073709551615"}, 56 } 57 for n, test := range tests { 58 if got := utos(test.input); got != test.output { 59 t.Errorf("test %d: expecting %s, got %s", n+1, test.output, got) 60 } 61 } 62 } 63