|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Unit tests for get_numeric_value_from_character in |
| 4 | + solvers/refinement/string_constraint_generator_valueof.cpp |
| 5 | +
|
| 6 | + Author: DiffBlue Limited. All rights reserved. |
| 7 | +
|
| 8 | +\*******************************************************************/ |
| 9 | + |
| 10 | +#include <catch.hpp> |
| 11 | + |
| 12 | +#include <util/arith_tools.h> |
| 13 | +#include <util/std_types.h> |
| 14 | +#include <util/std_expr.h> |
| 15 | +#include <solvers/refinement/string_refinement.h> |
| 16 | +#include <iostream> |
| 17 | + |
| 18 | +SCENARIO("substitute_array_list", |
| 19 | + "[core][solvers][refinement][string_refinement]") |
| 20 | +{ |
| 21 | + const typet char_type=unsignedbv_typet(16); |
| 22 | + const typet int_type=signedbv_typet(32); |
| 23 | + exprt arr("array-list"); |
| 24 | + const exprt index0=from_integer(0, int_type); |
| 25 | + const exprt charx=from_integer('x', char_type); |
| 26 | + const exprt index1=from_integer(1, int_type); |
| 27 | + const exprt chary=from_integer('y', char_type); |
| 28 | + const exprt index100=from_integer(100, int_type); |
| 29 | + |
| 30 | + // arr is `array-list [ 0 , 'x' , 1 , 'y' , 2 , 'z']` |
| 31 | + arr.operands()= |
| 32 | + { index0, charx, index1, chary, index100, from_integer('z', char_type) }; |
| 33 | + |
| 34 | + // Max length is 2, so index 2 should get ignored. |
| 35 | + const exprt subst=substitute_array_lists(arr, 2); |
| 36 | + |
| 37 | + // Check that `subst = e1 WITH [1:='y']` |
| 38 | + REQUIRE(subst.id()==ID_with); |
| 39 | + REQUIRE(subst.operands().size()==3); |
| 40 | + const exprt &e1=subst.op0(); |
| 41 | + REQUIRE(subst.op1()==index1); |
| 42 | + REQUIRE(subst.op2()==chary); |
| 43 | + |
| 44 | + // Check that `e1 = e2 WITH [0:='x']` |
| 45 | + REQUIRE(e1.id()==ID_with); |
| 46 | + REQUIRE(e1.operands().size()==3); |
| 47 | + const exprt &e2=e1.op0(); |
| 48 | + REQUIRE(e1.op1()==index0); |
| 49 | + REQUIRE(e1.op2()==charx); |
| 50 | + |
| 51 | + // Check that `e1 = ARRAY_OF 0` |
| 52 | + REQUIRE(e2.id()==ID_array_of); |
| 53 | + REQUIRE(e2.operands().size()==1); |
| 54 | + REQUIRE(e2.op0()==from_integer(0, char_type)); |
| 55 | +} |
0 commit comments