Sha256: a5eee020abbeeaa1c041aa9f6df3c69d25ab8e05f058ba790d98ee7a38b310f1
Contents?: true
Size: 1.18 KB
Versions: 83
Compression:
Stored size: 1.18 KB
Contents
package accumulate import ( "fmt" "strings" "testing" ) func echo(c string) string { return c } func capitalize(word string) string { return strings.Title(word) } var tests = []struct { expected []string given []string converter func(string) string description string }{ {[]string{}, []string{}, echo, "echo"}, {[]string{"echo", "echo", "echo", "echo"}, []string{"echo", "echo", "echo", "echo"}, echo, "echo"}, {[]string{"First", "Letter", "Only"}, []string{"first", "letter", "only"}, capitalize, "capitalize"}, {[]string{"HELLO", "WORLD"}, []string{"hello", "world"}, strings.ToUpper, "strings.ToUpper"}, } func TestAccumulate(t *testing.T) { for _, test := range tests { actual := Accumulate(test.given, test.converter) if fmt.Sprintf("%s", actual) != fmt.Sprintf("%s", test.expected) { t.Fatalf("Accumulate(%s, %s): expected %s, actual %s", test.given, test.description, test.expected, actual) } else { t.Logf("PASS: %s %v", test.description, test.given) } } } func BenchmarkAccumulate(b *testing.B) { b.StopTimer() for _, test := range tests { b.StartTimer() for i := 0; i < b.N; i++ { Accumulate(test.given, test.converter) } b.StopTimer() } }
Version data entries
83 entries across 83 versions & 1 rubygems