From 8af8fe09797927de1b5fb2d8c398cffa03b9f20e Mon Sep 17 00:00:00 2001 From: Yuki Date: Sat, 14 Jun 2025 11:41:04 +0800 Subject: [PATCH] feat: Add more packages. There are two packages in the module. --- hello.go => hello/hello.go | 0 hello_test.go => hello/hello_test.go | 0 num/num.go | 13 +++++++++++++ num/num_test.go | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+) rename hello.go => hello/hello.go (100%) rename hello_test.go => hello/hello_test.go (100%) create mode 100644 num/num.go create mode 100644 num/num_test.go diff --git a/hello.go b/hello/hello.go similarity index 100% rename from hello.go rename to hello/hello.go diff --git a/hello_test.go b/hello/hello_test.go similarity index 100% rename from hello_test.go rename to hello/hello_test.go diff --git a/num/num.go b/num/num.go new file mode 100644 index 0000000..c035ea3 --- /dev/null +++ b/num/num.go @@ -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; +} diff --git a/num/num_test.go b/num/num_test.go new file mode 100644 index 0000000..52db523 --- /dev/null +++ b/num/num_test.go @@ -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) + } + } +}