feat: Add more packages.
There are two packages in the module.
This commit is contained in:
parent
c378329803
commit
8af8fe0979
13
num/num.go
Normal file
13
num/num.go
Normal file
@ -0,0 +1,13 @@
|
||||
package num
|
||||
|
||||
func IsPrime(n int) bool {
|
||||
if n <= 1 {
|
||||
return false;
|
||||
}
|
||||
for i := 2; i < n; i++ {
|
||||
if n % i == 0 {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
24
num/num_test.go
Normal file
24
num/num_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
package num
|
||||
|
||||
import "testing"
|
||||
|
||||
type checklist struct {
|
||||
n int;
|
||||
ret bool;
|
||||
}
|
||||
|
||||
func TestNum(t *testing.T) {
|
||||
list := []checklist{
|
||||
{2, true},
|
||||
{3, true},
|
||||
{4, false},
|
||||
{57, false},
|
||||
{97, true},
|
||||
}
|
||||
|
||||
for _, item := range list {
|
||||
if item.ret != IsPrime(item.n) {
|
||||
t.Errorf("n: %v faild, want %v", item.n, item.ret)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user