|
| 1 | +// Author: Diffblue Ltd. |
| 2 | + |
| 3 | +#include <util/mp_arith.h> |
| 4 | + |
| 5 | +#include <solvers/smt2_incremental/smt_array_theory.h> |
| 6 | +#include <solvers/smt2_incremental/smt_bit_vector_theory.h> |
| 7 | +#include <testing-utils/use_catch.h> |
| 8 | + |
| 9 | +#include "testing-utils/invariant.h" |
| 10 | + |
| 11 | +TEST_CASE("SMT array theory \"select\".", "[core][smt2_incremental]") |
| 12 | +{ |
| 13 | + const smt_identifier_termt index_term("index", smt_bit_vector_sortt(64)); |
| 14 | + const smt_sortt value_sort(smt_bit_vector_sortt(32)); |
| 15 | + const smt_identifier_termt array_term( |
| 16 | + "array", smt_array_sortt(index_term.get_sort(), value_sort)); |
| 17 | + const smt_function_application_termt select = |
| 18 | + smt_array_theoryt::select(array_term, index_term); |
| 19 | + CHECK(select.get_sort() == value_sort); |
| 20 | + CHECK(select.function_identifier().identifier() == "select"); |
| 21 | + REQUIRE(select.arguments().size() == 2); |
| 22 | + CHECK(select.arguments()[0].get() == array_term); |
| 23 | + CHECK(select.arguments()[1].get() == index_term); |
| 24 | + cbmc_invariants_should_throwt invariants_throw; |
| 25 | + const smt_bit_vector_constant_termt two{2, 8}; |
| 26 | + REQUIRE_THROWS_MATCHES( |
| 27 | + smt_array_theoryt::select(two, index_term), |
| 28 | + invariant_failedt, |
| 29 | + invariant_failure_containing("\"select\" may only select from an array.")); |
| 30 | + REQUIRE_THROWS_MATCHES( |
| 31 | + smt_array_theoryt::select(array_term, two), |
| 32 | + invariant_failedt, |
| 33 | + invariant_failure_containing( |
| 34 | + "Sort of arrays index must match the sort of the index supplied.")); |
| 35 | +} |
| 36 | + |
| 37 | +TEST_CASE("SMT array theory \"store\".", "[core][smt2_incremental]") |
| 38 | +{ |
| 39 | + const smt_identifier_termt index_term("index", smt_bit_vector_sortt(64)); |
| 40 | + const smt_identifier_termt value_term("value", smt_bit_vector_sortt(32)); |
| 41 | + const smt_identifier_termt array_term( |
| 42 | + "array", smt_array_sortt(index_term.get_sort(), value_term.get_sort())); |
| 43 | + const smt_function_application_termt store = |
| 44 | + smt_array_theoryt::store(array_term, index_term, value_term); |
| 45 | + CHECK(store.get_sort() == array_term.get_sort()); |
| 46 | + CHECK(store.function_identifier().identifier() == "store"); |
| 47 | + REQUIRE(store.arguments().size() == 3); |
| 48 | + CHECK(store.arguments()[0].get() == array_term); |
| 49 | + CHECK(store.arguments()[1].get() == index_term); |
| 50 | + CHECK(store.arguments()[2].get() == value_term); |
| 51 | + cbmc_invariants_should_throwt invariants_throw; |
| 52 | + const smt_bit_vector_constant_termt two{2, 8}; |
| 53 | + REQUIRE_THROWS_MATCHES( |
| 54 | + smt_array_theoryt::store(two, index_term, value_term), |
| 55 | + invariant_failedt, |
| 56 | + invariant_failure_containing("\"store\" may only update an array.")); |
| 57 | + REQUIRE_THROWS_MATCHES( |
| 58 | + smt_array_theoryt::store(array_term, two, value_term), |
| 59 | + invariant_failedt, |
| 60 | + invariant_failure_containing( |
| 61 | + "Sort of arrays index must match the sort of the index supplied.")); |
| 62 | + REQUIRE_THROWS_MATCHES( |
| 63 | + smt_array_theoryt::store(array_term, index_term, two), |
| 64 | + invariant_failedt, |
| 65 | + invariant_failure_containing( |
| 66 | + "Sort of arrays value must match the sort of the value supplied.")); |
| 67 | +} |
0 commit comments