Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
3abe9331 | 2 | * Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | ******************************************************************************/ | |
8 | module TtemplateFloat { | |
9 | type component templateFloat_mycomp {}; | |
10 | type record templateFloat_rec { | |
11 | float x1, | |
12 | float x2, | |
13 | float x3 optional }; | |
14 | template templateFloat_rec templateFloat_tSpec :={ //specific values | |
15 | x1:=1.1, | |
16 | x2:=2.1, | |
17 | x3:=3.1 }; | |
18 | template templateFloat_rec templateFloat_tList :={ //specific value and value list | |
19 | x1:=1.1, | |
20 | x2:=(2.1,3.1,6.1), | |
21 | x3:=3.1 }; | |
22 | template templateFloat_rec templateFloat_tComp :={ //specific value and compl. list | |
23 | x1:=1.1, | |
24 | x2:=complement (2.1,3.1,6.1), | |
25 | x3:=3.1 }; | |
26 | template templateFloat_rec templateFloat_tOmit :={ //omitting values | |
27 | x1:=1.1, | |
28 | x2:=2.1, | |
29 | x3:=omit } ; | |
30 | template templateFloat_rec templateFloat_tAny :={ //specific and any value | |
31 | x1:=1.1, | |
32 | x2:=2.1, | |
33 | x3:=? } ; | |
34 | template templateFloat_rec templateFloat_tAnyorNone :={ //specific and AnyorNone value | |
35 | x1:=1.1, | |
36 | x2:=2.1, | |
37 | x3:=* }; | |
38 | template templateFloat_rec templateFloat_tRange1 :={ //specific value and Range | |
39 | x1:=1.1, | |
40 | x2:=(2.1 ..4.1), | |
41 | x3:=3.1 }; | |
42 | template templateFloat_rec templateFloat_tRange2 :={ //specific value and Range | |
43 | x1:=1.1, | |
44 | x2:=(2.1 .. 4.1), | |
45 | x3:=3.1 }; | |
46 | template templateFloat_rec templateFloat_tRange3 :={ //specific value and Range | |
47 | x1:=1.1, | |
48 | x2:=(2.1 .. infinity), | |
49 | x3:=3.1 }; | |
50 | template templateFloat_rec templateFloat_tRange4 :={ //specific value and Range | |
51 | x1:=1.1, | |
52 | x2:=(-infinity .. 4.1), | |
53 | x3:=3.1 }; | |
54 | template templateFloat_rec templateFloat_tIfpresent :={ //specific value and ifpresent | |
55 | x1:=1.1, | |
56 | x2:=2.1, | |
57 | x3:=3.1 ifpresent }; | |
3abe9331 | 58 | |
59 | template float templateFloat_tNaN := not_a_number; | |
60 | template float templateFloat_tPosInf := infinity; | |
61 | template float templateFloat_tNegInf := -infinity; | |
970ed795 EL |
62 | |
63 | testcase templateFloatSpec() runs on templateFloat_mycomp { | |
64 | var templateFloat_rec x1,x2; //specific value | |
65 | x1:={ x1:=1.1, x2:=2.1, x3:=3.1 }; | |
66 | x2:={ x1:=2.1, x2:=2.1, x3:=3.1 }; | |
67 | //match | |
68 | if (match(x1,templateFloat_tSpec)) {setverdict(pass);} | |
69 | else {setverdict(fail);} | |
70 | //no match | |
71 | if (not(match(x2,templateFloat_tSpec))) {setverdict(pass);} | |
72 | else {setverdict(fail);} | |
73 | } | |
74 | ||
75 | testcase templateFloatList() runs on templateFloat_mycomp { | |
76 | var templateFloat_rec x1,x2,x3; //value list | |
77 | x1:={ x1:=1.1, x2:=6.1, x3:=3.1 }; | |
78 | x2:={ x1:=1.1, x2:=7.1, x3:=3.1 }; | |
79 | x3:={ x1:=2.1, x2:=6.1, x3:=3.1 }; | |
80 | //match | |
81 | if (match(x1,templateFloat_tList)) {setverdict(pass);} | |
82 | else {setverdict(fail);} | |
83 | //no match: out of list | |
84 | if (not(match(x2,templateFloat_tList))) {setverdict(pass);} | |
85 | else {setverdict(fail);} | |
86 | //no match: other field | |
87 | if (not(match(x3,templateFloat_tList))) {setverdict(pass);} | |
88 | else {setverdict(fail);} | |
89 | } | |
90 | ||
91 | testcase templateFloatComp() runs on templateFloat_mycomp { | |
92 | var templateFloat_rec x1,x2,x3; //complemented list | |
93 | x1:={ x1:=1.1, x2:=7.1, x3:=3.1 }; | |
94 | x2:={ x1:=1.1, x2:=6.1, x3:=3.1 }; | |
95 | x3:={ x1:=2.1, x2:=7.1, x3:=3.1 }; | |
96 | //match | |
97 | if (match(x1,templateFloat_tComp)) {setverdict(pass);} | |
98 | else {setverdict(fail);} | |
99 | //no match: in the list | |
100 | if (not(match(x2,templateFloat_tComp))) {setverdict(pass);} | |
101 | else {setverdict(fail);} | |
102 | //no match: other field | |
103 | if (not(match(x3,templateFloat_tComp))) {setverdict(pass);} | |
104 | else {setverdict(fail);} | |
105 | } | |
106 | ||
107 | testcase templateFloatOmit() runs on templateFloat_mycomp { | |
108 | var templateFloat_rec x1,x2,x3; //omitting value | |
109 | x1:={ x1:=1.1, x2:=2.1, x3:=omit }; | |
110 | x2:={ x1:=1.1, x2:=2.1, x3:=3.1 }; | |
111 | x3:={ x1:=2.1, x2:=2.1, x3:=omit }; | |
112 | //match | |
113 | if (match(x1,templateFloat_tOmit)) {setverdict(pass);} | |
114 | else {setverdict(fail);} | |
115 | //no match: not omitted | |
116 | if (not(match(x2,templateFloat_tOmit))) {setverdict(pass);} | |
117 | else {setverdict(fail);} | |
118 | //no match: other field | |
119 | if (not(match(x3,templateFloat_tOmit))) {setverdict(pass);} | |
120 | else {setverdict(fail);} | |
121 | } | |
122 | ||
123 | testcase templateFloatAny() runs on templateFloat_mycomp { | |
124 | var templateFloat_rec x1,x2,x3; //any value | |
125 | x1:={ x1:=1.1, x2:=2.1, x3:=3.1 }; | |
126 | x2:={ x1:=1.1, x2:=2.1, x3:=omit }; | |
127 | x3:={ x1:=2.1, x2:=2.1, x3:=3.1 }; | |
128 | //match | |
129 | if (match(x1,templateFloat_tAny)) {setverdict(pass);} | |
130 | else {setverdict(fail);} | |
131 | //no match: field omitted | |
132 | if (not(match(x2,templateFloat_tAny))) {setverdict(pass);} | |
133 | else {setverdict(fail);} | |
134 | //no match: other field | |
135 | if (not(match(x3,templateFloat_tAny))) {setverdict(pass);} | |
136 | else {setverdict(fail);} | |
137 | } | |
138 | ||
139 | testcase templateFloatAnyorNone() runs on templateFloat_mycomp { | |
140 | var templateFloat_rec x1,x2,x3; //AnyorNone value | |
141 | x1:={ x1:=1.1, x2:=2.1, x3:=omit }; | |
142 | x2:={ x1:=1.1, x2:=2.1, x3:=3.1 }; | |
143 | x3:={ x1:=2.1, x2:=2.1, x3:=omit }; | |
144 | //match: omitted | |
145 | if (match(x1,templateFloat_tAnyorNone)) {setverdict(pass);} | |
146 | else {setverdict(fail);} | |
147 | //match: value | |
148 | if (match(x2,templateFloat_tAnyorNone)) {setverdict(pass);} | |
149 | else {setverdict(fail);} | |
150 | //no match: other field | |
151 | if (not(match(x3,templateFloat_tAnyorNone))) {setverdict(pass);} | |
152 | else {setverdict(fail);} | |
153 | } | |
154 | ||
155 | testcase templateFloatRange1() runs on templateFloat_mycomp { | |
156 | var templateFloat_rec x1,x2,x3; //Range ( .. ) | |
157 | x1:={ x1:=1.1, x2:=2.1, x3:=3.1 }; | |
158 | x2:={ x1:=1.1, x2:=5.1, x3:=3.1 }; | |
159 | x3:={ x1:=2.1, x2:=2.1, x3:=3.1 }; | |
160 | //match | |
161 | if (match(x1,templateFloat_tRange1)) {setverdict(pass);} | |
162 | else {setverdict(fail);} | |
163 | //no match: out of range | |
164 | if (not(match(x2,templateFloat_tRange1))) {setverdict(pass);} | |
165 | else {setverdict(fail);} | |
166 | //no match: other field | |
167 | if (not(match(x3,templateFloat_tRange1))) {setverdict(pass);} | |
168 | else {setverdict(fail);} | |
169 | } | |
170 | ||
171 | testcase templateFloatRange2() runs on templateFloat_mycomp { | |
172 | var templateFloat_rec x1,x2,x3; //Range ( to ) | |
173 | x1:={ x1:=1.1, x2:=2.1, x3:=3.1 }; | |
174 | x2:={ x1:=1.1, x2:=5.1, x3:=3.1 }; | |
175 | x3:={ x1:=2.1, x2:=2.1, x3:=3.1 }; | |
176 | //match | |
177 | if (match(x1,templateFloat_tRange2)) {setverdict(pass);} | |
178 | else {setverdict(fail);} | |
179 | //no match: out of range | |
180 | if (not(match(x2,templateFloat_tRange2))) {setverdict(pass);} | |
181 | else {setverdict(fail);} | |
182 | //no match: other field | |
183 | if (not(match(x3,templateFloat_tRange2))) {setverdict(pass);} | |
184 | else {setverdict(fail);} | |
185 | } | |
186 | ||
187 | testcase templateFloatRange3() runs on templateFloat_mycomp { | |
188 | var templateFloat_rec x1,x2,x3; //Range, with infinity | |
189 | x1:={ x1:=1.1, x2:=8.1, x3:=3.1 }; | |
190 | x2:={ x1:=1.1, x2:=-5.1, x3:=3.1 }; | |
191 | x3:={ x1:=2.1, x2:=2.1, x3:=3.1 }; | |
192 | //match | |
193 | if (match(x1,templateFloat_tRange3)) {setverdict(pass);} | |
194 | else {setverdict(fail);} | |
195 | //no match: out of range | |
196 | if (not(match(x2,templateFloat_tRange3))) {setverdict(pass);} | |
197 | else {setverdict(fail);} | |
198 | //no match: other field | |
199 | if (not(match(x3,templateFloat_tRange3))) {setverdict(pass);} | |
200 | else {setverdict(fail);} | |
201 | } | |
202 | ||
203 | testcase templateFloatRange4() runs on templateFloat_mycomp { | |
204 | var templateFloat_rec x1,x2,x3; //Range with - infinity | |
205 | x1:={ x1:=1.1, x2:=-2.1, x3:=3.1 }; | |
206 | x2:={ x1:=1.1, x2:=5.1, x3:=3.1 }; | |
207 | x3:={ x1:=2.1, x2:=2.1, x3:=3.1 }; | |
208 | //match | |
209 | if (match(x1,templateFloat_tRange4)) {setverdict(pass);} | |
210 | else {setverdict(fail);} | |
211 | //no match: out of range | |
212 | if (not(match(x2,templateFloat_tRange4))) {setverdict(pass);} | |
213 | else {setverdict(fail);} | |
214 | //no match: other field | |
215 | if (not(match(x3,templateFloat_tRange4))) {setverdict(pass);} | |
216 | else {setverdict(fail);} | |
217 | } | |
218 | ||
219 | testcase templateFloatIfpresent() runs on templateFloat_mycomp { | |
220 | var templateFloat_rec x1,x2,x3,x4; //ifpresent | |
221 | x1:={ x1:=1.1, x2:=2.1, x3:=3.1 }; | |
222 | x2:={ x1:=1.1, x2:=2.1, x3:=omit }; | |
223 | x3:={ x1:=1.1, x2:=2.1, x3:=4.1 }; | |
224 | x4:={ x1:=2.1, x2:=2.1, x3:=omit }; | |
225 | //match: present and match | |
226 | if (match(x1,templateFloat_tIfpresent)) {setverdict(pass);} | |
227 | else {setverdict(fail);} | |
228 | //match: not present | |
229 | if (match(x2,templateFloat_tIfpresent)) {setverdict(pass);} | |
230 | else {setverdict(fail);} | |
231 | //no match: present and not match | |
232 | if (not(match(x3,templateFloat_tIfpresent))) {setverdict(pass);} | |
233 | else {setverdict(fail);} | |
234 | ////no match: other field | |
235 | if (not(match(x4,templateFloat_tIfpresent))) {setverdict(pass);} | |
236 | else {setverdict(fail);} | |
237 | } | |
238 | ||
3abe9331 | 239 | testcase templateFloatSpecialValues() runs on templateFloat_mycomp { |
240 | var float v_nan := not_a_number; | |
241 | var float v_pos_inf := infinity; | |
242 | var float v_neg_inf := -infinity; | |
243 | ||
244 | if (match(v_nan, templateFloat_tNaN)) { setverdict(pass); } | |
245 | else { setverdict(fail, "not_a_number should match itself"); } | |
246 | ||
247 | if (match(v_pos_inf, templateFloat_tPosInf)) { setverdict(pass); } | |
248 | else { setverdict(fail, "infinity should match itself"); } | |
249 | ||
250 | if (match(v_neg_inf, templateFloat_tNegInf)) { setverdict(pass); } | |
251 | else { setverdict(fail, "-infinity should match itself"); } | |
252 | } | |
253 | ||
970ed795 EL |
254 | control { |
255 | execute(templateFloatSpec()); | |
256 | execute(templateFloatList()); | |
257 | execute(templateFloatComp()); | |
258 | execute(templateFloatOmit()); | |
259 | execute(templateFloatAny()); | |
260 | execute(templateFloatAnyorNone()); | |
261 | execute(templateFloatRange1()); | |
262 | execute(templateFloatRange2()); | |
263 | execute(templateFloatRange3()); | |
264 | execute(templateFloatRange4()); | |
265 | execute(templateFloatIfpresent()); | |
3abe9331 | 266 | execute(templateFloatSpecialValues()); |
970ed795 EL |
267 | } |
268 | } |