Skip to content

Commit cdf11c3

Browse files
committed
More tests to confirm value-sets of intervals behaviour
1 parent 5aa4b92 commit cdf11c3

File tree

3 files changed

+182
-13
lines changed

3 files changed

+182
-13
lines changed

unit/analyses/variable-sensitivity/value_expression_evaluation/expression_evaluation.cpp

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,155 @@ SCENARIO(
451451
}
452452
}
453453
}
454+
GIVEN("adding a value-set of intervals and constants with a constant")
455+
{
456+
auto interval12 = constant_interval_exprt(val1, val2);
457+
auto interval23 = constant_interval_exprt(val2, val3);
458+
auto interval34 = constant_interval_exprt(val3, val4);
459+
auto interval45 = constant_interval_exprt(val4, val5);
460+
461+
WHEN("{ [1,2] } + 2")
462+
{
463+
auto op1 = make_value_set(interval12, environment, ns);
464+
auto op2 = make_constant(val2, environment, ns);
465+
auto result = add_as_value_set(op1, op2, environment, ns);
466+
467+
THEN("= { [3,4] }")
468+
{
469+
EXPECT(result, {interval34});
470+
}
471+
}
472+
WHEN("{ [1,2], 3 } + 2")
473+
{
474+
auto op1 = make_value_set({interval12, val3}, environment, ns);
475+
auto op2 = make_constant(val2, environment, ns);
476+
auto result = add_as_value_set(op1, op2, environment, ns);
477+
478+
THEN("= { [3,4], 5 }")
479+
{
480+
EXPECT(result, {interval34, val5});
481+
}
482+
}
483+
WHEN("{ [1,2], [2,3] } + 2")
484+
{
485+
auto op1 = make_value_set({interval12, interval23}, environment, ns);
486+
auto op2 = make_constant(val2, environment, ns);
487+
auto result = add_as_value_set(op1, op2, environment, ns);
488+
489+
THEN("= { [3,4], [4,5] }")
490+
{
491+
EXPECT(result, {interval34, interval45});
492+
}
493+
}
494+
}
495+
GIVEN("adding a value-set of intervals and constants with an interval")
496+
{
497+
auto interval12 = constant_interval_exprt(val1, val2);
498+
auto interval23 = constant_interval_exprt(val2, val3);
499+
auto interval34 = constant_interval_exprt(val3, val4);
500+
auto interval45 = constant_interval_exprt(val4, val5);
501+
auto interval24 = constant_interval_exprt(val2, val4);
502+
auto interval35 = constant_interval_exprt(val3, val5);
503+
504+
WHEN("{ [1,2] } + [1,2]")
505+
{
506+
auto op1 = make_value_set(interval12, environment, ns);
507+
auto op2 = make_interval(interval12, environment, ns);
508+
auto result = add_as_value_set(op1, op2, environment, ns);
509+
510+
THEN("= { [2,4] }")
511+
{
512+
EXPECT(result, {interval24});
513+
}
514+
}
515+
WHEN("{ [1,2], 1 } + [1,2]")
516+
{
517+
auto op1 = make_value_set({interval12, val1}, environment, ns);
518+
auto op2 = make_interval(interval12, environment, ns);
519+
auto result = add_as_value_set(op1, op2, environment, ns);
520+
521+
THEN("= { [2,4], [2,3] }")
522+
{
523+
EXPECT(result, {interval24, interval23});
524+
}
525+
}
526+
WHEN("{ [1,2], [2,3] } + [1,2]")
527+
{
528+
auto op1 = make_value_set({interval12, interval23}, environment, ns);
529+
auto op2 = make_interval(interval12, environment, ns);
530+
auto result = add_as_value_set(op1, op2, environment, ns);
531+
532+
THEN("= { [2,4], [3,5] }")
533+
{
534+
EXPECT(result, {interval24, interval35});
535+
}
536+
}
537+
}
538+
GIVEN("adding a value-set of intervals and constants with a value-set")
539+
{
540+
auto interval12 = constant_interval_exprt(val1, val2);
541+
auto interval23 = constant_interval_exprt(val2, val3);
542+
auto interval34 = constant_interval_exprt(val3, val4);
543+
auto interval45 = constant_interval_exprt(val4, val5);
544+
auto interval24 = constant_interval_exprt(val2, val4);
545+
auto interval35 = constant_interval_exprt(val3, val5);
546+
547+
WHEN("{ [1,2] } + { 1, 2 }")
548+
{
549+
auto op1 = make_value_set(interval12, environment, ns);
550+
auto op2 = make_value_set({val1, val2}, environment, ns);
551+
auto result = add_as_value_set(op1, op2, environment, ns);
552+
553+
THEN("= { [2,3], [3,4] }")
554+
{
555+
EXPECT(result, {interval23, interval34});
556+
}
557+
}
558+
WHEN("{ [1,2] } + { [1,2] }")
559+
{
560+
auto op1 = make_value_set(interval12, environment, ns);
561+
auto op2 = make_value_set(interval12, environment, ns);
562+
auto result = add_as_value_set(op1, op2, environment, ns);
563+
564+
THEN("= { [2,4] }")
565+
{
566+
EXPECT(result, {interval24});
567+
}
568+
}
569+
WHEN("{ [1,2], 1 } + { [1,2] }")
570+
{
571+
auto op1 = make_value_set({interval12, val1}, environment, ns);
572+
auto op2 = make_value_set(interval12, environment, ns);
573+
auto result = add_as_value_set(op1, op2, environment, ns);
574+
575+
THEN("= { [2,4], [2,3] }")
576+
{
577+
EXPECT(result, {interval24, interval23});
578+
}
579+
}
580+
WHEN("{ [1,2], [2,3] } + { [1,2] }")
581+
{
582+
auto op1 = make_value_set({interval12, interval23}, environment, ns);
583+
auto op2 = make_interval(interval12, environment, ns);
584+
auto result = add_as_value_set(op1, op2, environment, ns);
585+
586+
THEN("= { [2,4], [3,5] }")
587+
{
588+
EXPECT(result, {interval24, interval35});
589+
}
590+
}
591+
WHEN("{ [1,2], 1 } + { [1,2], 1 }")
592+
{
593+
auto op1 = make_value_set({interval12, val1}, environment, ns);
594+
auto op2 = make_value_set({interval12, val1}, environment, ns);
595+
auto result = add_as_value_set(op1, op2, environment, ns);
596+
597+
THEN("= { [2,4], [2,3], [2,3], 2 }")
598+
{ // duplicate interval ok as first pass. Will be eliminated in due course.
599+
EXPECT(result, {interval24, interval23, interval23, val2});
600+
}
601+
}
602+
}
454603
GIVEN("multiple operands")
455604
{
456605
WHEN("{ 1, 2, 3 } + 1 + 1")

unit/analyses/variable-sensitivity/variable_sensitivity_test_helpers.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
#include <util/mathematical_types.h>
1414
#include <util/string_utils.h>
1515

16-
std::shared_ptr<value_set_abstract_objectt>
17-
make_value_set(exprt val, abstract_environmentt &env, namespacet &ns)
18-
{
19-
return std::make_shared<value_set_abstract_objectt>(val, env, ns);
20-
}
21-
2216
std::shared_ptr<const constant_abstract_valuet>
2317
make_constant(exprt val, abstract_environmentt &env, namespacet &ns)
2418
{
@@ -38,29 +32,51 @@ std::shared_ptr<const constant_abstract_valuet> make_bottom_constant()
3832
}
3933

4034
std::shared_ptr<const interval_abstract_valuet> make_interval(
41-
exprt vall,
42-
exprt valh,
35+
const exprt &vall,
36+
const exprt &valh,
4337
abstract_environmentt &env,
4438
namespacet &ns)
4539
{
4640
auto interval = constant_interval_exprt(vall, valh);
47-
return std::make_shared<interval_abstract_valuet>(interval, env, ns);
41+
return make_interval(interval, env, ns);
42+
}
43+
44+
std::shared_ptr<const interval_abstract_valuet> make_interval(
45+
const constant_interval_exprt &val,
46+
abstract_environmentt &env,
47+
namespacet &ns)
48+
{
49+
return std::make_shared<interval_abstract_valuet>(val, env, ns);
4850
}
4951

5052
std::shared_ptr<const interval_abstract_valuet> make_top_interval()
5153
{
5254
return std::make_shared<interval_abstract_valuet>(
5355
signedbv_typet(32), true, false);
5456
}
57+
58+
std::shared_ptr<value_set_abstract_objectt>
59+
make_value_set(exprt val, abstract_environmentt &env, namespacet &ns)
60+
{
61+
auto vals = std::vector<exprt>{val};
62+
return make_value_set(vals, env, ns);
63+
}
64+
5565
std::shared_ptr<value_set_abstract_objectt> make_value_set(
5666
const std::vector<exprt> &vals,
5767
abstract_environmentt &env,
5868
namespacet &ns)
5969
{
6070
auto initial_values = abstract_object_sett{};
6171
for(auto v : vals)
62-
initial_values.insert(make_constant(v, env, ns));
63-
auto vs = make_value_set(vals[0], env, ns);
72+
{
73+
if(v.id() == ID_constant_interval)
74+
initial_values.insert(
75+
std::make_shared<interval_abstract_valuet>(v, env, ns));
76+
else
77+
initial_values.insert(make_constant(v, env, ns));
78+
}
79+
auto vs = std::make_shared<value_set_abstract_objectt>(vals[0], env, ns);
6480
vs->set_values(initial_values);
6581
return vs;
6682
}

unit/analyses/variable-sensitivity/variable_sensitivity_test_helpers.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ std::shared_ptr<const constant_abstract_valuet> make_top_constant();
1717
std::shared_ptr<const constant_abstract_valuet> make_bottom_constant();
1818

1919
std::shared_ptr<const interval_abstract_valuet> make_interval(
20-
exprt vall,
21-
exprt valh,
20+
const exprt &vall,
21+
const exprt &valh,
22+
abstract_environmentt &env,
23+
namespacet &ns);
24+
std::shared_ptr<const interval_abstract_valuet> make_interval(
25+
const constant_interval_exprt &val,
2226
abstract_environmentt &env,
2327
namespacet &ns);
2428
std::shared_ptr<const interval_abstract_valuet> make_top_interval();

0 commit comments

Comments
 (0)