@@ -174,6 +174,32 @@ TEST_CASE("SMT bit vector bitwise operators", "[core][smt2_incremental]")
174174 }
175175}
176176
177+ TEST_CASE (" SMT bit vector comparison" , " [core][smt2_incremental]" )
178+ {
179+ const smt_bit_vector_constant_termt a_valid{42 , 16 }, b_valid{8 , 16 };
180+ SECTION (" Valid operands" )
181+ {
182+ const auto compare = smt_bit_vector_theoryt::compare (a_valid, b_valid);
183+ const auto expected_return_sort = smt_bit_vector_sortt{1 };
184+ REQUIRE (
185+ compare.function_identifier () ==
186+ smt_identifier_termt (" bvcomp" , expected_return_sort));
187+ REQUIRE (compare.get_sort () == expected_return_sort);
188+ REQUIRE (compare.arguments ().size () == 2 );
189+ REQUIRE (compare.arguments ()[0 ].get () == a_valid);
190+ REQUIRE (compare.arguments ()[1 ].get () == b_valid);
191+ }
192+ SECTION (" Invalid operands" )
193+ {
194+ const smt_bool_literal_termt false_term{false };
195+ const smt_bool_literal_termt true_term{true };
196+ cbmc_invariants_should_throwt invariants_throw;
197+ CHECK_THROWS (smt_bit_vector_theoryt::compare (a_valid, false_term));
198+ CHECK_THROWS (smt_bit_vector_theoryt::compare (false_term, a_valid));
199+ CHECK_THROWS (smt_bit_vector_theoryt::compare (false_term, true_term));
200+ }
201+ }
202+
177203TEST_CASE (" SMT bit vector predicates" , " [core][smt2_incremental]" )
178204{
179205 const smt_bit_vector_constant_termt two{2 , 8 };
@@ -551,3 +577,96 @@ TEST_CASE("SMT bit vector shifts", "[core][smt2_incremental]")
551577 smt_bit_vector_theoryt::arithmetic_shift_right (true_val, three));
552578 }
553579}
580+
581+ TEST_CASE (" SMT bit vector repeat" , " [core][smt2_incremental]" )
582+ {
583+ const smt_bit_vector_constant_termt two{2 , 8 };
584+ const auto expected_return_sort = smt_bit_vector_sortt{32 };
585+ const smt_bool_literal_termt true_val{true };
586+ const auto function_application = smt_bit_vector_theoryt::repeat (4 )(two);
587+ REQUIRE (
588+ function_application.function_identifier () ==
589+ smt_identifier_termt (
590+ " repeat" , expected_return_sort, {smt_numeral_indext{4 }}));
591+ REQUIRE (function_application.get_sort () == expected_return_sort);
592+ REQUIRE (function_application.arguments ().size () == 1 );
593+ REQUIRE (function_application.arguments ()[0 ].get () == two);
594+ cbmc_invariants_should_throwt invariants_throw;
595+ REQUIRE_THROWS (smt_bit_vector_theoryt::repeat (0 ));
596+ REQUIRE_THROWS (smt_bit_vector_theoryt::repeat (1 )(true_val));
597+ }
598+
599+ TEST_CASE (" SMT bit vector extend" , " [core][smt2_incremental]" )
600+ {
601+ const smt_bit_vector_constant_termt two{2 , 8 };
602+ const smt_bool_literal_termt true_val{true };
603+ SECTION (" Zero extension" )
604+ {
605+ const auto function_application =
606+ smt_bit_vector_theoryt::zero_extend (4 )(two);
607+ const auto expected_return_sort = smt_bit_vector_sortt{12 };
608+ REQUIRE (
609+ function_application.function_identifier () ==
610+ smt_identifier_termt (
611+ " zero_extend" , expected_return_sort, {smt_numeral_indext{4 }}));
612+ REQUIRE (function_application.get_sort () == expected_return_sort);
613+ REQUIRE (function_application.arguments ().size () == 1 );
614+ REQUIRE (function_application.arguments ()[0 ].get () == two);
615+ cbmc_invariants_should_throwt invariants_throw;
616+ REQUIRE_NOTHROW (smt_bit_vector_theoryt::zero_extend (0 ));
617+ REQUIRE_THROWS (smt_bit_vector_theoryt::zero_extend (1 )(true_val));
618+ }
619+ SECTION (" Sign extension" )
620+ {
621+ const auto function_application =
622+ smt_bit_vector_theoryt::sign_extend (4 )(two);
623+ const auto expected_return_sort = smt_bit_vector_sortt{12 };
624+ REQUIRE (
625+ function_application.function_identifier () ==
626+ smt_identifier_termt (
627+ " sign_extend" , expected_return_sort, {smt_numeral_indext{4 }}));
628+ REQUIRE (function_application.get_sort () == expected_return_sort);
629+ REQUIRE (function_application.arguments ().size () == 1 );
630+ REQUIRE (function_application.arguments ()[0 ].get () == two);
631+ cbmc_invariants_should_throwt invariants_throw;
632+ REQUIRE_NOTHROW (smt_bit_vector_theoryt::sign_extend (0 ));
633+ REQUIRE_THROWS (smt_bit_vector_theoryt::sign_extend (1 )(true_val));
634+ }
635+ }
636+
637+ TEST_CASE (" SMT bit vector rotation" , " [core][smt2_incremental]" )
638+ {
639+ const smt_bit_vector_constant_termt two{2 , 8 };
640+ const smt_bool_literal_termt true_val{true };
641+ const auto expected_return_sort = smt_bit_vector_sortt{8 };
642+ SECTION (" Left rotation" )
643+ {
644+ const auto function_application =
645+ smt_bit_vector_theoryt::rotate_left (4 )(two);
646+ REQUIRE (
647+ function_application.function_identifier () ==
648+ smt_identifier_termt (
649+ " rotate_left" , expected_return_sort, {smt_numeral_indext{4 }}));
650+ REQUIRE (function_application.get_sort () == expected_return_sort);
651+ REQUIRE (function_application.arguments ().size () == 1 );
652+ REQUIRE (function_application.arguments ()[0 ].get () == two);
653+ cbmc_invariants_should_throwt invariants_throw;
654+ REQUIRE_NOTHROW (smt_bit_vector_theoryt::rotate_left (0 ));
655+ REQUIRE_THROWS (smt_bit_vector_theoryt::rotate_left (1 )(true_val));
656+ }
657+ SECTION (" Right rotation" )
658+ {
659+ const auto function_application =
660+ smt_bit_vector_theoryt::rotate_right (4 )(two);
661+ REQUIRE (
662+ function_application.function_identifier () ==
663+ smt_identifier_termt (
664+ " rotate_right" , expected_return_sort, {smt_numeral_indext{4 }}));
665+ REQUIRE (function_application.get_sort () == expected_return_sort);
666+ REQUIRE (function_application.arguments ().size () == 1 );
667+ REQUIRE (function_application.arguments ()[0 ].get () == two);
668+ cbmc_invariants_should_throwt invariants_throw;
669+ REQUIRE_NOTHROW (smt_bit_vector_theoryt::rotate_right (0 ));
670+ REQUIRE_THROWS (smt_bit_vector_theoryt::rotate_right (1 )(true_val));
671+ }
672+ }
0 commit comments