File: OpTest.java

package info (click to toggle)
cvc5 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 87,260 kB
  • sloc: cpp: 383,850; java: 12,207; python: 12,090; sh: 5,679; ansic: 4,729; lisp: 763; perl: 208; makefile: 38
file content (215 lines) | stat: -rw-r--r-- 8,032 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/******************************************************************************
 * Top contributors (to current version):
 *   Andres Noetzli, Aina Niemetz, Mudathir Mohamed
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2025 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * Black box testing of the Op class.
 */

package tests;
import static io.github.cvc5.Kind.*;
import static org.junit.jupiter.api.Assertions.*;

import io.github.cvc5.*;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class OpTest
{
  private TermManager d_tm;

  @BeforeEach
  void setUp()
  {
    d_tm = new TermManager();
  }

  @AfterEach
  void tearDown()
  {
    Context.deletePointers();
  }

  @Test
  void hash() throws CVC5ApiException
  {
    Op ext1 = d_tm.mkOp(BITVECTOR_EXTRACT, 31, 1);
    Op ext2 = d_tm.mkOp(BITVECTOR_EXTRACT, 31, 2);
    assertEquals(ext1.hashCode(), ext1.hashCode());
    assertNotEquals(ext1.hashCode(), ext2.hashCode());
    assertNotEquals(ext1.hashCode(), (new Op()).hashCode());
  }

  @Test
  void getKind() throws CVC5ApiException
  {
    Op x;
    x = d_tm.mkOp(BITVECTOR_EXTRACT, 31, 1);
    assertDoesNotThrow(() -> x.getKind());
  }

  @Test
  void isNull() throws CVC5ApiException
  {
    Op x = new Op();
    assertTrue(x.isNull());
    Op y = d_tm.mkOp(BITVECTOR_EXTRACT, 31, 1);
    assertFalse(y.isNull());
    assertTrue(x != y);
  }

  @Test
  void opFromKind()
  {
    assertDoesNotThrow(() -> d_tm.mkOp(ADD));
    assertThrows(CVC5ApiException.class, () -> d_tm.mkOp(BITVECTOR_EXTRACT));
  }

  @Test
  void getNumIndices() throws CVC5ApiException
  {
    // Operators with 0 indices
    Op plus = d_tm.mkOp(ADD);

    assertEquals(0, plus.getNumIndices());

    // Operators with 1 index
    Op divisible = d_tm.mkOp(DIVISIBLE, 4);
    Op bvRepeat = d_tm.mkOp(BITVECTOR_REPEAT, 5);
    Op bvZeroExtend = d_tm.mkOp(BITVECTOR_ZERO_EXTEND, 6);
    Op bvSignExtend = d_tm.mkOp(BITVECTOR_SIGN_EXTEND, 7);
    Op bvRotateLeft = d_tm.mkOp(BITVECTOR_ROTATE_LEFT, 8);
    Op bvRotateRight = d_tm.mkOp(BITVECTOR_ROTATE_RIGHT, 9);
    Op intToBv = d_tm.mkOp(INT_TO_BITVECTOR, 10);
    Op iand = d_tm.mkOp(IAND, 11);
    Op fpToUbv = d_tm.mkOp(FLOATINGPOINT_TO_UBV, 12);
    Op fpToSbv = d_tm.mkOp(FLOATINGPOINT_TO_SBV, 13);

    assertEquals(1, divisible.getNumIndices());
    assertEquals(1, bvRepeat.getNumIndices());
    assertEquals(1, bvZeroExtend.getNumIndices());
    assertEquals(1, bvSignExtend.getNumIndices());
    assertEquals(1, bvRotateLeft.getNumIndices());
    assertEquals(1, bvRotateRight.getNumIndices());
    assertEquals(1, intToBv.getNumIndices());
    assertEquals(1, iand.getNumIndices());
    assertEquals(1, fpToUbv.getNumIndices());
    assertEquals(1, fpToSbv.getNumIndices());

    // Operators with 2 indices
    Op bvExtract = d_tm.mkOp(BITVECTOR_EXTRACT, 1, 0);
    Op toFpFromIeeeBv = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_IEEE_BV, 3, 2);
    Op toFpFromFp = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_FP, 5, 4);
    Op toFpFromReal = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_REAL, 7, 6);
    Op toFpFromSbv = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_SBV, 9, 8);
    Op toFpFromUbv = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_UBV, 11, 10);
    Op regexpLoop = d_tm.mkOp(REGEXP_LOOP, 15, 14);

    assertEquals(2, bvExtract.getNumIndices());
    assertEquals(2, toFpFromIeeeBv.getNumIndices());
    assertEquals(2, toFpFromFp.getNumIndices());
    assertEquals(2, toFpFromReal.getNumIndices());
    assertEquals(2, toFpFromSbv.getNumIndices());
    assertEquals(2, toFpFromUbv.getNumIndices());
    assertEquals(2, regexpLoop.getNumIndices());

    // Operators with n indices
    int[] indices = {0, 3, 2, 0, 1, 2};
    Op tupleProject = d_tm.mkOp(TUPLE_PROJECT, indices);
    assertEquals(6, tupleProject.getNumIndices());

    Op relationProject = d_tm.mkOp(RELATION_PROJECT, indices);
    assertEquals(6, relationProject.getNumIndices());

    Op tableProject = d_tm.mkOp(TABLE_PROJECT, indices);
    assertEquals(6, tableProject.getNumIndices());
  }

  @Test
  void opSubscriptOperator() throws CVC5ApiException
  {
    // Operators with 0 indices
    Op plus = d_tm.mkOp(ADD);

    assertThrows(CVC5ApiException.class, () -> plus.get(0));

    // Operators with 1 index
    Op divisible = d_tm.mkOp(DIVISIBLE, 4);
    Op bvRepeat = d_tm.mkOp(BITVECTOR_REPEAT, 5);
    Op bvZeroExtend = d_tm.mkOp(BITVECTOR_ZERO_EXTEND, 6);
    Op bvSignExtend = d_tm.mkOp(BITVECTOR_SIGN_EXTEND, 7);
    Op bvRotateLeft = d_tm.mkOp(BITVECTOR_ROTATE_LEFT, 8);
    Op bvRotateRight = d_tm.mkOp(BITVECTOR_ROTATE_RIGHT, 9);
    Op intToBv = d_tm.mkOp(INT_TO_BITVECTOR, 10);
    Op iand = d_tm.mkOp(IAND, 11);
    Op fpToUbv = d_tm.mkOp(FLOATINGPOINT_TO_UBV, 12);
    Op fpToSbv = d_tm.mkOp(FLOATINGPOINT_TO_SBV, 13);
    Op regexpRepeat = d_tm.mkOp(REGEXP_REPEAT, 14);

    assertEquals(4, divisible.get(0).getIntegerValue().intValue());
    assertEquals(5, bvRepeat.get(0).getIntegerValue().intValue());
    assertEquals(6, bvZeroExtend.get(0).getIntegerValue().intValue());
    assertEquals(7, bvSignExtend.get(0).getIntegerValue().intValue());
    assertEquals(8, bvRotateLeft.get(0).getIntegerValue().intValue());
    assertEquals(9, bvRotateRight.get(0).getIntegerValue().intValue());
    assertEquals(10, intToBv.get(0).getIntegerValue().intValue());
    assertEquals(11, iand.get(0).getIntegerValue().intValue());
    assertEquals(12, fpToUbv.get(0).getIntegerValue().intValue());
    assertEquals(13, fpToSbv.get(0).getIntegerValue().intValue());
    assertEquals(14, regexpRepeat.get(0).getIntegerValue().intValue());

    // Operators with 2 indices
    Op bvExtract = d_tm.mkOp(BITVECTOR_EXTRACT, 1, 0);
    Op toFpFromIeeeBv = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_IEEE_BV, 3, 2);
    Op toFpFromFp = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_FP, 5, 4);
    Op toFpFromReal = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_REAL, 7, 6);
    Op toFpFromSbv = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_SBV, 9, 8);
    Op toFpFromUbv = d_tm.mkOp(FLOATINGPOINT_TO_FP_FROM_UBV, 11, 10);
    Op regexpLoop = d_tm.mkOp(REGEXP_LOOP, 15, 14);

    assertEquals(1, bvExtract.get(0).getIntegerValue().intValue());
    assertEquals(0, bvExtract.get(1).getIntegerValue().intValue());
    assertEquals(3, toFpFromIeeeBv.get(0).getIntegerValue().intValue());
    assertEquals(2, toFpFromIeeeBv.get(1).getIntegerValue().intValue());
    assertEquals(5, toFpFromFp.get(0).getIntegerValue().intValue());
    assertEquals(4, toFpFromFp.get(1).getIntegerValue().intValue());
    assertEquals(7, toFpFromReal.get(0).getIntegerValue().intValue());
    assertEquals(6, toFpFromReal.get(1).getIntegerValue().intValue());
    assertEquals(9, toFpFromSbv.get(0).getIntegerValue().intValue());
    assertEquals(8, toFpFromSbv.get(1).getIntegerValue().intValue());
    assertEquals(11, toFpFromUbv.get(0).getIntegerValue().intValue());
    assertEquals(10, toFpFromUbv.get(1).getIntegerValue().intValue());
    assertEquals(15, regexpLoop.get(0).getIntegerValue().intValue());
    assertEquals(14, regexpLoop.get(1).getIntegerValue().intValue());

    // Operators with n indices
    int[] indices = {0, 3, 2, 0, 1, 2};
    Op tupleProject = d_tm.mkOp(TUPLE_PROJECT, indices);
    for (int i = 0, size = tupleProject.getNumIndices(); i < size; i++)
    {
      assertEquals(indices[i], tupleProject.get(i).getIntegerValue().intValue());
    }
  }

  @Test
  void opScopingToString() throws CVC5ApiException
  {
    Op bitvector_repeat_ot = d_tm.mkOp(BITVECTOR_REPEAT, 5);
    String op_repr = bitvector_repeat_ot.toString();

    Solver solver2;
    assertEquals(bitvector_repeat_ot.toString(), op_repr);
  }
}