Browse Source

Move useful code

pull/533/head
Xavier Petit 4 years ago committed by xpetit
parent
commit
dc7853ec7c
  1. 2
      go/lib/is/is.go
  2. 8
      go/tests/any/main.go
  3. 8
      go/tests/countif/main.go
  4. 2
      go/tests/isnumeric/main.go

2
go/tests/common/is.go → go/lib/is/is.go

@ -5,7 +5,7 @@ import (
"unicode" "unicode"
) )
func IsNumeric(s string) bool { func IsDigit(s string) bool {
for _, r := range s { for _, r := range s {
if !unicode.IsDigit(r) { if !unicode.IsDigit(r) {
return false return false

8
go/tests/any/main.go

@ -17,7 +17,7 @@ func any(f func(string) bool, arr []string) bool {
} }
func main() { func main() {
functions := []func(string) bool{common.IsNumeric, common.IsLower, common.IsUpper} functions := []func(string) bool{common.IsDigit, common.IsLower, common.IsUpper}
type node struct { type node struct {
f func(string) bool f func(string) bool
@ -35,7 +35,7 @@ func main() {
} }
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
table = append(table, node{ table = append(table, node{
f: common.IsNumeric, f: common.IsDigit,
a: lib.MultRandDigit(), a: lib.MultRandDigit(),
}) })
} }
@ -55,11 +55,11 @@ func main() {
table = append(table, table = append(table,
node{ node{
f: common.IsNumeric, f: common.IsDigit,
a: []string{"Hello", "how", "are", "you"}, a: []string{"Hello", "how", "are", "you"},
}, },
node{ node{
f: common.IsNumeric, f: common.IsDigit,
a: []string{"This", "is", "4", "you"}, a: []string{"This", "is", "4", "you"},
}, },
) )

8
go/tests/countif/main.go

@ -18,7 +18,7 @@ func countIf(f func(string) bool, arr []string) int {
} }
func main() { func main() {
functions := []func(string) bool{common.IsNumeric, common.IsLower, common.IsUpper} functions := []func(string) bool{common.IsDigit, common.IsLower, common.IsUpper}
type node struct { type node struct {
f func(string) bool f func(string) bool
@ -37,7 +37,7 @@ func main() {
} }
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
val := node{ val := node{
f: common.IsNumeric, f: common.IsDigit,
arr: lib.MultRandDigit(), arr: lib.MultRandDigit(),
} }
table = append(table, val) table = append(table, val)
@ -60,11 +60,11 @@ func main() {
table = append(table, table = append(table,
node{ node{
f: common.IsNumeric, f: common.IsDigit,
arr: []string{"Hello", "how", "are", "you"}, arr: []string{"Hello", "how", "are", "you"},
}, },
node{ node{
f: common.IsNumeric, f: common.IsDigit,
arr: []string{"This", "is", "4", "you"}, arr: []string{"This", "is", "4", "you"},
}, },
) )

2
go/tests/isnumeric/main.go

@ -33,6 +33,6 @@ func main() {
"01,02,03", "01,02,03",
) )
for _, arg := range table { for _, arg := range table {
lib.Challenge("IsNumeric", student.IsNumeric, common.IsNumeric, arg) lib.Challenge("IsNumeric", student.IsNumeric, common.IsDigit, arg)
} }
} }

Loading…
Cancel
Save