@@ -289,23 +289,25 @@ func TestLongestRepeatingSequence(t *testing.T) {
289289 }
290290}
291291
292-
293- type truncatetest struct {
294- MaxSize int
295- Result interface {}
292+ type truncaTeest struct {
293+ test string
294+ maxSize int
295+ result string
296296}
297297
298298func TestTruncate (t * testing.T ) {
299- tests := map [string ]truncatetest {
300- "abcd" : {MaxSize : 0 , Result : "abcd" },
301- "abcde" : {MaxSize : 3 , Result : "abc" },
302- "abcdef" : {MaxSize : 8 , Result : "abcdef" },
303- "abcdefg" : {MaxSize : 6 , Result : "abcdef" },
299+ tests := []truncaTeest {
300+ {test : "abcd" , maxSize : - 1 , result : "abcd" },
301+ {test : "abcd" , maxSize : 0 , result : "" },
302+ {test : "abcde" , maxSize : 3 , result : "abc" },
303+ {test : "abcdef" , maxSize : 8 , result : "abcdef" },
304+ {test : "abcdefg" , maxSize : 6 , result : "abcdef" },
305+ {test : "aaaa" , maxSize : 20 , result : "aaaa" },
306+ {test : "aaaa" , maxSize : 4 , result : "aaaa" },
304307 }
305308
306- for str , test := range tests {
307- res := Truncate (str , test .MaxSize )
308- require .Equalf (t , test .Result , res , "test:%s maxsize: %d result: %s" , str , test .MaxSize , res )
309+ for _ , test := range tests {
310+ res := Truncate (test . test , test .maxSize )
311+ require .Equalf (t , test .result , res , "test:%s maxsize: %d result: %s" , test . test , test .maxSize , res )
309312 }
310-
311- }
313+ }
0 commit comments