-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·31 lines (23 loc) · 1.04 KB
/
test.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
#!/usr/bin/env python3
"""Unit tests"""
import unittest
from batch_gcd import products, remainders, batch_gcd
class TestFactHack(unittest.TestCase):
"""FactHack test cases"""
def test_product_tree_small_sequence(self) -> None:
"""Calculate a product tree"""
seq = [10, 20, 30, 40, 50, 60]
tree = products(*seq)
self.assertEqual(tree, [[10, 20, 30, 40, 50, 60], [200, 1200, 3000],
[240000, 3000], [720000000]])
def test_remainder_small_sequence(self) -> None:
"""Calculate a remainder sequence"""
remainder_seq = remainders(8675309, products(11, 13, 17, 19, 23))
self.assertEqual(remainder_seq, [5, 6, 5, 4, 8])
def test_batch_gcd_small_sequence(self) -> None:
"""Perform batch GCD on a small sequence"""
seq = [1909, 2923, 291, 205, 989, 62, 451, 1943, 1079, 2419]
gs = batch_gcd(*seq)
self.assertEqual(gs, [1909, 1, 1, 41, 23, 1, 41, 1, 83, 41])
if __name__ == "__main__":
unittest.main(verbosity=2, buffer=True)