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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Balasko, Jeno
* Raduly, Csaba
* Szabados, Kristof
* Szabo, Janos Zoltan – initial implementation
*
******************************************************************************/
module TtemplateSet {
type component templateSet_mycomp {};
type set templateSet_myset {
integer f1,
float f2 };
type record templateSet_rec {
templateSet_myset x1,
templateSet_myset x2,
templateSet_myset x3 optional };
template templateSet_rec templateSet_tSpec :={ //specific values
x1:={f1:=1,f2:=1.2},
x2:={f1:=2,f2:=1.2},
x3:={f1:=3,f2:=1.2} };
template templateSet_rec templateSet_tList :={ //specific value and value list
x1:={f2:=1.2,f1:=1},
x2:=({f1:=2,f2:=1.2},{f1:=3,f2:=1.2},{f1:=6,f2:=1.2}),
x3:={f1:=3,f2:=1.2} };
template templateSet_rec templateSet_tComp :={ //specific value and compl. list
x1:={f1:=1,f2:=1.2},
x2:=complement ({f1:=2,f2:=1.2},{f1:=3,f2:=1.2},{f1:=6,f2:=1.2}),
x3:={f1:=3,f2:=1.2} };
template templateSet_rec templateSet_tOmit :={ //omitting values
x1:={f1:=1,f2:=1.2},
x2:={f1:=2,f2:=1.2},
x3:=omit } ;
template templateSet_rec templateSet_tAny :={ //specific and any value
x1:={f1:=1,f2:=1.2},
x2:={f1:=2,f2:=1.2},
x3:=? } ;
template templateSet_rec templateSet_tAnyorNone :={ //specific and AnyorNone value
x1:={f1:=1,f2:=1.2},
x2:={f1:=2,f2:=1.2},
x3:=* };
//template templateSet_rec templateSet_tIfpresent :={ //specific value and ifpresent
// x1:={f1:=1,f2:=1.2},
// x2:={f1:=2,f2:=1.2},
// x3:={f1:=3,f2:=1.2} ifpresent };
testcase templateSetSpec() runs on templateSet_mycomp {
var templateSet_myset temp:={f1:=3,f2:=1.2};
var templateSet_rec x1,x2; //specific value
x1:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=temp };
x2:={ x1:={f1:=2,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=temp };
//match
if (match(x1,templateSet_tSpec)) {setverdict(pass);}
else {setverdict(fail);}
//no match
if (not(match(x2,templateSet_tSpec))) {setverdict(pass);}
else {setverdict(fail);}
}
testcase templateSetList() runs on templateSet_mycomp {
var templateSet_myset temp:={f1:=3,f2:=1.2};
var templateSet_rec x1,x2,x3; //value list
x1:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=6,f2:=1.2}, x3:=temp };
x2:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=7,f2:=1.2}, x3:=temp };
x3:={ x1:={f1:=8,f2:=1.2}, x2:={f1:=6,f2:=1.2}, x3:=temp };
//match
if (match(x1,templateSet_tList)) {setverdict(pass);}
else {setverdict(fail);}
//no match: out of list
if (not(match(x2,templateSet_tList))) {setverdict(pass);}
else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateSet_tList))) {setverdict(pass);}
else {setverdict(fail);}
}
testcase templateSetComp() runs on templateSet_mycomp {
var templateSet_myset temp:={f1:=3,f2:=1.2};
var templateSet_rec x1,x2,x3; //complemented list
x1:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=7,f2:=1.2}, x3:=temp };
x2:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=6,f2:=1.2}, x3:=temp };
x3:={ x1:={f1:=2,f2:=1.2}, x2:={f1:=7,f2:=1.2}, x3:=temp };
//match
if (match(x1,templateSet_tComp)) {setverdict(pass);}
else {setverdict(fail);}
//no match: in the list
if (not(match(x2,templateSet_tComp))) {setverdict(pass);}
else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateSet_tComp))) {setverdict(pass);}
else {setverdict(fail);}
}
testcase templateSetOmit() runs on templateSet_mycomp {
var templateSet_myset temp:={f1:=3,f2:=1.2};
var templateSet_rec x1,x2,x3; //omitting value
x1:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=omit };
x2:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=temp };
x3:={ x1:={f1:=2,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=omit };
//match
if (match(x1,templateSet_tOmit)) {setverdict(pass);}
else {setverdict(fail);}
//no match: not omitted
if (not(match(x2,templateSet_tOmit))) {setverdict(pass);}
else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateSet_tOmit))) {setverdict(pass);}
else {setverdict(fail);}
}
testcase templateSetAny() runs on templateSet_mycomp {
var templateSet_myset temp:={f1:=3,f2:=1.2};
var templateSet_rec x1,x2,x3; //any value
x1:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=temp };
x2:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=omit };
x3:={ x1:={f1:=2,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=temp };
//match
if (match(x1,templateSet_tAny)) {setverdict(pass);}
else {setverdict(fail);}
//no match: field omitted
if (not(match(x2,templateSet_tAny))) {setverdict(pass);}
else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateSet_tAny))) {setverdict(pass);}
else {setverdict(fail);}
}
testcase templateSetAnyorNone() runs on templateSet_mycomp {
var templateSet_myset temp:={f1:=3,f2:=1.2};
var templateSet_rec x1,x2,x3; //AnyorNone value
x1:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=omit };
x2:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=temp };
x3:={ x1:={f1:=2,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=omit };
//match: omitted
if (match(x1,templateSet_tAnyorNone)) {setverdict(pass);}
else {setverdict(fail);}
//match: value
if (match(x2,templateSet_tAnyorNone)) {setverdict(pass);}
else {setverdict(fail);}
//no match: other field
if (not(match(x3,templateSet_tAnyorNone))) {setverdict(pass);}
else {setverdict(fail);}
}
//testcase templateSetIfpresent() runs on templateInt_mycomp {
//var templateSet_myset temp1:={f1:=3,f2:=1.2}; //ifpresent
//var templateSet_myset temp2:={f1:=4,f2:=1.2};
//var templateSet_rec x1,x2,x3,x4;
//x1:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=temp1 };
//x2:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=omit };
//x3:={ x1:={f1:=1,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=temp2 };
//x4:={ x1:={f1:=2,f2:=1.2}, x2:={f1:=2,f2:=1.2}, x3:=omit };
//match: present and match
//if (match(x1,templateSet_tIfpresent)) {setverdict(pass);}
// else {setverdict(fail);}
//match: not present
//if (match(x2,templateSet_tIfpresent)) {setverdict(pass);}
// else {setverdict(fail);}
//no match: present and not match
//if (not(match(x3,templateSet_tIfpresent))) {setverdict(pass);}
// else {setverdict(fail);}
//no match: other field
//if (not(match(x4,templateSet_tIfpresent))) {setverdict(pass);}
// else {setverdict(fail);}
//}
type record Set {
integer num,
charstring str optional
}
function f_identical_fields(Set p_par) return boolean {
return ispresent(p_par.str) and p_par.str == int2str(p_par.num);
}
template Set t_str_is_present := { num := ?, str := ? };
template Set t_conjunction := conjunct(t_str_is_present, @dynamic f_identical_fields);
template Set t_implication := t_str_is_present implies @dynamic f_identical_fields;
template Set t_dynamic(template integer pt_num, template charstring pt_str) := @dynamic {
return match(value.num, pt_num) and match(value.str, pt_str);
}
testcase templateSetConjunction() runs on templateSet_mycomp {
var Set v1 := { 16, "16" }, v2 := { 6, "a" };
if (not match(v1, t_conjunction)) {
setverdict(fail, match(v1, t_conjunction));
}
if (match(v2, t_conjunction)) {
setverdict(fail, match(v2, t_conjunction));
}
setverdict(pass);
}
testcase templateSetImplication() runs on templateSet_mycomp {
var Set v1 := { -2, omit }, v2 := { 71, "x" }, v3 := { -12, "-12" };
if (not match(v1, t_implication)) {
setverdict(fail, match(v1, t_implication));
}
if (match(v2, t_implication)) {
setverdict(fail, match(v2, t_implication));
}
if (not match(v3, t_implication)) {
setverdict(fail, match(v3, t_implication));
}
setverdict(pass);
}
testcase templateSetDynamic() runs on templateSet_mycomp {
var Set v1 := { 37, "abxc" }, v2 := { 16, "def" };
var template integer vt_num := (0..100);
var template charstring vt_str := pattern "*x*";
if (not match(v1, t_dynamic(vt_num, vt_str))) {
setverdict(fail, match(v1, t_dynamic(vt_num, vt_str)));
}
if (match(v2, t_dynamic(vt_num, vt_str))) {
setverdict(fail, match(v2, t_dynamic(vt_num, vt_str)));
}
setverdict(pass);
}
control {
execute(templateSetSpec());
execute(templateSetList());
execute(templateSetComp());
execute(templateSetOmit());
execute(templateSetAny());
execute(templateSetAnyorNone());
// execute(templateSetIfpresent());
execute(templateSetConjunction());
execute(templateSetImplication());
execute(templateSetDynamic());
}
}
|