summaryrefslogtreecommitdiff
path: root/Examples/test-suite/python/contract_runme.py
blob: 8bfda8930766ec65fdc1e24f933d179be8ab710b (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import contract

contract.test_preassert(1, 2)
try:
    contract.test_preassert(-1, 3)
    print "Failed! Preassertions are broken"
except RuntimeError:
    pass

contract.test_postassert(3)
try:
    contract.test_postassert(-3)
    print "Failed! Postassertions are broken"
except RuntimeError:
    pass

contract.test_prepost(2, 3)
contract.test_prepost(5, -4)
try:
    contract.test_prepost(-3, 4)
    print "Failed! Preassertions are broken"
except RuntimeError:
    pass

try:
    contract.test_prepost(4, -10)
    print "Failed! Postassertions are broken"

except RuntimeError:
    pass

f = contract.Foo()
f.test_preassert(4, 5)
try:
    f.test_preassert(-2, 3)
    print "Failed! Method preassertion."
except RuntimeError:
    pass

f.test_postassert(4)
try:
    f.test_postassert(-4)
    print "Failed! Method postassertion"
except RuntimeError:
    pass

f.test_prepost(3, 4)
f.test_prepost(4, -3)
try:
    f.test_prepost(-4, 2)
    print "Failed! Method preassertion."
except RuntimeError:
    pass

try:
    f.test_prepost(4, -10)
    print "Failed! Method postassertion."
except RuntimeError:
    pass

contract.Foo_stest_prepost(4, 0)
try:
    contract.Foo_stest_prepost(-4, 2)
    print "Failed! Static method preassertion"
except RuntimeError:
    pass

try:
    contract.Foo_stest_prepost(4, -10)
    print "Failed! Static method posteassertion"
except RuntimeError:
    pass

b = contract.Bar()
try:
    b.test_prepost(2, -4)
    print "Failed! Inherited preassertion."
except RuntimeError:
    pass


d = contract.D()
try:
    d.foo(-1, 1, 1, 1, 1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass
try:
    d.foo(1, -1, 1, 1, 1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass
try:
    d.foo(1, 1, -1, 1, 1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass
try:
    d.foo(1, 1, 1, -1, 1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass
try:
    d.foo(1, 1, 1, 1, -1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass


try:
    d.bar(-1, 1, 1, 1, 1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass
try:
    d.bar(1, -1, 1, 1, 1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass
try:
    d.bar(1, 1, -1, 1, 1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass
try:
    d.bar(1, 1, 1, -1, 1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass
try:
    d.bar(1, 1, 1, 1, -1)
    print "Failed! Inherited preassertion (D)."
except RuntimeError:
    pass

# Namespace
my = contract.myClass(1)
try:
    my = contract.myClass(0)
    print "Failed! constructor preassertion"
except RuntimeError:
    pass