templates.test_math

 1import smartpy as sp
 2
 3
 4@sp.module
 5def M():
 6    class C(sp.Contract):
 7        def __init__(self):
 8            pass
 9
10        @sp.private
11        def test_pow(self):
12            assert math.pow((2, 0)) == sp.int(1)
13            assert math.pow((2, 1)) == sp.int(2)
14            assert math.pow((2, 3)) == sp.int(8)
15            assert math.pow((3, 0)) == sp.int(1)
16            assert math.pow((3, 1)) == sp.int(3)
17            assert math.pow((3, 2)) == sp.int(9)
18            assert math.pow((3, 3)) == sp.int(27)
19            assert math.pow((10, 0)) == sp.int(1)
20            assert math.pow((10, 1)) == sp.int(10)
21            assert math.pow((10, 2)) == sp.int(100)
22            assert math.pow((10, 3)) == sp.int(1000)
23
24        @sp.private
25        def test_gcd(self):
26            assert math.gcd((15, 10)) == sp.int(5)
27            assert math.gcd((18, 42)) == sp.int(6)
28            assert math.gcd((15, 36)) == sp.int(3)
29            assert math.gcd((4, 24)) == sp.int(4)
30            assert math.gcd((-4, 24)) == sp.int(4)
31
32        @sp.private
33        def test_lcm(self):
34            assert math.lcm((3, 5)) == sp.int(15)
35            assert math.lcm((54, 24)) == sp.int(216)
36
37        @sp.entrypoint
38        def ep(self):
39            self.test_pow()
40            self.test_gcd()
41            self.test_lcm()
42
43
44@sp.add_test()
45def test():
46    s = sp.test_scenario("Test", [sp.math, M])
47    c = M.C()
48    s += c
49    c.ep()