templates.test_div

 1# Div - Example for illustrative purposes only.
 2
 3import smartpy as sp
 4
 5
 6@sp.module
 7def main():
 8    class TestDiv(sp.Contract):
 9        def __init__(self):
10            self.data.a = None
11            self.data.b = None
12            self.data.c = None
13            self.data.d = None
14            self.data.e = None
15            self.data.f = None
16            self.data.g = None
17            self.data.h = None
18            self.data.i = None
19            self.data.j = None
20            self.data.k = None
21            self.data.l = None
22            self.data.m = None
23
24        @sp.entrypoint
25        def test(self, params):
26            self.data.a = sp.ediv(1, 0)
27            self.data.b = sp.ediv(-1, 0)
28            self.data.c = sp.ediv(1, 12)
29            self.data.d = sp.ediv(-1, 12)
30            self.data.e = sp.ediv(-1, -12)
31            self.data.f = sp.ediv(15, 12)
32            self.data.g = sp.ediv(-15, 12)
33            self.data.h = sp.ediv(-15, -12)
34            self.data.i = sp.ediv(sp.tez(2), sp.mutez(100))
35            self.data.j = sp.ediv(sp.tez(2), sp.mutez(101))
36            self.data.k = sp.ediv(sp.tez(2), sp.tez(100))
37            self.data.l = sp.ediv(sp.tez(2), 15)
38            self.data.m = sp.ediv(sp.amount, sp.cast(params, sp.nat))
39
40
41@sp.add_test()
42def test():
43    scenario = sp.test_scenario("Div", main)
44    c1 = main.TestDiv()
45    scenario.h1("Division")
46    scenario += c1
47    c1.test(2000, _amount=sp.tez(2))
48    scenario.show(c1.data)
49    scenario.verify_equal(
50        c1.data,
51        sp.record(
52            a=None,
53            b=None,
54            c=sp.Some((0, 1)),
55            d=sp.Some((-1, 11)),
56            e=sp.Some((1, 11)),
57            f=sp.Some((1, 3)),
58            g=sp.Some((-2, 9)),
59            h=sp.Some((2, 9)),
60            i=sp.Some((20000, sp.tez(0))),
61            j=sp.Some((19801, sp.mutez(99))),
62            k=sp.Some((0, sp.tez(2))),
63            l=sp.Some((sp.mutez(133333), sp.mutez(5))),
64            m=sp.Some((sp.mutez(1000), sp.tez(0))),
65        ),
66    )