Debian Codegraph @

reports/st/st_number.li

raw
1 /*
2 * @progname st_number.li
3 * @version 1.0
4 * @author Perry Rapp
5 * @category self-test
6 * @output none
7 * @description
8 *
9 * validate numeric functions
10 *
11 */
12
13 char_encoding("ASCII")
14
15 require("lifelines-reports.version:1.3")
16 option("explicitvars") /* Disallow use of undefined variables */
17 include("st_aux")
18
19 /* entry point in case not invoked via st_all.ll */
20 proc main()
21 {
22 call testNums()
23 }
24
25 /*
26 test some numeric functions
27 */
28 proc testNums()
29 {
30 set(testok, 0)
31 set(testfail, 0)
32
33 set(one,1)
34 set(two,add(one,one))
35 if (ne(two,2)) {
36 call reportfail("1+1 FAILED")
37 }
38 else { incr(testok) }
39
40 if (eq(two,one)) {
41 call reportfail("1==2 FAILED")
42 }
43 else { incr(testok) }
44
45 if (ne(add(two,two,two,two,two),10)) {
46 call reportfail("2+2+2+2+2 FAILED")
47 }
48 else { incr(testok) }
49
50 if (ne(sub(two,one),1)) {
51 call reportfail("2-1 FAILED")
52 }
53 else { incr(testok) }
54
55 if (ne(sub(890,30),860)) {
56 call reportfail("890-30 FAILED")
57 }
58 else { incr(testok) }
59
60 if (ne(mul(3,4),12)) {
61 call reportfail("3*4 FAILED")
62 }
63 else { incr(testok) }
64
65 if (ne(mul(3,-4),-12)) {
66 call reportfail("3*(-4) FAILED")
67 }
68 else { incr(testok) }
69
70 if (ne(mul(-3,-4),12)) {
71 call reportfail("(-3)*(-4) FAILED")
72 }
73 else { incr(testok) }
74
75 if (ne(mul(.5,.5),.25)) {
76 call reportfail(".5*.5 FAILED")
77 }
78 else { incr(testok) }
79
80 if (ne(mul(2,.5),1)) {
81 call reportfail("2*.5 FAILED")
82 }
83 else { incr(testok) }
84
85 if (gt(.5, .7)) {
86 call reportfail(".5>.7 FAILED")
87 }
88 else { incr(testok) }
89
90 if (lt(-.4,-.5)) {
91 call reportfail("-.4<-.5 FAILED")
92 }
93 else { incr(testok) }
94
95 if (ge(15,18)) {
96 call reportfail("15>=18 FAILED")
97 }
98 else { incr(testok) }
99
100 if (le(-.4,-.5)) {
101 call reportfail("-.4<=-.5 FAILED")
102 }
103 else { incr(testok) }
104
105 if (not(le(-.4,-.4))) {
106 call reportfail("-.4<=-.4 FAILED")
107 }
108 else { incr(testok) }
109
110 if (not(le(-1,-.4))) {
111 call reportfail("-1<=-.4 FAILED")
112 }
113 else { incr(testok) }
114
115 if (not(le(-1.1,-1))) {
116 call reportfail("-1.1<=-1 FAILED")
117 }
118 else { incr(testok) }
119
120 if (ne(div(20, 4), 5)) {
121 call reportfail("20/4==5 FAILED")
122 }
123 else { incr(testok) }
124
125 if (ne(mod(22, 7), 1)) {
126 call reportfail("22 % 7==1 FAILED")
127 }
128 else { incr(testok) }
129
130 if (ne(exp(2, 10), 1024)) {
131 call reportfail("2 ^10 ==1024 FAILED")
132 }
133 else { incr(testok) }
134
135 if (ne(exp(.5, 2), .25)) {
136 call reportfail(".5 ^2 ==.25 FAILED")
137 }
138 else { incr(testok) }
139
140 set(bubba,34)
141 incr(bubba)
142 if (ne(bubba,35)) {
143 call reportfail("incr(34) == 35 FAILED")
144 }
145 else { incr(testok) }
146
147 set(bubba,45)
148 decr(bubba)
149 if (ne(bubba,44)) {
150 call reportfail("decr(45) == 44 FAILED")
151 }
152 else { incr(testok) }
153
154 set(bubba,45.3)
155 decr(bubba)
156 if (ne(bubba,44.3)) {
157 call reportfail("decr(45.3) == 44.3 FAILED")
158 }
159 else { incr(testok) }
160
161 set(bubba,34.3)
162 incr(bubba)
163 if (ne(bubba,35.3)) {
164 call reportfail("incr(34.3) == 35.3 FAILED")
165 }
166 else { incr(testok) }
167
168 set(bubba,45.6)
169 decr(bubba)
170 if (ne(bubba,44.6)) {
171 call reportfail("decr(45.6) == 44.6 FAILED")
172 }
173 else { incr(testok) }
174
175 if (ne(neg(52), -52)) {
176 call reportfail("neg(52) == -52 FAILED")
177 }
178 else { incr(testok) }
179
180 call reportSubsection("number tests")
181 }
182