-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest2.go
43 lines (36 loc) · 842 Bytes
/
test2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
// START OMIT
import (
"strings"
"testing"
)
var acronymTests = []struct {
in string
out string
}{{
in: "hello gophercon, how are you?",
out: "hghay",
}, {
in: "Where will Gophercon be hosted next year?",
out: "wwgbhny",
}}
func TestAcronym(t *testing.T) {
for _, test := range acronymTests {
if Acronym(test.in) != test.out {
t.Errorf("Expected %s but got %s.", test.out, Acronym(test.in))
}
}
}
// END OMIT
func Acronym(s string) string {
var letters string
for _, word := range strings.Split(strings.ToLower(s), " ") {
letters = letters + string(word[0])
}
return letters
}
func main() {
var tests []testing.InternalTest
tests = append(tests, testing.InternalTest{Name: "TestTitle", F: TestAcronym})
testing.Main(func(pat, str string) (bool, error) { return true, nil }, tests, nil, nil)
}