mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-19 14:31:43 +08:00
update book code
This commit is contained in:
8
eBook/examples/chapter_9/uppercase/uc/uc.go
Normal file
8
eBook/examples/chapter_9/uppercase/uc/uc.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// uc.go
|
||||
package uc
|
||||
|
||||
import "strings"
|
||||
|
||||
func UpperCase(str string) string {
|
||||
return strings.ToUpper(str)
|
||||
}
|
23
eBook/examples/chapter_9/uppercase/uc/uc_test.go
Normal file
23
eBook/examples/chapter_9/uppercase/uc/uc_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// uc_test.go
|
||||
package uc
|
||||
|
||||
import "testing"
|
||||
|
||||
type ucTest struct {
|
||||
in, out string
|
||||
}
|
||||
|
||||
var ucTests = []ucTest {
|
||||
ucTest{"abc", "ABC"},
|
||||
ucTest{"cvo-az", "CVO-AZ"},
|
||||
ucTest{"Antwerp", "ANTWERP"},
|
||||
}
|
||||
|
||||
func TestUC(t *testing.T) {
|
||||
for _, ut := range ucTests {
|
||||
uc := UpperCase(ut.in)
|
||||
if uc != ut.out {
|
||||
t.Errorf("UpperCase(%s) = %s, must be %s.", ut.in, uc, ut.out)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user