diff --git a/go/lib/is/is.go b/go/lib/is/is.go index 44dd64a3..a80df059 100644 --- a/go/lib/is/is.go +++ b/go/lib/is/is.go @@ -1,11 +1,11 @@ -package common +package is import ( "math/big" "unicode" ) -func IsDigit(s string) bool { +func Digit(s string) bool { for _, r := range s { if !unicode.IsDigit(r) { return false @@ -14,7 +14,7 @@ func IsDigit(s string) bool { return true } -func IsLower(s string) bool { +func Lower(s string) bool { for _, r := range s { if !unicode.IsLower(r) { return false @@ -23,7 +23,7 @@ func IsLower(s string) bool { return true } -func IsUpper(s string) bool { +func Upper(s string) bool { for _, r := range s { if !(r >= 'A' && r <= 'Z') { return false @@ -32,6 +32,6 @@ func IsUpper(s string) bool { return true } -func IsPrime(i int) bool { +func Prime(i int) bool { return big.NewInt(int64(i)).ProbablyPrime(0) } diff --git a/go/tests/any/main.go b/go/tests/any/main.go index 18f0ef98..7cfbd5a7 100644 --- a/go/tests/any/main.go +++ b/go/tests/any/main.go @@ -1,9 +1,9 @@ package main import ( - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func any(f func(string) bool, arr []string) bool { @@ -17,7 +17,7 @@ func any(f func(string) bool, arr []string) bool { } func main() { - functions := []func(string) bool{common.IsDigit, common.IsLower, common.IsUpper} + functions := []func(string) bool{is.Digit, is.Lower, is.Upper} type node struct { f func(string) bool @@ -35,31 +35,31 @@ func main() { } for i := 0; i < 5; i++ { table = append(table, node{ - f: common.IsDigit, + f: is.Digit, a: lib.MultRandDigit(), }) } for i := 0; i < 5; i++ { table = append(table, node{ - f: common.IsLower, + f: is.Lower, a: lib.MultRandLower(), }) } for i := 0; i < 5; i++ { table = append(table, node{ - f: common.IsUpper, + f: is.Upper, a: lib.MultRandUpper(), }) } table = append(table, node{ - f: common.IsDigit, + f: is.Digit, a: []string{"Hello", "how", "are", "you"}, }, node{ - f: common.IsDigit, + f: is.Digit, a: []string{"This", "is", "4", "you"}, }, ) diff --git a/go/tests/countif/main.go b/go/tests/countif/main.go index 8017fe25..6e1a2bde 100644 --- a/go/tests/countif/main.go +++ b/go/tests/countif/main.go @@ -1,9 +1,9 @@ package main import ( - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func countIf(f func(string) bool, arr []string) int { @@ -18,7 +18,7 @@ func countIf(f func(string) bool, arr []string) int { } func main() { - functions := []func(string) bool{common.IsDigit, common.IsLower, common.IsUpper} + functions := []func(string) bool{is.Digit, is.Lower, is.Upper} type node struct { f func(string) bool @@ -37,7 +37,7 @@ func main() { } for i := 0; i < 5; i++ { val := node{ - f: common.IsDigit, + f: is.Digit, arr: lib.MultRandDigit(), } table = append(table, val) @@ -45,14 +45,14 @@ func main() { for i := 0; i < 5; i++ { val := node{ - f: common.IsLower, + f: is.Lower, arr: lib.MultRandLower(), } table = append(table, val) } for i := 0; i < 5; i++ { val := node{ - f: common.IsUpper, + f: is.Upper, arr: lib.MultRandUpper(), } table = append(table, val) @@ -60,11 +60,11 @@ func main() { table = append(table, node{ - f: common.IsDigit, + f: is.Digit, arr: []string{"Hello", "how", "are", "you"}, }, node{ - f: common.IsDigit, + f: is.Digit, arr: []string{"This", "is", "4", "you"}, }, ) diff --git a/go/tests/findnextprime/main.go b/go/tests/findnextprime/main.go index 31bcf72d..dfc4a295 100644 --- a/go/tests/findnextprime/main.go +++ b/go/tests/findnextprime/main.go @@ -1,13 +1,13 @@ package main import ( - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func findNextPrime(nb int) int { - if common.IsPrime(nb) { + if is.Prime(nb) { return nb } return findNextPrime(nb + 1) diff --git a/go/tests/findprevprime/main.go b/go/tests/findprevprime/main.go index 58404d79..d1977323 100644 --- a/go/tests/findprevprime/main.go +++ b/go/tests/findprevprime/main.go @@ -1,16 +1,16 @@ package main import ( - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func findPrevPrime(nb int) int { if nb < 2 { return 0 } - if common.IsPrime(nb) { + if is.Prime(nb) { return nb } return findPrevPrime(nb - 1) diff --git a/go/tests/islower/main.go b/go/tests/islower/main.go index 4af520b9..46e3519b 100644 --- a/go/tests/islower/main.go +++ b/go/tests/islower/main.go @@ -1,9 +1,9 @@ package main import ( - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func main() { @@ -39,6 +39,6 @@ func main() { "hello!", ) for _, arg := range table { - lib.Challenge("IsLower", student.IsLower, common.IsLower, arg) + lib.Challenge("IsLower", student.IsLower, is.Lower, arg) } } diff --git a/go/tests/isnumeric/main.go b/go/tests/isnumeric/main.go index 3d3b4328..7cec8382 100644 --- a/go/tests/isnumeric/main.go +++ b/go/tests/isnumeric/main.go @@ -3,9 +3,9 @@ package main import ( "strconv" - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func main() { @@ -33,6 +33,6 @@ func main() { "01,02,03", ) for _, arg := range table { - lib.Challenge("IsNumeric", student.IsNumeric, common.IsDigit, arg) + lib.Challenge("IsNumeric", student.IsNumeric, is.Digit, arg) } } diff --git a/go/tests/isprime/main.go b/go/tests/isprime/main.go index 159d05da..f14c2c3d 100644 --- a/go/tests/isprime/main.go +++ b/go/tests/isprime/main.go @@ -1,9 +1,9 @@ package main import ( - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func main() { @@ -27,6 +27,6 @@ func main() { 1000000087, ) for _, arg := range table { - lib.Challenge("IsPrime", student.IsPrime, common.IsPrime, arg) + lib.Challenge("IsPrime", student.IsPrime, is.Prime, arg) } } diff --git a/go/tests/isupper/main.go b/go/tests/isupper/main.go index 01bf963a..7cb29942 100644 --- a/go/tests/isupper/main.go +++ b/go/tests/isupper/main.go @@ -1,9 +1,9 @@ package main import ( - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func main() { @@ -41,6 +41,6 @@ func main() { "HELLO!", ) for _, arg := range table { - lib.Challenge("IsUpper", student.IsUpper, common.IsUpper, arg) + lib.Challenge("IsUpper", student.IsUpper, is.Upper, arg) } } diff --git a/go/tests/map/main.go b/go/tests/map/main.go index 758f74e1..444da880 100644 --- a/go/tests/map/main.go +++ b/go/tests/map/main.go @@ -1,9 +1,9 @@ package main import ( - "../common" "./student" "github.com/01-edu/public/go/lib" + "github.com/01-edu/public/go/lib/is" ) func isPositive(i int) bool { @@ -25,7 +25,7 @@ func _map(f func(int) bool, a []int) []bool { } func main() { - functions := []func(int) bool{isPositive, isNegative0, common.IsPrime} + functions := []func(int) bool{isPositive, isNegative0, is.Prime} type node struct { f func(int) bool @@ -44,7 +44,7 @@ func main() { } table = append(table, node{ - f: common.IsPrime, + f: is.Prime, arr: []int{1, 2, 3, 4, 5, 6}, })