Skip to content

Commit 1faf516

Browse files
author
Thomas Kiley
committed
Add missing tests for modulo
1 parent d838704 commit 1faf516

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

unit/util/interval/modulo.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717

1818
SCENARIO("modulo interval domain", "[core][analyses][interval][modulo]")
1919
{
20+
GIVEN("Two single element internvals")
21+
{
22+
constant_interval_exprt a(CEV(5));
23+
constant_interval_exprt b(CEV(10));
24+
constant_interval_exprt zero(CEV(0));
25+
const auto a_mod_b = a.modulo(b);
26+
REQUIRE(V(a_mod_b.get_upper()) == 5);
27+
28+
const auto b_mod_a = b.modulo(a);
29+
// TODO: precision with single element modulo
30+
REQUIRE(V(b_mod_a.get_upper()) == 4);
31+
32+
const auto zero_mod_a = zero.modulo(a);
33+
REQUIRE(zero_mod_a == constant_interval_exprt(CEV(0)));
34+
35+
// TODO: this causes an invariant as it is unable to simplify the
36+
// TODO: simplify(a % 0) == a % 0
37+
// REQUIRE(a.modulo(zero).is_top());
38+
}
2039
GIVEN("Two simple signed intervals")
2140
{
2241
symbol_tablet symbol_table;
@@ -52,6 +71,19 @@ SCENARIO("modulo interval domain", "[core][analyses][interval][modulo]")
5271
constant_interval_exprt(CEV(-10), CEV(20)),
5372
constant_interval_exprt(CEV(0), CEV(5))) ==
5473
constant_interval_exprt::top(signedbv_typet(32)));
74+
75+
REQUIRE(
76+
constant_interval_exprt::modulo(
77+
constant_interval_exprt(CEV(-10), CEV(20)),
78+
constant_interval_exprt(CEV(1), CEV(5))) ==
79+
constant_interval_exprt(CEV(-10), CEV(20)));
80+
81+
REQUIRE(
82+
constant_interval_exprt::modulo(
83+
constant_interval_exprt(CEV(-10), CEV(-1)),
84+
constant_interval_exprt(CEV(-5), CEV(-1))) ==
85+
constant_interval_exprt(CEV(-5), CEV(0)));
86+
5587
REQUIRE(
5688
constant_interval_exprt::modulo(
5789
constant_interval_exprt(CEV(-20), CEV(-10)),

0 commit comments

Comments
 (0)