Skip to content

Commit 637da5b

Browse files
authored
add tests
1 parent 58b393c commit 637da5b

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/runtests.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Test
2+
3+
@testset "iroot" begin
4+
for T in (Int32, Int64, BigInt)
5+
@test iroot(T(100), 2) === T(10)
6+
@test iroot(T(101), 2) === T(10)
7+
@test iroot(T(99), 2) === T(9)
8+
@test iroot(T(1000), 3) === T(10)
9+
@test iroot(T(1001), 3) === T(10)
10+
@test iroot(T(999), 3) === T(9)
11+
@test iroot(T(10000), 4) === T(10)
12+
@test iroot(T(10001), 4) === T(10)
13+
@test iroot(T(9999), 4) === T(9)
14+
end
15+
@test iroot(big(23)^50, 50) === big(23)
16+
@test iroot(big(23)^50 + 1, 50) === big(23)
17+
@test iroot(big(23)^50 - 1, 50) === big(22)
18+
end
19+
20+
@testset "ispower" begin
21+
for T in (Int32, Int64, BigInt)
22+
@test ispower(T(100)) == true
23+
@test ispower(T(1)) == true
24+
@test ispower(T(0)) == true
25+
@test ispower(T(12)) == false
26+
@test ispower(T(2^30)) == true
27+
@test ispower(T(5)^10) == true
28+
@test ispower(T(2^30)+1) == false
29+
@test ispower(T(5)^10+1) == false
30+
end
31+
@test ispower(big(5)^40) == true
32+
@test ispower(big(5)^40 + 1) == false
33+
@test ispower(6 * big(5)^40) == false
34+
end
35+
36+
@testset "find_exponent" begin
37+
for T in (Int32, Int64, BigInt)
38+
@test ispower(T(100)) === (T(10), 2)
39+
@test ispower(T(1)) === (T(1), 1)
40+
@test ispower(T(0)) === (T(0), 1)
41+
@test ispower(T(12)) === (T(12), 1)
42+
@test ispower(T(2^30)) === (T(2), 30)
43+
@test ispower(T(5)^10) === (T(5), 10)
44+
@test ispower(T(2^30)+1) === (T(2^30+1), 1)
45+
@test ispower(T(5)^10+1) === (T(5^10+1), 1)
46+
end
47+
@test ispower(big(5)^40) === (big(5), 30)
48+
@test ispower(big(5)^40 + 1) === (big(5)^40 + 1, 1)
49+
@test ispower(6*big(5)^40 ) === (6 * big(5)^40, 1)
50+
end
51+
52+
@testset "is_probably_prime" begin
53+
for T in (Int32, Int64, BigInt)
54+
@test is_probably_prime(T(2)^7-1) == true
55+
@test is_probably_prime(T(2)^13-1) == true
56+
@test is_probably_prime(T(2)^31-1) == true
57+
@test is_probably_prime(T(2)^27-1) == false
58+
@test is_probably_prime(T(2)^23-1) == false
59+
@test is_probably_prime(T(2)^30-1) == false
60+
end
61+
@test is_probably_prime(big(2)^127-1) == true
62+
@test is_probably_prime(big(2)^128-1) == false

0 commit comments

Comments
 (0)