mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-20 08:59:32 +08:00
update book code
This commit is contained in:
10
eBook/examples/chapter_13/even/even/even.go
Normal file
10
eBook/examples/chapter_13/even/even/even.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// even.go
|
||||
package even
|
||||
|
||||
func Even(i int) bool { // Exported function
|
||||
return i%2 == 0
|
||||
}
|
||||
|
||||
func Odd(i int) bool { // Exported function
|
||||
return i%2 != 0
|
||||
}
|
||||
27
eBook/examples/chapter_13/even/even/oddeven_test.go
Normal file
27
eBook/examples/chapter_13/even/even/oddeven_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// oddeven_test.go
|
||||
package even
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEven(t *testing.T) {
|
||||
if !Even(10) {
|
||||
t.Log(" 10 must be even!")
|
||||
t.Fail()
|
||||
}
|
||||
if Even(7) {
|
||||
t.Log(" 7 is not even!")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestOdd(t *testing.T) {
|
||||
if !Odd(11) {
|
||||
t.Log(" 11 must be odd!")
|
||||
t.Fail()
|
||||
}
|
||||
if Odd(10) {
|
||||
t.Log(" 10 is not odd!")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user