summaryrefslogtreecommitdiff
path: root/test/unit/api/java/cvc5/OpTest.java
blob: afe728b88cc3c2ba9e024f3f5a96724d1ccac23f (plain)
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
/******************************************************************************
 * Top contributors (to current version):
 *   Makai Mann, Aina Niemetz, Mudathir Mohamed
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 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 cvc5;

import static cvc5.Kind.*;
import static org.junit.jupiter.api.Assertions.*;

import java.util.Arrays;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class OpTest {
  private Solver d_solver;

  @BeforeEach
  void setUp() {
    d_solver = new Solver();
  }

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

  @Test
  void isNull() throws CVC5ApiException {
    Op x = d_solver.getNullOp();
    assertTrue(x.isNull());
    x = d_solver.mkOp(BITVECTOR_EXTRACT, 31, 1);
    assertFalse(x.isNull());
  }

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

  @Test
  void getIndicesString() throws CVC5ApiException {
    Op x = d_solver.getNullOp();
    assertThrows(CVC5ApiException.class, () -> x.getStringIndices());

    Op divisible_ot = d_solver.mkOp(DIVISIBLE, 4);
    assertTrue(divisible_ot.isIndexed());
    String divisible_idx = divisible_ot.getStringIndices()[0];
    assertEquals(divisible_idx, "4");
  }

  @Test
  void getIndicesUint() throws CVC5ApiException {
    Op bitvector_repeat_ot = d_solver.mkOp(BITVECTOR_REPEAT, 5);
    assertTrue(bitvector_repeat_ot.isIndexed());
    int bitvector_repeat_idx = bitvector_repeat_ot.getIntegerIndices()[0];
    assertEquals(bitvector_repeat_idx, 5);

    // unlike bitvector_repeat_ot.getIndices<std::pair<uint32_t, uint32_t>>() in
    // c++, this does not throw in Java
    // assertThrows(CVC5ApiException.class,
    //              () -> bitvector_repeat_ot.getIntegerIndices());

    Op bitvector_zero_extend_ot = d_solver.mkOp(BITVECTOR_ZERO_EXTEND, 6);
    int bitvector_zero_extend_idx =
        bitvector_zero_extend_ot.getIntegerIndices()[0];
    assertEquals(bitvector_zero_extend_idx, 6);

    Op bitvector_sign_extend_ot = d_solver.mkOp(BITVECTOR_SIGN_EXTEND, 7);
    int bitvector_sign_extend_idx =
        bitvector_sign_extend_ot.getIntegerIndices()[0];
    assertEquals(bitvector_sign_extend_idx, 7);

    Op bitvector_rotate_left_ot = d_solver.mkOp(BITVECTOR_ROTATE_LEFT, 8);
    int bitvector_rotate_left_idx =
        bitvector_rotate_left_ot.getIntegerIndices()[0];
    assertEquals(bitvector_rotate_left_idx, 8);

    Op bitvector_rotate_right_ot = d_solver.mkOp(BITVECTOR_ROTATE_RIGHT, 9);
    int bitvector_rotate_right_idx =
        bitvector_rotate_right_ot.getIntegerIndices()[0];
    assertEquals(bitvector_rotate_right_idx, 9);

    Op int_to_bitvector_ot = d_solver.mkOp(INT_TO_BITVECTOR, 10);
    int int_to_bitvector_idx = int_to_bitvector_ot.getIntegerIndices()[0];
    assertEquals(int_to_bitvector_idx, 10);

    Op floatingpoint_to_ubv_ot = d_solver.mkOp(FLOATINGPOINT_TO_UBV, 11);
    int floatingpoint_to_ubv_idx =
        floatingpoint_to_ubv_ot.getIntegerIndices()[0];
    assertEquals(floatingpoint_to_ubv_idx, 11);

    Op floatingpoint_to_sbv_ot = d_solver.mkOp(FLOATINGPOINT_TO_SBV, 13);
    int floatingpoint_to_sbv_idx =
        floatingpoint_to_sbv_ot.getIntegerIndices()[0];
    assertEquals(floatingpoint_to_sbv_idx, 13);
  }

  @Test
  void getIndicesPairUint() throws CVC5ApiException {
    Op bitvector_extract_ot = d_solver.mkOp(BITVECTOR_EXTRACT, 4, 0);
    assertTrue(bitvector_extract_ot.isIndexed());
    int[] bitvector_extract_indices = bitvector_extract_ot.getIntegerIndices();
    assertArrayEquals(bitvector_extract_indices, new int[] {4, 0});

    Op floatingpoint_to_fp_ieee_bitvector_ot =
        d_solver.mkOp(FLOATINGPOINT_TO_FP_IEEE_BITVECTOR, 4, 25);
    int[] floatingpoint_to_fp_ieee_bitvector_indices =
        floatingpoint_to_fp_ieee_bitvector_ot.getIntegerIndices();
    assertArrayEquals(
        floatingpoint_to_fp_ieee_bitvector_indices, new int[] {4, 25});

    Op floatingpoint_to_fp_floatingpoint_ot =
        d_solver.mkOp(FLOATINGPOINT_TO_FP_FLOATINGPOINT, 4, 25);
    int[] floatingpoint_to_fp_floatingpoint_indices =
        floatingpoint_to_fp_floatingpoint_ot.getIntegerIndices();
    assertArrayEquals(
        floatingpoint_to_fp_floatingpoint_indices, new int[] {4, 25});

    Op floatingpoint_to_fp_real_ot =
        d_solver.mkOp(FLOATINGPOINT_TO_FP_REAL, 4, 25);
    int[] floatingpoint_to_fp_real_indices =
        floatingpoint_to_fp_real_ot.getIntegerIndices();
    assertArrayEquals(floatingpoint_to_fp_real_indices, new int[] {4, 25});

    Op floatingpoint_to_fp_signed_bitvector_ot =
        d_solver.mkOp(FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR, 4, 25);
    int[] floatingpoint_to_fp_signed_bitvector_indices =
        floatingpoint_to_fp_signed_bitvector_ot.getIntegerIndices();
    assertArrayEquals(
        floatingpoint_to_fp_signed_bitvector_indices, new int[] {4, 25});

    Op floatingpoint_to_fp_unsigned_bitvector_ot =
        d_solver.mkOp(FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR, 4, 25);
    int[] floatingpoint_to_fp_unsigned_bitvector_indices =
        floatingpoint_to_fp_unsigned_bitvector_ot.getIntegerIndices();
    assertArrayEquals(
        floatingpoint_to_fp_unsigned_bitvector_indices, new int[] {4, 25});

    Op floatingpoint_to_fp_generic_ot =
        d_solver.mkOp(FLOATINGPOINT_TO_FP_GENERIC, 4, 25);
    int[] floatingpoint_to_fp_generic_indices =
        floatingpoint_to_fp_generic_ot.getIntegerIndices();
    assertArrayEquals(floatingpoint_to_fp_generic_indices, new int[] {4, 25});
    assertThrows(CVC5ApiException.class,
        () -> floatingpoint_to_fp_generic_ot.getStringIndices());
  }

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

    Solver solver2;
    assertEquals(bitvector_repeat_ot.toString(), op_repr);
  }
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback