|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Unit tests for solvers/flattening/boolbv_onehot |
| 4 | +
|
| 5 | +Author: Daniel Kroening, [email protected] |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +/// \file |
| 10 | + |
| 11 | +#include <util/arith_tools.h> |
| 12 | +#include <util/bitvector_expr.h> |
| 13 | +#include <util/bitvector_types.h> |
| 14 | +#include <util/cout_message.h> |
| 15 | +#include <util/namespace.h> |
| 16 | +#include <util/std_expr.h> |
| 17 | +#include <util/symbol_table.h> |
| 18 | + |
| 19 | +#include <solvers/flattening/boolbv.h> |
| 20 | +#include <solvers/sat/satcheck.h> |
| 21 | +#include <testing-utils/use_catch.h> |
| 22 | + |
| 23 | +TEST_CASE("onehot flattening", "[core][solvers][flattening][boolbvt][onehot]") |
| 24 | +{ |
| 25 | + console_message_handlert message_handler; |
| 26 | + message_handler.set_verbosity(0); |
| 27 | + satcheckt satcheck{message_handler}; |
| 28 | + symbol_tablet symbol_table; |
| 29 | + namespacet ns{symbol_table}; |
| 30 | + boolbvt boolbv{ns, satcheck, message_handler}; |
| 31 | + unsignedbv_typet u8{8}; |
| 32 | + |
| 33 | + GIVEN("A bit-vector that is one-hot") |
| 34 | + { |
| 35 | + boolbv << onehot_exprt{from_integer(64, u8)}; |
| 36 | + |
| 37 | + THEN("the lowering of onehot is true") |
| 38 | + { |
| 39 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_SATISFIABLE); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + GIVEN("A bit-vector that is not one-hot") |
| 44 | + { |
| 45 | + boolbv << onehot_exprt{from_integer(5, u8)}; |
| 46 | + |
| 47 | + THEN("the lowering of onehot is false") |
| 48 | + { |
| 49 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_UNSATISFIABLE); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + GIVEN("A bit-vector that is not one-hot") |
| 54 | + { |
| 55 | + boolbv << onehot_exprt{from_integer(0, u8)}; |
| 56 | + |
| 57 | + THEN("the lowering of onehot is false") |
| 58 | + { |
| 59 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_UNSATISFIABLE); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + GIVEN("A bit-vector that is one-hot 0") |
| 64 | + { |
| 65 | + boolbv << onehot0_exprt{from_integer(0xfe, u8)}; |
| 66 | + |
| 67 | + THEN("the lowering of onehot0 is true") |
| 68 | + { |
| 69 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_SATISFIABLE); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + GIVEN("A bit-vector that is not one-hot 0") |
| 74 | + { |
| 75 | + boolbv << onehot0_exprt{from_integer(0x7e, u8)}; |
| 76 | + |
| 77 | + THEN("the lowering of onehot0 is false") |
| 78 | + { |
| 79 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_UNSATISFIABLE); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + GIVEN("A bit-vector that is not one-hot 0") |
| 84 | + { |
| 85 | + boolbv << onehot0_exprt{from_integer(0xff, u8)}; |
| 86 | + |
| 87 | + THEN("the lowering of onehot0 is false") |
| 88 | + { |
| 89 | + REQUIRE(boolbv() == decision_proceduret::resultt::D_UNSATISFIABLE); |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments