Jupyter Notebook Viewer

2 min read Original article ↗
def tests():
    assert make_Apowers(6, 10) == {
         1: [1],
         2: [8, 16, 32, 128],
         3: [27, 81, 243, 2187],
         4: [64, 256, 1024, 16384],
         5: [125, 625, 3125, 78125],
         6: [216, 1296, 7776, 279936]}
    
    assert make_Czroots(make_Apowers(5, 8)) == {
        1: 1, 8: 2, 16: 2, 27: 3, 32: 2, 64: 4, 81: 3,
        125: 5, 128: 2, 243: 3, 256: 4, 625: 5, 1024: 4,
        2187: 3, 3125: 5, 16384: 4, 78125: 5}
    Czroots = make_Czroots(make_Apowers(100, 100))
    assert 3 ** 3 + 6 ** 3 in Czroots
    assert 99 ** 97 in Czroots
    assert 101 ** 100 not in Czroots
    assert Czroots[99 ** 97] == 99
    
    assert exponent(10 ** 5, 10) == 5
    assert exponent(7 ** 3, 7) == 3
    assert exponent(1234 ** 999, 1234) == 999
    assert exponent(12345 ** 6789, 12345) == 6789
    assert exponent(3 ** 10000, 3) == 10000
    assert exponent(1, 1) == 3
    
    assert exponents_upto(2) == []
    assert exponents_upto(3) == [3]
    assert exponents_upto(4) == [3, 4]
    assert exponents_upto(40) == [3, 4, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    assert exponents_upto(100) == [
        3, 4, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 
        67, 71, 73, 79, 83, 89, 97]
    
    assert gcd(3, 6) == 3
    assert gcd(3, 7) == 1
    assert gcd(861591083269373931, 94815872265407) == 97
    assert gcd(2*3*5*(7**10)*(11**12), 3*(7**5)*(11**13)*17) == 3*(7**5)*(11**12)
    
    return 'tests pass'
    
tests()