1
+ #include " analyses/variable-sensitivity/variable_sensitivity_test_helpers.h"
1
2
#include < analyses/variable-sensitivity/abstract_environment.h>
2
- #include < analyses/variable-sensitivity/abstract_object.h>
3
3
#include < analyses/variable-sensitivity/constant_abstract_value.h>
4
4
#include < analyses/variable-sensitivity/value_set_abstract_object.h>
5
5
#include < analyses/variable-sensitivity/variable_sensitivity_object_factory.h>
6
6
#include < testing-utils/use_catch.h>
7
7
#include < util/arith_tools.h>
8
- #include < util/mathematical_types.h>
9
8
#include < util/namespace.h>
10
9
#include < util/symbol_table.h>
11
10
12
11
SCENARIO (
13
12
" index_range for constant_abstract_values"
14
- " [core][analyses][variable-sensitivity][constant_abstract_value][index- "
13
+ " [core][analyses][variable-sensitivity][constant_abstract_value][index_ "
15
14
" range]" )
16
15
{
17
16
auto type = signedbv_typet (32 );
@@ -26,8 +25,7 @@ SCENARIO(
26
25
{
27
26
auto int_value = 99 ;
28
27
auto value_expr = from_integer (int_value, type);
29
- auto value =
30
- std::make_shared<constant_abstract_valuet>(value_expr, env, ns);
28
+ auto value = make_constant (value_expr, env, ns);
31
29
32
30
auto range = value->index_range (ns);
33
31
@@ -59,7 +57,7 @@ SCENARIO(
59
57
60
58
GIVEN (" a top constant's range is has a single nil expression" )
61
59
{
62
- auto value = std::make_shared<constant_abstract_valuet>(type );
60
+ auto value = make_top_constant ( );
63
61
64
62
auto range = value->index_range (ns);
65
63
@@ -78,7 +76,7 @@ SCENARIO(
78
76
79
77
SCENARIO (
80
78
" index_range for interval_abstract_values"
81
- " [core][analyses][variable-sensitivity][interval_abstract_value][index- "
79
+ " [core][analyses][variable-sensitivity][interval_abstract_value][index_ "
82
80
" range]" )
83
81
{
84
82
auto object_factory = variable_sensitivity_object_factoryt::configured_with (
@@ -91,7 +89,7 @@ SCENARIO(
91
89
92
90
GIVEN (" a top intervals's range is empty" )
93
91
{
94
- auto value = std::make_shared<interval_abstract_valuet>(type, true , false );
92
+ auto value = make_top_interval ( );
95
93
96
94
auto range = value->index_range (ns);
97
95
@@ -105,8 +103,7 @@ SCENARIO(
105
103
{
106
104
auto int_value = 99 ;
107
105
auto value_expr = from_integer (int_value, type);
108
- auto value =
109
- std::make_shared<interval_abstract_valuet>(value_expr, env, ns);
106
+ auto value = make_interval (value_expr, value_expr, env, ns);
110
107
111
108
auto range = value->index_range (ns);
112
109
@@ -127,12 +124,9 @@ SCENARIO(
127
124
GIVEN (" a [99,100] interval's index_range has two elements" )
128
125
{
129
126
auto int_value = 99 ;
130
- auto value_expr = from_integer (int_value, type);
131
- auto value = std::make_shared<interval_abstract_valuet>(
132
- constant_interval_exprt (
133
- from_integer (int_value, type), from_integer (int_value + 1 , type), type),
134
- env,
135
- ns);
127
+ auto lower = from_integer (int_value, type);
128
+ auto upper = from_integer (int_value + 1 , type);
129
+ auto value = make_interval (lower, upper, env, ns);
136
130
137
131
auto range = value->index_range (ns);
138
132
@@ -159,12 +153,9 @@ SCENARIO(
159
153
GIVEN (" a [99,102] interval's index_range has four elements" )
160
154
{
161
155
auto int_value = 99 ;
162
- auto value_expr = from_integer (int_value, type);
163
- auto value = std::make_shared<interval_abstract_valuet>(
164
- constant_interval_exprt (
165
- from_integer (int_value, type), from_integer (int_value + 3 , type), type),
166
- env,
167
- ns);
156
+ auto lower = from_integer (int_value, type);
157
+ auto upper = from_integer (int_value + 3 , type);
158
+ auto value = make_interval (lower, upper, env, ns);
168
159
169
160
auto range = value->index_range (ns);
170
161
@@ -186,7 +177,7 @@ SCENARIO(
186
177
187
178
SCENARIO (
188
179
" index_range for value_set_abstract_values"
189
- " [core][analyses][variable-sensitivity][value_set_abstract_value][index- "
180
+ " [core][analyses][variable-sensitivity][value_set_abstract_value][index_ "
190
181
" range]" )
191
182
{
192
183
auto object_factory = variable_sensitivity_object_factoryt::configured_with (
@@ -197,10 +188,9 @@ SCENARIO(
197
188
namespacet ns (symbol_table);
198
189
auto type = signedbv_typet (32 );
199
190
200
- GIVEN (" a value_set is empty" )
191
+ GIVEN (" a TOP value_set is empty" )
201
192
{
202
- auto value =
203
- std::make_shared<value_set_abstract_objectt>(type, true , false );
193
+ auto value = make_top_value_set ();
204
194
auto range = value->index_range (ns);
205
195
206
196
THEN (" range should have a nil expr" )
@@ -214,4 +204,91 @@ SCENARIO(
214
204
REQUIRE (i == range.end ());
215
205
}
216
206
}
207
+ GIVEN (" a value_set { 99, 100, 101, 102 } index_range has four elements" )
208
+ {
209
+ auto int_value = 99 ;
210
+ auto _99 = from_integer (int_value, type);
211
+ auto _100 = from_integer (100 , type);
212
+ auto _101 = from_integer (101 , type);
213
+ auto _102 = from_integer (102 , type);
214
+ auto value = make_value_set ({_99, _100, _101, _102}, env, ns);
215
+
216
+ auto range = value->index_range (ns);
217
+
218
+ THEN (" range has four values" )
219
+ {
220
+ auto values = std::vector<exprt>();
221
+ for (const auto &e : range)
222
+ values.push_back (to_constant_expr (e));
223
+
224
+ REQUIRE (values.size () == 4 );
225
+ EXPECT (values, {_99, _100, _101, _102});
226
+ }
227
+ }
228
+ GIVEN (" a value_set { [99, 102] } index_range has four elements" )
229
+ {
230
+ auto int_value = 99 ;
231
+ auto _99 = from_integer (int_value, type);
232
+ auto _100 = from_integer (100 , type);
233
+ auto _101 = from_integer (101 , type);
234
+ auto _102 = from_integer (102 , type);
235
+ auto _99_102 = constant_interval_exprt (_99, _102);
236
+ auto value = make_value_set ({_99_102}, env, ns);
237
+
238
+ auto range = value->index_range (ns);
239
+
240
+ THEN (" range has four values" )
241
+ {
242
+ auto values = std::vector<exprt>();
243
+ for (const auto &e : range)
244
+ values.push_back (to_constant_expr (e));
245
+
246
+ REQUIRE (values.size () == 4 );
247
+ EXPECT (values, {_99, _100, _101, _102});
248
+ }
249
+ }
250
+ GIVEN (" a value_set { 99, 100, [101, 102] } index_range has four elements" )
251
+ {
252
+ auto int_value = 99 ;
253
+ auto _99 = from_integer (int_value, type);
254
+ auto _100 = from_integer (100 , type);
255
+ auto _101 = from_integer (101 , type);
256
+ auto _102 = from_integer (102 , type);
257
+ auto _101_102 = constant_interval_exprt (_101, _102);
258
+ auto value = make_value_set ({_99, _101_102, _100}, env, ns);
259
+
260
+ auto range = value->index_range (ns);
261
+
262
+ THEN (" range has four values" )
263
+ {
264
+ auto values = std::vector<exprt>();
265
+ for (const auto &e : range)
266
+ values.push_back (to_constant_expr (e));
267
+
268
+ REQUIRE (values.size () == 4 );
269
+ EXPECT (values, {_99, _100, _101, _102});
270
+ }
271
+ }
272
+ GIVEN (" a value_set { [99, 102], 100, 101 } index_range has four elements" )
273
+ {
274
+ auto int_value = 99 ;
275
+ auto _99 = from_integer (int_value, type);
276
+ auto _100 = from_integer (100 , type);
277
+ auto _101 = from_integer (101 , type);
278
+ auto _102 = from_integer (102 , type);
279
+ auto _99_102 = constant_interval_exprt (_99, _102);
280
+ auto value = make_value_set ({_99_102, _100, _101}, env, ns);
281
+
282
+ auto range = value->index_range (ns);
283
+
284
+ THEN (" range has four values" )
285
+ {
286
+ auto values = std::vector<exprt>();
287
+ for (const auto &e : range)
288
+ values.push_back (to_constant_expr (e));
289
+
290
+ REQUIRE (values.size () == 4 );
291
+ EXPECT (values, {_99, _100, _101, _102});
292
+ }
293
+ }
217
294
}
0 commit comments