Skip to content

Commit 654418a

Browse files
Unit tests for sparse_arrayt
1 parent d65bf9f commit 654418a

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

unit/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SRC += unit_tests.cpp \
3636
solvers/refinement/string_refinement/has_subtype.cpp \
3737
solvers/refinement/string_refinement/substitute_array_list.cpp \
3838
solvers/refinement/string_refinement/string_symbol_resolution.cpp \
39+
solvers/refinement/string_refinement/sparse_array.cpp \
3940
solvers/refinement/string_refinement/union_find_replace.cpp \
4041
util/expr_cast/expr_cast.cpp \
4142
util/expr_iterator.cpp \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for sparse arrays
4+
solvers/refinement/string_refinement.cpp
5+
6+
Author: DiffBlue Limited. All rights reserved.
7+
8+
\*******************************************************************/
9+
10+
#include <testing-utils/catch.hpp>
11+
12+
#include <util/arith_tools.h>
13+
#include <util/std_types.h>
14+
#include <util/std_expr.h>
15+
#include <util/symbol_table.h>
16+
#include <solvers/refinement/string_refinement.h>
17+
#include <iostream>
18+
19+
SCENARIO("sparse_array", "[core][solvers][refinement][string_refinement]")
20+
{
21+
GIVEN("`ARRAY_OF(0) WITH [4:=x] WITH [1:=y] WITH [100:=z]`")
22+
{
23+
const typet char_type = unsignedbv_typet(16);
24+
const typet int_type = signedbv_typet(32);
25+
const exprt index1 = from_integer(1, int_type);
26+
const exprt charx = from_integer('x', char_type);
27+
const exprt index4 = from_integer(4, int_type);
28+
const exprt chary = from_integer('y', char_type);
29+
const exprt index100 = from_integer(100, int_type);
30+
const exprt char0 = from_integer('0', char_type);
31+
const exprt index2 = from_integer(2, int_type);
32+
const exprt charz = from_integer('z', char_type);
33+
const array_typet array_type(char_type, infinity_exprt(int_type));
34+
35+
const with_exprt input_expr(
36+
with_exprt(
37+
with_exprt(
38+
array_of_exprt(from_integer(0, char_type), array_type),
39+
index4,
40+
charx),
41+
index1,
42+
chary),
43+
index100,
44+
charz);
45+
46+
WHEN("It is converted to a sparse array")
47+
{
48+
const sparse_arrayt sparse_array(input_expr);
49+
THEN("The resulting if expression is index=4?x:index=1?y:index=100?z:0")
50+
{
51+
const symbol_exprt index("index", int_type);
52+
const if_exprt expected(
53+
equal_exprt(index, index4),
54+
charx,
55+
if_exprt(
56+
equal_exprt(index, index1),
57+
chary,
58+
if_exprt(
59+
equal_exprt(index, index100),
60+
charz,
61+
from_integer(0, char_type))));
62+
REQUIRE(sparse_array.to_if_expression(index) == expected);
63+
}
64+
}
65+
66+
WHEN("It is converted to an interval sparse array")
67+
{
68+
const interval_sparse_arrayt sparse_array(input_expr);
69+
70+
THEN(
71+
"The resulting if expression is index<=1?x:index<=4?y:index<=100?z:0")
72+
{
73+
const symbol_exprt index("index", int_type);
74+
const if_exprt expected(
75+
binary_relation_exprt(index, ID_le, index1),
76+
chary,
77+
if_exprt(
78+
binary_relation_exprt(index, ID_le, index4),
79+
charx,
80+
if_exprt(
81+
binary_relation_exprt(index, ID_le, index100),
82+
charz,
83+
from_integer(0, char_type))));
84+
REQUIRE(sparse_array.to_if_expression(index) == expected);
85+
}
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)