templates.test_fixed_point

 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_fixed_point(self):
12            assert fp.mk((123, 2)) == sp.record(value=sp.int(123), exponent=2)
13
14        @sp.private
15        def test_add(self):
16            v1 = fp.mk((123, 2))
17            v2 = fp.mk((245, 2))
18            assert fp.add((v1, v2)) == sp.record(value=sp.int(368), exponent=2)
19
20        @sp.private
21        def test_sub(self):
22            v1 = fp.mk((245, 2))
23            v2 = fp.mk((123, 2))
24            assert fp.sub((v1, v2)) == sp.record(value=sp.int(122), exponent=2)
25
26        @sp.private
27        def test_mul(self):
28            v1 = fp.mk((123, 3))
29            v2 = fp.mk((25, 1))
30            assert fp.mul((v1, v2)) == sp.record(value=sp.int(3075), exponent=4)
31
32        @sp.private
33        def test_eq(self):
34            v1 = fp.mk((123, 3))
35            v2 = fp.mk((25, 3))
36            v3 = fp.mk((25, 3))
37            assert not fp.eq((v1, v2))
38            assert fp.eq((v2, v3))
39
40        @sp.private
41        def test_lt(self):
42            v1 = fp.mk((123, 3))
43            v2 = fp.mk((25, 3))
44            v3 = fp.mk((25, 3))
45            assert not fp.lt((v1, v2))
46            assert not fp.lt((v2, v3))
47            assert fp.lt((v2, v1))
48            assert fp.lt((v3, v1))
49
50        @sp.private
51        def test_gt(self):
52            v1 = fp.mk((123, 3))
53            v2 = fp.mk((25, 3))
54            v3 = fp.mk((25, 3))
55            assert fp.gt((v1, v2))
56            assert not fp.gt((v2, v3))
57            assert not fp.gt((v2, v1))
58            assert not fp.gt((v3, v1))
59
60        @sp.entrypoint
61        def ep(self):
62            self.test_fixed_point()
63            self.test_add()
64            self.test_sub()
65            self.test_mul()
66            self.test_eq()
67            self.test_lt()
68            self.test_gt()
69
70
71@sp.add_test()
72def test():
73    s = sp.test_scenario("Test", [sp.fp, M])
74    c = M.C()
75    s += c
76    c.ep()