File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77- [ Max] ( math/max.jule )
88- [ Median] ( math/median.jule )
99- [ Min] ( math/min.jule )
10+ - [ Prime] ( math/prime.jule )
1011- [ Q Rsqrt] ( math/q_rsqrt.jule )
1112- [ Sum] ( math/sum.jule )
1213
Original file line number Diff line number Diff line change 1+ fn CheckPrime(n: int): bool {
2+ if n <= 1 {
3+ return false
4+ }
5+ if n == 2 {
6+ return true
7+ }
8+ if n%2 == 0 {
9+ return false
10+ }
11+
12+ let mut i = 3
13+ for i*i <= n {
14+ if n%i == 0 {
15+ return false
16+ }
17+ i += 2
18+ }
19+ return true
20+ }
Original file line number Diff line number Diff line change 1+ #build test
2+
3+ use "std/testing"
4+
5+ #test
6+ fn testCheckPrime(t: &testing::T) {
7+ t.Assert(!CheckPrime(-7), "-7 should not be prime")
8+ t.Assert(!CheckPrime(0), "0 should not be prime")
9+ t.Assert(!CheckPrime(1), "1 should not be prime")
10+ t.Assert(CheckPrime(2), "2 should be prime")
11+ t.Assert(CheckPrime(3), "3 should be prime")
12+ t.Assert(!CheckPrime(4), "4 should not be prime")
13+ t.Assert(CheckPrime(97), "97 should be prime")
14+ t.Assert(!CheckPrime(100), "100 should not be prime")
15+ }
You can’t perform that action at this time.
0 commit comments