|
1 | 1 | // Author: Diffblue Ltd.
|
2 | 2 |
|
| 3 | +#include <util/arith_tools.h> |
3 | 4 | #include <util/bitvector_expr.h>
|
4 | 5 | #include <util/bitvector_types.h>
|
| 6 | +#include <util/cout_message.h> |
| 7 | +#include <util/namespace.h> |
| 8 | +#include <util/std_expr.h> |
| 9 | +#include <util/symbol_table.h> |
5 | 10 |
|
| 11 | +#include <solvers/flattening/boolbv.h> |
| 12 | +#include <solvers/sat/satcheck.h> |
6 | 13 | #include <testing-utils/use_catch.h>
|
7 | 14 |
|
8 | 15 | TEST_CASE(
|
@@ -64,3 +71,74 @@ TEMPLATE_TEST_CASE(
|
64 | 71 | }
|
65 | 72 | }
|
66 | 73 | }
|
| 74 | + |
| 75 | +TEST_CASE("onehot expression lowering", "[core][util][expr]") |
| 76 | +{ |
| 77 | + console_message_handlert message_handler; |
| 78 | + message_handler.set_verbosity(0); |
| 79 | + satcheckt satcheck{message_handler}; |
| 80 | + symbol_tablet symbol_table; |
| 81 | + namespacet ns{symbol_table}; |
| 82 | + boolbvt boolbv{ns, satcheck, message_handler}; |
| 83 | + unsignedbv_typet u8{8}; |
| 84 | + |
| 85 | + GIVEN("A bit-vector that is one-hot") |
| 86 | + { |
| 87 | + boolbv << onehot_exprt{from_integer(64, u8)}.lower(); |
| 88 | + |
| 89 | + THEN("the lowering of onehot is true") |
| 90 | + { |
| 91 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_SATISFIABLE); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + GIVEN("A bit-vector that is not one-hot") |
| 96 | + { |
| 97 | + boolbv << onehot_exprt{from_integer(5, u8)}.lower(); |
| 98 | + |
| 99 | + THEN("the lowering of onehot is false") |
| 100 | + { |
| 101 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_UNSATISFIABLE); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + GIVEN("A bit-vector that is not one-hot") |
| 106 | + { |
| 107 | + boolbv << onehot_exprt{from_integer(0, u8)}.lower(); |
| 108 | + |
| 109 | + THEN("the lowering of onehot is false") |
| 110 | + { |
| 111 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_UNSATISFIABLE); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + GIVEN("A bit-vector that is one-hot 0") |
| 116 | + { |
| 117 | + boolbv << onehot0_exprt{from_integer(0xfe, u8)}.lower(); |
| 118 | + |
| 119 | + THEN("the lowering of onehot0 is true") |
| 120 | + { |
| 121 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_SATISFIABLE); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + GIVEN("A bit-vector that is not one-hot 0") |
| 126 | + { |
| 127 | + boolbv << onehot0_exprt{from_integer(0x7e, u8)}.lower(); |
| 128 | + |
| 129 | + THEN("the lowering of onehot0 is false") |
| 130 | + { |
| 131 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_UNSATISFIABLE); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + GIVEN("A bit-vector that is not one-hot 0") |
| 136 | + { |
| 137 | + boolbv << onehot0_exprt{from_integer(0xff, u8)}.lower(); |
| 138 | + |
| 139 | + THEN("the lowering of onehot0 is false") |
| 140 | + { |
| 141 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_UNSATISFIABLE); |
| 142 | + } |
| 143 | + } |
| 144 | +} |
0 commit comments