|
| 1 | +// Author: Diffblue Ltd. |
| 2 | + |
| 3 | +#include <testing-utils/use_catch.h> |
| 4 | + |
| 5 | +#include <solvers/smt2_incremental/smt_core_theory.h> |
| 6 | +#include <solvers/smt2_incremental/smt_terms.h> |
| 7 | + |
| 8 | +#include <util/mp_arith.h> |
| 9 | + |
| 10 | +TEST_CASE("SMT core theory \"not\".", "[core][smt2_incremental]") |
| 11 | +{ |
| 12 | + const smt_bool_literal_termt operand{true}; |
| 13 | + const auto not_term = smt_core_theoryt::make_not(operand); |
| 14 | + |
| 15 | + CHECK(not_term.get_sort() == smt_bool_sortt{}); |
| 16 | + REQUIRE(not_term.arguments().size() == 1); |
| 17 | + REQUIRE(not_term.arguments()[0].get() == operand); |
| 18 | + cbmc_invariants_should_throwt invariants_throw; |
| 19 | + CHECK_THROWS(smt_core_theoryt::make_not(smt_bit_vector_constant_termt{0, 1})); |
| 20 | +} |
| 21 | + |
| 22 | +TEST_CASE("SMT core theory \"=\".", "[core][smt2_incremental]") |
| 23 | +{ |
| 24 | + SECTION("Bool sorted term comparison") |
| 25 | + { |
| 26 | + const smt_bool_literal_termt true_term{true}; |
| 27 | + const smt_bool_literal_termt false_term{false}; |
| 28 | + const auto bool_comparison = smt_core_theoryt::equal(true_term, false_term); |
| 29 | + CHECK(bool_comparison.get_sort() == smt_bool_sortt{}); |
| 30 | + REQUIRE(bool_comparison.arguments().size() == 2); |
| 31 | + REQUIRE(bool_comparison.arguments()[0].get() == true_term); |
| 32 | + REQUIRE(bool_comparison.arguments()[1].get() == false_term); |
| 33 | + } |
| 34 | + |
| 35 | + SECTION("Bit vector sorted term comparison") |
| 36 | + { |
| 37 | + const smt_bit_vector_constant_termt two{2, 8}; |
| 38 | + const smt_bit_vector_constant_termt three{3, 8}; |
| 39 | + const auto bit_vector_comparison = smt_core_theoryt::equal(two, three); |
| 40 | + CHECK(bit_vector_comparison.get_sort() == smt_bool_sortt{}); |
| 41 | + REQUIRE(bit_vector_comparison.arguments().size() == 2); |
| 42 | + REQUIRE(bit_vector_comparison.arguments()[0].get() == two); |
| 43 | + REQUIRE(bit_vector_comparison.arguments()[1].get() == three); |
| 44 | + } |
| 45 | + |
| 46 | + SECTION("Mismatch sort invariant") |
| 47 | + { |
| 48 | + cbmc_invariants_should_throwt invariants_throw; |
| 49 | + CHECK_THROWS(smt_core_theoryt::equal( |
| 50 | + smt_bit_vector_constant_termt{2, 8}, |
| 51 | + smt_bit_vector_constant_termt{2, 16})); |
| 52 | + CHECK_THROWS(smt_core_theoryt::equal( |
| 53 | + smt_bit_vector_constant_termt{2, 8}, smt_bool_literal_termt{true})); |
| 54 | + } |
| 55 | +} |
0 commit comments