1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Makai Mann, Aina Niemetz |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Black box testing of the Op class. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "test_api.h" |
17 |
|
|
18 |
|
namespace cvc5 { |
19 |
|
|
20 |
|
using namespace api; |
21 |
|
|
22 |
|
namespace test { |
23 |
|
|
24 |
40 |
class TestApiBlackOp : public TestApi |
25 |
|
{ |
26 |
|
}; |
27 |
|
|
28 |
19 |
TEST_F(TestApiBlackOp, getKind) |
29 |
|
{ |
30 |
4 |
Op x; |
31 |
2 |
x = d_solver.mkOp(BITVECTOR_EXTRACT, 31, 1); |
32 |
2 |
ASSERT_NO_THROW(x.getKind()); |
33 |
|
} |
34 |
|
|
35 |
19 |
TEST_F(TestApiBlackOp, isNull) |
36 |
|
{ |
37 |
4 |
Op x; |
38 |
2 |
ASSERT_TRUE(x.isNull()); |
39 |
2 |
x = d_solver.mkOp(BITVECTOR_EXTRACT, 31, 1); |
40 |
2 |
ASSERT_FALSE(x.isNull()); |
41 |
|
} |
42 |
|
|
43 |
19 |
TEST_F(TestApiBlackOp, opFromKind) |
44 |
|
{ |
45 |
2 |
ASSERT_NO_THROW(d_solver.mkOp(PLUS)); |
46 |
4 |
ASSERT_THROW(d_solver.mkOp(BITVECTOR_EXTRACT), CVC5ApiException); |
47 |
|
} |
48 |
|
|
49 |
19 |
TEST_F(TestApiBlackOp, getNumIndices) |
50 |
|
{ |
51 |
4 |
Op plus = d_solver.mkOp(PLUS); |
52 |
4 |
Op divisible = d_solver.mkOp(DIVISIBLE, 4); |
53 |
4 |
Op bitvector_repeat = d_solver.mkOp(BITVECTOR_REPEAT, 5); |
54 |
4 |
Op bitvector_zero_extend = d_solver.mkOp(BITVECTOR_ZERO_EXTEND, 6); |
55 |
4 |
Op bitvector_sign_extend = d_solver.mkOp(BITVECTOR_SIGN_EXTEND, 7); |
56 |
4 |
Op bitvector_rotate_left = d_solver.mkOp(BITVECTOR_ROTATE_LEFT, 8); |
57 |
4 |
Op bitvector_rotate_right = d_solver.mkOp(BITVECTOR_ROTATE_RIGHT, 9); |
58 |
4 |
Op int_to_bitvector = d_solver.mkOp(INT_TO_BITVECTOR, 10); |
59 |
4 |
Op iand = d_solver.mkOp(IAND, 3); |
60 |
4 |
Op floatingpoint_to_ubv = d_solver.mkOp(FLOATINGPOINT_TO_UBV, 11); |
61 |
4 |
Op floatingopint_to_sbv = d_solver.mkOp(FLOATINGPOINT_TO_SBV, 13); |
62 |
|
Op floatingpoint_to_fp_ieee_bitvector = |
63 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_IEEE_BITVECTOR, 4, 25); |
64 |
|
Op floatingpoint_to_fp_floatingpoint = |
65 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_FLOATINGPOINT, 4, 25); |
66 |
4 |
Op floatingpoint_to_fp_real = d_solver.mkOp(FLOATINGPOINT_TO_FP_REAL, 4, 25); |
67 |
|
Op floatingpoint_to_fp_signed_bitvector = |
68 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR, 4, 25); |
69 |
|
Op floatingpoint_to_fp_unsigned_bitvector = |
70 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR, 4, 25); |
71 |
|
Op floatingpoint_to_fp_generic = |
72 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_GENERIC, 4, 25); |
73 |
4 |
Op regexp_loop = d_solver.mkOp(REGEXP_LOOP, 2, 3); |
74 |
|
|
75 |
2 |
ASSERT_EQ(0, plus.getNumIndices()); |
76 |
2 |
ASSERT_EQ(1, divisible.getNumIndices()); |
77 |
2 |
ASSERT_EQ(1, bitvector_repeat.getNumIndices()); |
78 |
2 |
ASSERT_EQ(1, bitvector_zero_extend.getNumIndices()); |
79 |
2 |
ASSERT_EQ(1, bitvector_sign_extend.getNumIndices()); |
80 |
2 |
ASSERT_EQ(1, bitvector_rotate_left.getNumIndices()); |
81 |
2 |
ASSERT_EQ(1, bitvector_rotate_right.getNumIndices()); |
82 |
2 |
ASSERT_EQ(1, int_to_bitvector.getNumIndices()); |
83 |
2 |
ASSERT_EQ(1, iand.getNumIndices()); |
84 |
2 |
ASSERT_EQ(1, floatingpoint_to_ubv.getNumIndices()); |
85 |
2 |
ASSERT_EQ(1, floatingopint_to_sbv.getNumIndices()); |
86 |
2 |
ASSERT_EQ(2, floatingpoint_to_fp_ieee_bitvector.getNumIndices()); |
87 |
2 |
ASSERT_EQ(2, floatingpoint_to_fp_floatingpoint.getNumIndices()); |
88 |
2 |
ASSERT_EQ(2, floatingpoint_to_fp_real.getNumIndices()); |
89 |
2 |
ASSERT_EQ(2, floatingpoint_to_fp_signed_bitvector.getNumIndices()); |
90 |
2 |
ASSERT_EQ(2, floatingpoint_to_fp_unsigned_bitvector.getNumIndices()); |
91 |
2 |
ASSERT_EQ(2, floatingpoint_to_fp_generic.getNumIndices()); |
92 |
2 |
ASSERT_EQ(2, regexp_loop.getNumIndices()); |
93 |
|
} |
94 |
|
|
95 |
19 |
TEST_F(TestApiBlackOp, subscriptOperator) |
96 |
|
{ |
97 |
4 |
Op plus = d_solver.mkOp(PLUS); |
98 |
4 |
Op divisible = d_solver.mkOp(DIVISIBLE, 4); |
99 |
4 |
Op bitvector_repeat = d_solver.mkOp(BITVECTOR_REPEAT, 4); |
100 |
4 |
Op bitvector_zero_extend = d_solver.mkOp(BITVECTOR_ZERO_EXTEND, 4); |
101 |
4 |
Op bitvector_sign_extend = d_solver.mkOp(BITVECTOR_SIGN_EXTEND, 4); |
102 |
4 |
Op bitvector_rotate_left = d_solver.mkOp(BITVECTOR_ROTATE_LEFT, 4); |
103 |
4 |
Op bitvector_rotate_right = d_solver.mkOp(BITVECTOR_ROTATE_RIGHT, 4); |
104 |
4 |
Op int_to_bitvector = d_solver.mkOp(INT_TO_BITVECTOR, 4); |
105 |
4 |
Op iand = d_solver.mkOp(IAND, 4); |
106 |
4 |
Op floatingpoint_to_ubv = d_solver.mkOp(FLOATINGPOINT_TO_UBV, 4); |
107 |
4 |
Op floatingopint_to_sbv = d_solver.mkOp(FLOATINGPOINT_TO_SBV, 4); |
108 |
|
Op floatingpoint_to_fp_ieee_bitvector = |
109 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_IEEE_BITVECTOR, 4, 5); |
110 |
|
Op floatingpoint_to_fp_floatingpoint = |
111 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_FLOATINGPOINT, 4, 5); |
112 |
4 |
Op floatingpoint_to_fp_real = d_solver.mkOp(FLOATINGPOINT_TO_FP_REAL, 4, 5); |
113 |
|
Op floatingpoint_to_fp_signed_bitvector = |
114 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR, 4, 5); |
115 |
|
Op floatingpoint_to_fp_unsigned_bitvector = |
116 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR, 4, 5); |
117 |
|
Op floatingpoint_to_fp_generic = |
118 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_GENERIC, 4, 5); |
119 |
4 |
Op regexp_loop = d_solver.mkOp(REGEXP_LOOP, 4, 5); |
120 |
|
|
121 |
4 |
ASSERT_THROW(plus[0], CVC5ApiException); |
122 |
2 |
ASSERT_EQ(4, divisible[0].getUInt32Value()); |
123 |
2 |
ASSERT_EQ(4, bitvector_repeat[0].getUInt32Value()); |
124 |
2 |
ASSERT_EQ(4, bitvector_zero_extend[0].getUInt32Value()); |
125 |
2 |
ASSERT_EQ(4, bitvector_sign_extend[0].getUInt32Value()); |
126 |
2 |
ASSERT_EQ(4, bitvector_rotate_left[0].getUInt32Value()); |
127 |
2 |
ASSERT_EQ(4, bitvector_rotate_right[0].getUInt32Value()); |
128 |
2 |
ASSERT_EQ(4, int_to_bitvector[0].getUInt32Value()); |
129 |
2 |
ASSERT_EQ(4, iand[0].getUInt32Value()); |
130 |
2 |
ASSERT_EQ(4, floatingpoint_to_ubv[0].getUInt32Value()); |
131 |
2 |
ASSERT_EQ(4, floatingopint_to_sbv[0].getUInt32Value()); |
132 |
2 |
ASSERT_EQ(4, floatingpoint_to_fp_ieee_bitvector[0].getUInt32Value()); |
133 |
2 |
ASSERT_EQ(4, floatingpoint_to_fp_floatingpoint[0].getUInt32Value()); |
134 |
2 |
ASSERT_EQ(4, floatingpoint_to_fp_real[0].getUInt32Value()); |
135 |
2 |
ASSERT_EQ(4, floatingpoint_to_fp_signed_bitvector[0].getUInt32Value()); |
136 |
2 |
ASSERT_EQ(4, floatingpoint_to_fp_unsigned_bitvector[0].getUInt32Value()); |
137 |
2 |
ASSERT_EQ(4, floatingpoint_to_fp_generic[0].getUInt32Value()); |
138 |
2 |
ASSERT_EQ(4, regexp_loop[0].getUInt32Value()); |
139 |
|
} |
140 |
|
|
141 |
19 |
TEST_F(TestApiBlackOp, getIndicesString) |
142 |
|
{ |
143 |
4 |
Op x; |
144 |
4 |
ASSERT_THROW(x.getIndices<std::string>(), CVC5ApiException); |
145 |
|
|
146 |
4 |
Op divisible_ot = d_solver.mkOp(DIVISIBLE, 4); |
147 |
2 |
ASSERT_TRUE(divisible_ot.isIndexed()); |
148 |
4 |
std::string divisible_idx = divisible_ot.getIndices<std::string>(); |
149 |
2 |
ASSERT_EQ(divisible_idx, "4"); |
150 |
|
} |
151 |
|
|
152 |
19 |
TEST_F(TestApiBlackOp, getIndicesUint) |
153 |
|
{ |
154 |
4 |
Op bitvector_repeat_ot = d_solver.mkOp(BITVECTOR_REPEAT, 5); |
155 |
2 |
ASSERT_TRUE(bitvector_repeat_ot.isIndexed()); |
156 |
2 |
uint32_t bitvector_repeat_idx = bitvector_repeat_ot.getIndices<uint32_t>(); |
157 |
2 |
ASSERT_EQ(bitvector_repeat_idx, 5); |
158 |
4 |
ASSERT_THROW( |
159 |
|
(bitvector_repeat_ot.getIndices<std::pair<uint32_t, uint32_t>>()), |
160 |
2 |
CVC5ApiException); |
161 |
|
|
162 |
4 |
Op bitvector_zero_extend_ot = d_solver.mkOp(BITVECTOR_ZERO_EXTEND, 6); |
163 |
|
uint32_t bitvector_zero_extend_idx = |
164 |
2 |
bitvector_zero_extend_ot.getIndices<uint32_t>(); |
165 |
2 |
ASSERT_EQ(bitvector_zero_extend_idx, 6); |
166 |
|
|
167 |
4 |
Op bitvector_sign_extend_ot = d_solver.mkOp(BITVECTOR_SIGN_EXTEND, 7); |
168 |
|
uint32_t bitvector_sign_extend_idx = |
169 |
2 |
bitvector_sign_extend_ot.getIndices<uint32_t>(); |
170 |
2 |
ASSERT_EQ(bitvector_sign_extend_idx, 7); |
171 |
|
|
172 |
4 |
Op bitvector_rotate_left_ot = d_solver.mkOp(BITVECTOR_ROTATE_LEFT, 8); |
173 |
|
uint32_t bitvector_rotate_left_idx = |
174 |
2 |
bitvector_rotate_left_ot.getIndices<uint32_t>(); |
175 |
2 |
ASSERT_EQ(bitvector_rotate_left_idx, 8); |
176 |
|
|
177 |
4 |
Op bitvector_rotate_right_ot = d_solver.mkOp(BITVECTOR_ROTATE_RIGHT, 9); |
178 |
|
uint32_t bitvector_rotate_right_idx = |
179 |
2 |
bitvector_rotate_right_ot.getIndices<uint32_t>(); |
180 |
2 |
ASSERT_EQ(bitvector_rotate_right_idx, 9); |
181 |
|
|
182 |
4 |
Op int_to_bitvector_ot = d_solver.mkOp(INT_TO_BITVECTOR, 10); |
183 |
2 |
uint32_t int_to_bitvector_idx = int_to_bitvector_ot.getIndices<uint32_t>(); |
184 |
2 |
ASSERT_EQ(int_to_bitvector_idx, 10); |
185 |
|
|
186 |
4 |
Op floatingpoint_to_ubv_ot = d_solver.mkOp(FLOATINGPOINT_TO_UBV, 11); |
187 |
|
uint32_t floatingpoint_to_ubv_idx = |
188 |
2 |
floatingpoint_to_ubv_ot.getIndices<uint32_t>(); |
189 |
2 |
ASSERT_EQ(floatingpoint_to_ubv_idx, 11); |
190 |
|
|
191 |
4 |
Op floatingpoint_to_sbv_ot = d_solver.mkOp(FLOATINGPOINT_TO_SBV, 13); |
192 |
|
uint32_t floatingpoint_to_sbv_idx = |
193 |
2 |
floatingpoint_to_sbv_ot.getIndices<uint32_t>(); |
194 |
2 |
ASSERT_EQ(floatingpoint_to_sbv_idx, 13); |
195 |
|
} |
196 |
|
|
197 |
19 |
TEST_F(TestApiBlackOp, getIndicesPairUint) |
198 |
|
{ |
199 |
4 |
Op bitvector_extract_ot = d_solver.mkOp(BITVECTOR_EXTRACT, 4, 0); |
200 |
2 |
ASSERT_TRUE(bitvector_extract_ot.isIndexed()); |
201 |
|
std::pair<uint32_t, uint32_t> bitvector_extract_indices = |
202 |
2 |
bitvector_extract_ot.getIndices<std::pair<uint32_t, uint32_t>>(); |
203 |
2 |
ASSERT_TRUE( |
204 |
2 |
(bitvector_extract_indices == std::pair<uint32_t, uint32_t>{4, 0})); |
205 |
|
|
206 |
|
Op floatingpoint_to_fp_ieee_bitvector_ot = |
207 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_IEEE_BITVECTOR, 4, 25); |
208 |
|
std::pair<uint32_t, uint32_t> floatingpoint_to_fp_ieee_bitvector_indices = |
209 |
|
floatingpoint_to_fp_ieee_bitvector_ot |
210 |
2 |
.getIndices<std::pair<uint32_t, uint32_t>>(); |
211 |
2 |
ASSERT_TRUE((floatingpoint_to_fp_ieee_bitvector_indices |
212 |
2 |
== std::pair<uint32_t, uint32_t>{4, 25})); |
213 |
|
|
214 |
|
Op floatingpoint_to_fp_floatingpoint_ot = |
215 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_FLOATINGPOINT, 4, 25); |
216 |
|
std::pair<uint32_t, uint32_t> floatingpoint_to_fp_floatingpoint_indices = |
217 |
|
floatingpoint_to_fp_floatingpoint_ot |
218 |
2 |
.getIndices<std::pair<uint32_t, uint32_t>>(); |
219 |
2 |
ASSERT_TRUE((floatingpoint_to_fp_floatingpoint_indices |
220 |
2 |
== std::pair<uint32_t, uint32_t>{4, 25})); |
221 |
|
|
222 |
|
Op floatingpoint_to_fp_real_ot = |
223 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_REAL, 4, 25); |
224 |
|
std::pair<uint32_t, uint32_t> floatingpoint_to_fp_real_indices = |
225 |
2 |
floatingpoint_to_fp_real_ot.getIndices<std::pair<uint32_t, uint32_t>>(); |
226 |
2 |
ASSERT_TRUE((floatingpoint_to_fp_real_indices |
227 |
2 |
== std::pair<uint32_t, uint32_t>{4, 25})); |
228 |
|
|
229 |
|
Op floatingpoint_to_fp_signed_bitvector_ot = |
230 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR, 4, 25); |
231 |
|
std::pair<uint32_t, uint32_t> floatingpoint_to_fp_signed_bitvector_indices = |
232 |
|
floatingpoint_to_fp_signed_bitvector_ot |
233 |
2 |
.getIndices<std::pair<uint32_t, uint32_t>>(); |
234 |
2 |
ASSERT_TRUE((floatingpoint_to_fp_signed_bitvector_indices |
235 |
2 |
== std::pair<uint32_t, uint32_t>{4, 25})); |
236 |
|
|
237 |
|
Op floatingpoint_to_fp_unsigned_bitvector_ot = |
238 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR, 4, 25); |
239 |
|
std::pair<uint32_t, uint32_t> floatingpoint_to_fp_unsigned_bitvector_indices = |
240 |
|
floatingpoint_to_fp_unsigned_bitvector_ot |
241 |
2 |
.getIndices<std::pair<uint32_t, uint32_t>>(); |
242 |
2 |
ASSERT_TRUE((floatingpoint_to_fp_unsigned_bitvector_indices |
243 |
2 |
== std::pair<uint32_t, uint32_t>{4, 25})); |
244 |
|
|
245 |
|
Op floatingpoint_to_fp_generic_ot = |
246 |
4 |
d_solver.mkOp(FLOATINGPOINT_TO_FP_GENERIC, 4, 25); |
247 |
|
std::pair<uint32_t, uint32_t> floatingpoint_to_fp_generic_indices = |
248 |
|
floatingpoint_to_fp_generic_ot |
249 |
2 |
.getIndices<std::pair<uint32_t, uint32_t>>(); |
250 |
2 |
ASSERT_TRUE((floatingpoint_to_fp_generic_indices |
251 |
2 |
== std::pair<uint32_t, uint32_t>{4, 25})); |
252 |
4 |
ASSERT_THROW(floatingpoint_to_fp_generic_ot.getIndices<std::string>(), |
253 |
2 |
CVC5ApiException); |
254 |
|
} |
255 |
|
|
256 |
19 |
TEST_F(TestApiBlackOp, getIndicesVector) |
257 |
|
{ |
258 |
4 |
std::vector<uint32_t> indices = {0, 3, 2, 0, 1, 2}; |
259 |
4 |
Op tuple_project_op = d_solver.mkOp(TUPLE_PROJECT, indices); |
260 |
|
|
261 |
2 |
ASSERT_TRUE(tuple_project_op.isIndexed()); |
262 |
|
std::vector<Term> tuple_project_extract_indices = |
263 |
4 |
tuple_project_op.getIndices<std::vector<Term>>(); |
264 |
4 |
ASSERT_THROW(tuple_project_op.getIndices<std::string>(), CVC5ApiException); |
265 |
14 |
for (size_t i = 0; i < indices.size(); i++) |
266 |
|
{ |
267 |
12 |
ASSERT_EQ(indices[i], tuple_project_extract_indices[i].getUInt32Value()); |
268 |
12 |
ASSERT_EQ(indices[i], tuple_project_op[i].getUInt32Value()); |
269 |
|
} |
270 |
|
} |
271 |
|
|
272 |
19 |
TEST_F(TestApiBlackOp, opScopingToString) |
273 |
|
{ |
274 |
4 |
Op bitvector_repeat_ot = d_solver.mkOp(BITVECTOR_REPEAT, 5); |
275 |
4 |
std::string op_repr = bitvector_repeat_ot.toString(); |
276 |
4 |
Solver solver2; |
277 |
2 |
ASSERT_EQ(bitvector_repeat_ot.toString(), op_repr); |
278 |
|
} |
279 |
|
} // namespace test |
280 |
33 |
} // namespace cvc5 |