|
| 1 | +// Author: Diffblue Ltd. |
| 2 | + |
| 3 | +#include <testing-utils/use_catch.h> |
| 4 | + |
| 5 | +#include <solvers/smt2_incremental/smt_bitvector_theory.h> |
| 6 | +#include <solvers/smt2_incremental/smt_terms.h> |
| 7 | + |
| 8 | +#include <util/mp_arith.h> |
| 9 | + |
| 10 | +TEST_CASE("SMT bit vector predicates", "[core][smt2_incremental]") |
| 11 | +{ |
| 12 | + const smt_bit_vector_constant_termt two{2, 8}; |
| 13 | + const smt_bit_vector_constant_termt three{3, 8}; |
| 14 | + const smt_bool_literal_termt false_term{false}; |
| 15 | + const smt_bit_vector_constant_termt wider{2, 16}; |
| 16 | + SECTION("unsigned less than") |
| 17 | + { |
| 18 | + const auto function_application = |
| 19 | + smt_bit_vector_theoryt::unsigned_less_than(two, three); |
| 20 | + REQUIRE( |
| 21 | + function_application.function_identifier() == |
| 22 | + smt_identifier_termt("bvult", smt_bool_sortt{})); |
| 23 | + REQUIRE(function_application.get_sort() == smt_bool_sortt{}); |
| 24 | + REQUIRE(function_application.arguments().size() == 2); |
| 25 | + REQUIRE(function_application.arguments()[0].get() == two); |
| 26 | + REQUIRE(function_application.arguments()[1].get() == three); |
| 27 | + cbmc_invariants_should_throwt invariants_throw; |
| 28 | + CHECK_THROWS(smt_bit_vector_theoryt::unsigned_less_than(false_term, two)); |
| 29 | + CHECK_THROWS(smt_bit_vector_theoryt::unsigned_less_than(two, false_term)); |
| 30 | + CHECK_THROWS(smt_bit_vector_theoryt::unsigned_less_than(wider, two)); |
| 31 | + CHECK_THROWS(smt_bit_vector_theoryt::unsigned_less_than(two, wider)); |
| 32 | + } |
| 33 | + SECTION("unsigned less than or equal") |
| 34 | + { |
| 35 | + const auto function_application = |
| 36 | + smt_bit_vector_theoryt::unsigned_less_than_or_equal(two, three); |
| 37 | + REQUIRE( |
| 38 | + function_application.function_identifier() == |
| 39 | + smt_identifier_termt("bvule", smt_bool_sortt{})); |
| 40 | + REQUIRE(function_application.get_sort() == smt_bool_sortt{}); |
| 41 | + REQUIRE(function_application.arguments().size() == 2); |
| 42 | + REQUIRE(function_application.arguments()[0].get() == two); |
| 43 | + REQUIRE(function_application.arguments()[1].get() == three); |
| 44 | + cbmc_invariants_should_throwt invariants_throw; |
| 45 | + CHECK_THROWS( |
| 46 | + smt_bit_vector_theoryt::unsigned_less_than_or_equal(false_term, two)); |
| 47 | + CHECK_THROWS( |
| 48 | + smt_bit_vector_theoryt::unsigned_less_than_or_equal(two, false_term)); |
| 49 | + CHECK_THROWS( |
| 50 | + smt_bit_vector_theoryt::unsigned_less_than_or_equal(wider, two)); |
| 51 | + CHECK_THROWS( |
| 52 | + smt_bit_vector_theoryt::unsigned_less_than_or_equal(two, wider)); |
| 53 | + } |
| 54 | + SECTION("unsigned greater than") |
| 55 | + { |
| 56 | + const auto function_application = |
| 57 | + smt_bit_vector_theoryt::unsigned_greater_than(two, three); |
| 58 | + REQUIRE( |
| 59 | + function_application.function_identifier() == |
| 60 | + smt_identifier_termt("bvugt", smt_bool_sortt{})); |
| 61 | + REQUIRE(function_application.get_sort() == smt_bool_sortt{}); |
| 62 | + REQUIRE(function_application.arguments().size() == 2); |
| 63 | + REQUIRE(function_application.arguments()[0].get() == two); |
| 64 | + REQUIRE(function_application.arguments()[1].get() == three); |
| 65 | + cbmc_invariants_should_throwt invariants_throw; |
| 66 | + CHECK_THROWS( |
| 67 | + smt_bit_vector_theoryt::unsigned_greater_than(false_term, two)); |
| 68 | + CHECK_THROWS( |
| 69 | + smt_bit_vector_theoryt::unsigned_greater_than(two, false_term)); |
| 70 | + CHECK_THROWS(smt_bit_vector_theoryt::unsigned_greater_than(wider, two)); |
| 71 | + CHECK_THROWS(smt_bit_vector_theoryt::unsigned_greater_than(two, wider)); |
| 72 | + } |
| 73 | + SECTION("unsigned greater than or equal") |
| 74 | + { |
| 75 | + const auto function_application = |
| 76 | + smt_bit_vector_theoryt::unsigned_greater_than_or_equal(two, three); |
| 77 | + REQUIRE( |
| 78 | + function_application.function_identifier() == |
| 79 | + smt_identifier_termt("bvuge", smt_bool_sortt{})); |
| 80 | + REQUIRE(function_application.get_sort() == smt_bool_sortt{}); |
| 81 | + REQUIRE(function_application.arguments().size() == 2); |
| 82 | + REQUIRE(function_application.arguments()[0].get() == two); |
| 83 | + REQUIRE(function_application.arguments()[1].get() == three); |
| 84 | + cbmc_invariants_should_throwt invariants_throw; |
| 85 | + CHECK_THROWS( |
| 86 | + smt_bit_vector_theoryt::unsigned_greater_than_or_equal(false_term, two)); |
| 87 | + CHECK_THROWS( |
| 88 | + smt_bit_vector_theoryt::unsigned_greater_than_or_equal(two, false_term)); |
| 89 | + CHECK_THROWS( |
| 90 | + smt_bit_vector_theoryt::unsigned_greater_than_or_equal(wider, two)); |
| 91 | + CHECK_THROWS( |
| 92 | + smt_bit_vector_theoryt::unsigned_greater_than_or_equal(two, wider)); |
| 93 | + } |
| 94 | + SECTION("signed less than") |
| 95 | + { |
| 96 | + const auto function_application = |
| 97 | + smt_bit_vector_theoryt::signed_less_than(two, three); |
| 98 | + REQUIRE( |
| 99 | + function_application.function_identifier() == |
| 100 | + smt_identifier_termt("bvslt", smt_bool_sortt{})); |
| 101 | + REQUIRE(function_application.get_sort() == smt_bool_sortt{}); |
| 102 | + REQUIRE(function_application.arguments().size() == 2); |
| 103 | + REQUIRE(function_application.arguments()[0].get() == two); |
| 104 | + REQUIRE(function_application.arguments()[1].get() == three); |
| 105 | + cbmc_invariants_should_throwt invariants_throw; |
| 106 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_less_than(false_term, two)); |
| 107 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_less_than(two, false_term)); |
| 108 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_less_than(wider, two)); |
| 109 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_less_than(two, wider)); |
| 110 | + } |
| 111 | + SECTION("signed less than or equal") |
| 112 | + { |
| 113 | + const auto function_application = |
| 114 | + smt_bit_vector_theoryt::signed_less_than_or_equal(two, three); |
| 115 | + REQUIRE( |
| 116 | + function_application.function_identifier() == |
| 117 | + smt_identifier_termt("bvsle", smt_bool_sortt{})); |
| 118 | + REQUIRE(function_application.get_sort() == smt_bool_sortt{}); |
| 119 | + REQUIRE(function_application.arguments().size() == 2); |
| 120 | + REQUIRE(function_application.arguments()[0].get() == two); |
| 121 | + REQUIRE(function_application.arguments()[1].get() == three); |
| 122 | + cbmc_invariants_should_throwt invariants_throw; |
| 123 | + CHECK_THROWS( |
| 124 | + smt_bit_vector_theoryt::signed_less_than_or_equal(false_term, two)); |
| 125 | + CHECK_THROWS( |
| 126 | + smt_bit_vector_theoryt::signed_less_than_or_equal(two, false_term)); |
| 127 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_less_than_or_equal(wider, two)); |
| 128 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_less_than_or_equal(two, wider)); |
| 129 | + } |
| 130 | + SECTION("signed greater than") |
| 131 | + { |
| 132 | + const auto function_application = |
| 133 | + smt_bit_vector_theoryt::signed_greater_than(two, three); |
| 134 | + REQUIRE( |
| 135 | + function_application.function_identifier() == |
| 136 | + smt_identifier_termt("bvsgt", smt_bool_sortt{})); |
| 137 | + REQUIRE(function_application.get_sort() == smt_bool_sortt{}); |
| 138 | + REQUIRE(function_application.arguments().size() == 2); |
| 139 | + REQUIRE(function_application.arguments()[0].get() == two); |
| 140 | + REQUIRE(function_application.arguments()[1].get() == three); |
| 141 | + cbmc_invariants_should_throwt invariants_throw; |
| 142 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_greater_than(false_term, two)); |
| 143 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_greater_than(two, false_term)); |
| 144 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_greater_than(wider, two)); |
| 145 | + CHECK_THROWS(smt_bit_vector_theoryt::signed_greater_than(two, wider)); |
| 146 | + } |
| 147 | + SECTION("signed greater than or equal") |
| 148 | + { |
| 149 | + const auto function_application = |
| 150 | + smt_bit_vector_theoryt::signed_greater_than_or_equal(two, three); |
| 151 | + REQUIRE( |
| 152 | + function_application.function_identifier() == |
| 153 | + smt_identifier_termt("bvsge", smt_bool_sortt{})); |
| 154 | + REQUIRE(function_application.get_sort() == smt_bool_sortt{}); |
| 155 | + REQUIRE(function_application.arguments().size() == 2); |
| 156 | + REQUIRE(function_application.arguments()[0].get() == two); |
| 157 | + REQUIRE(function_application.arguments()[1].get() == three); |
| 158 | + cbmc_invariants_should_throwt invariants_throw; |
| 159 | + CHECK_THROWS( |
| 160 | + smt_bit_vector_theoryt::signed_greater_than_or_equal(false_term, two)); |
| 161 | + CHECK_THROWS( |
| 162 | + smt_bit_vector_theoryt::signed_greater_than_or_equal(two, false_term)); |
| 163 | + CHECK_THROWS( |
| 164 | + smt_bit_vector_theoryt::signed_greater_than_or_equal(wider, two)); |
| 165 | + CHECK_THROWS( |
| 166 | + smt_bit_vector_theoryt::signed_greater_than_or_equal(two, wider)); |
| 167 | + } |
| 168 | +} |
0 commit comments