GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/api/op_black.cpp Lines: 123 123 100.0 %
Date: 2021-05-22 Branches: 278 920 30.2 %

Line Exec Source
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
32
class TestApiBlackOp : public TestApi
25
{
26
};
27
28
17
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
17
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
17
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
17
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
17
TEST_F(TestApiBlackOp, getIndicesString)
96
{
97
4
  Op x;
98
4
  ASSERT_THROW(x.getIndices<std::string>(), CVC5ApiException);
99
100
4
  Op divisible_ot = d_solver.mkOp(DIVISIBLE, 4);
101
2
  ASSERT_TRUE(divisible_ot.isIndexed());
102
4
  std::string divisible_idx = divisible_ot.getIndices<std::string>();
103
2
  ASSERT_EQ(divisible_idx, "4");
104
}
105
106
17
TEST_F(TestApiBlackOp, getIndicesUint)
107
{
108
4
  Op bitvector_repeat_ot = d_solver.mkOp(BITVECTOR_REPEAT, 5);
109
2
  ASSERT_TRUE(bitvector_repeat_ot.isIndexed());
110
2
  uint32_t bitvector_repeat_idx = bitvector_repeat_ot.getIndices<uint32_t>();
111
2
  ASSERT_EQ(bitvector_repeat_idx, 5);
112
4
  ASSERT_THROW(
113
      (bitvector_repeat_ot.getIndices<std::pair<uint32_t, uint32_t>>()),
114
2
      CVC5ApiException);
115
116
4
  Op bitvector_zero_extend_ot = d_solver.mkOp(BITVECTOR_ZERO_EXTEND, 6);
117
  uint32_t bitvector_zero_extend_idx =
118
2
      bitvector_zero_extend_ot.getIndices<uint32_t>();
119
2
  ASSERT_EQ(bitvector_zero_extend_idx, 6);
120
121
4
  Op bitvector_sign_extend_ot = d_solver.mkOp(BITVECTOR_SIGN_EXTEND, 7);
122
  uint32_t bitvector_sign_extend_idx =
123
2
      bitvector_sign_extend_ot.getIndices<uint32_t>();
124
2
  ASSERT_EQ(bitvector_sign_extend_idx, 7);
125
126
4
  Op bitvector_rotate_left_ot = d_solver.mkOp(BITVECTOR_ROTATE_LEFT, 8);
127
  uint32_t bitvector_rotate_left_idx =
128
2
      bitvector_rotate_left_ot.getIndices<uint32_t>();
129
2
  ASSERT_EQ(bitvector_rotate_left_idx, 8);
130
131
4
  Op bitvector_rotate_right_ot = d_solver.mkOp(BITVECTOR_ROTATE_RIGHT, 9);
132
  uint32_t bitvector_rotate_right_idx =
133
2
      bitvector_rotate_right_ot.getIndices<uint32_t>();
134
2
  ASSERT_EQ(bitvector_rotate_right_idx, 9);
135
136
4
  Op int_to_bitvector_ot = d_solver.mkOp(INT_TO_BITVECTOR, 10);
137
2
  uint32_t int_to_bitvector_idx = int_to_bitvector_ot.getIndices<uint32_t>();
138
2
  ASSERT_EQ(int_to_bitvector_idx, 10);
139
140
4
  Op floatingpoint_to_ubv_ot = d_solver.mkOp(FLOATINGPOINT_TO_UBV, 11);
141
  uint32_t floatingpoint_to_ubv_idx =
142
2
      floatingpoint_to_ubv_ot.getIndices<uint32_t>();
143
2
  ASSERT_EQ(floatingpoint_to_ubv_idx, 11);
144
145
4
  Op floatingpoint_to_sbv_ot = d_solver.mkOp(FLOATINGPOINT_TO_SBV, 13);
146
  uint32_t floatingpoint_to_sbv_idx =
147
2
      floatingpoint_to_sbv_ot.getIndices<uint32_t>();
148
2
  ASSERT_EQ(floatingpoint_to_sbv_idx, 13);
149
}
150
151
17
TEST_F(TestApiBlackOp, getIndicesPairUint)
152
{
153
4
  Op bitvector_extract_ot = d_solver.mkOp(BITVECTOR_EXTRACT, 4, 0);
154
2
  ASSERT_TRUE(bitvector_extract_ot.isIndexed());
155
  std::pair<uint32_t, uint32_t> bitvector_extract_indices =
156
2
      bitvector_extract_ot.getIndices<std::pair<uint32_t, uint32_t>>();
157
2
  ASSERT_TRUE(
158
2
      (bitvector_extract_indices == std::pair<uint32_t, uint32_t>{4, 0}));
159
160
  Op floatingpoint_to_fp_ieee_bitvector_ot =
161
4
      d_solver.mkOp(FLOATINGPOINT_TO_FP_IEEE_BITVECTOR, 4, 25);
162
  std::pair<uint32_t, uint32_t> floatingpoint_to_fp_ieee_bitvector_indices =
163
      floatingpoint_to_fp_ieee_bitvector_ot
164
2
          .getIndices<std::pair<uint32_t, uint32_t>>();
165
2
  ASSERT_TRUE((floatingpoint_to_fp_ieee_bitvector_indices
166
2
               == std::pair<uint32_t, uint32_t>{4, 25}));
167
168
  Op floatingpoint_to_fp_floatingpoint_ot =
169
4
      d_solver.mkOp(FLOATINGPOINT_TO_FP_FLOATINGPOINT, 4, 25);
170
  std::pair<uint32_t, uint32_t> floatingpoint_to_fp_floatingpoint_indices =
171
      floatingpoint_to_fp_floatingpoint_ot
172
2
          .getIndices<std::pair<uint32_t, uint32_t>>();
173
2
  ASSERT_TRUE((floatingpoint_to_fp_floatingpoint_indices
174
2
               == std::pair<uint32_t, uint32_t>{4, 25}));
175
176
  Op floatingpoint_to_fp_real_ot =
177
4
      d_solver.mkOp(FLOATINGPOINT_TO_FP_REAL, 4, 25);
178
  std::pair<uint32_t, uint32_t> floatingpoint_to_fp_real_indices =
179
2
      floatingpoint_to_fp_real_ot.getIndices<std::pair<uint32_t, uint32_t>>();
180
2
  ASSERT_TRUE((floatingpoint_to_fp_real_indices
181
2
               == std::pair<uint32_t, uint32_t>{4, 25}));
182
183
  Op floatingpoint_to_fp_signed_bitvector_ot =
184
4
      d_solver.mkOp(FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR, 4, 25);
185
  std::pair<uint32_t, uint32_t> floatingpoint_to_fp_signed_bitvector_indices =
186
      floatingpoint_to_fp_signed_bitvector_ot
187
2
          .getIndices<std::pair<uint32_t, uint32_t>>();
188
2
  ASSERT_TRUE((floatingpoint_to_fp_signed_bitvector_indices
189
2
               == std::pair<uint32_t, uint32_t>{4, 25}));
190
191
  Op floatingpoint_to_fp_unsigned_bitvector_ot =
192
4
      d_solver.mkOp(FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR, 4, 25);
193
  std::pair<uint32_t, uint32_t> floatingpoint_to_fp_unsigned_bitvector_indices =
194
      floatingpoint_to_fp_unsigned_bitvector_ot
195
2
          .getIndices<std::pair<uint32_t, uint32_t>>();
196
2
  ASSERT_TRUE((floatingpoint_to_fp_unsigned_bitvector_indices
197
2
               == std::pair<uint32_t, uint32_t>{4, 25}));
198
199
  Op floatingpoint_to_fp_generic_ot =
200
4
      d_solver.mkOp(FLOATINGPOINT_TO_FP_GENERIC, 4, 25);
201
  std::pair<uint32_t, uint32_t> floatingpoint_to_fp_generic_indices =
202
      floatingpoint_to_fp_generic_ot
203
2
          .getIndices<std::pair<uint32_t, uint32_t>>();
204
2
  ASSERT_TRUE((floatingpoint_to_fp_generic_indices
205
2
               == std::pair<uint32_t, uint32_t>{4, 25}));
206
4
  ASSERT_THROW(floatingpoint_to_fp_generic_ot.getIndices<std::string>(),
207
2
               CVC5ApiException);
208
}
209
210
17
TEST_F(TestApiBlackOp, opScopingToString)
211
{
212
4
  Op bitvector_repeat_ot = d_solver.mkOp(BITVECTOR_REPEAT, 5);
213
4
  std::string op_repr = bitvector_repeat_ot.toString();
214
4
  Solver solver2;
215
2
  ASSERT_EQ(bitvector_repeat_ot.toString(), op_repr);
216
}
217
}  // namespace test
218
27
}  // namespace cvc5