-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mathlib.py
42 lines (33 loc) · 1.46 KB
/
test_mathlib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from mathlib import primes, factorize
def test_primes():
assert [el for el in primes(0)] == []
assert [el for el in primes(1)] == []
assert [el for el in primes(2)] == []
assert [el for el in primes(3)] == [2]
assert [el for el in primes(5)] == [2, 3]
assert [el for el in primes(10)] == [2, 3, 5, 7]
assert [el for el in primes(maximum=0)] == []
assert [el for el in primes(maximum=1)] == []
assert [el for el in primes(maximum=2)] == []
assert [el for el in primes(maximum=3)] == [2]
assert [el for el in primes(maximum=5)] == [2, 3]
assert [el for el in primes(maximum=10)] == [2, 3, 5, 7]
assert len([el for el in primes(nb_max=0)]) == 0
assert len([el for el in primes(nb_max=1)]) == 1
assert len([el for el in primes(nb_max=2)]) == 2
assert len([el for el in primes(nb_max=3)]) == 3
assert len([el for el in primes(nb_max=5)]) == 5
assert len([el for el in primes(nb_max=10)]) == 10
assert [el for el in primes(maximum=10, nb_max=2)] == [2, 3]
assert [el for el in primes(maximum=3, nb_max=100)] == [2]
assert [el for el in primes(nb_max=10001)][-1] == 104743
def test_factorize():
assert factorize(5) == [5]
assert factorize(25) == [5, 5]
assert factorize(125) == [5, 5, 5]
assert factorize(360) == [2, 2, 2, 3, 3, 5]
assert factorize(1001) == [7, 11, 13]
assert factorize(1010021) == [17, 19, 53, 59]
if __name__ == '__main__':
test_primes()
test_factorize()