feat: Add more packages.

There are two packages in the module.
This commit is contained in:
Yuki 2025-06-14 11:41:04 +08:00
parent c378329803
commit 8af8fe0979
Signed by: yuki
GPG Key ID: 0E266240CCAD7A90
4 changed files with 37 additions and 0 deletions

13
num/num.go Normal file
View 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
View 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)
}
}
}