api: Require size argument for mkBitVector. (#6998)
authorAina Niemetz <aina.niemetz@gmail.com>
Mon, 23 Aug 2021 16:50:06 +0000 (09:50 -0700)
committerGitHub <noreply@github.com>
Mon, 23 Aug 2021 16:50:06 +0000 (16:50 +0000)
This removes support for creating bit-vectors from a string without a
size argument. We further also now require that the base argument is
always given (it has no default value).

examples/api/python/floating_point.py
src/api/cpp/cvc5.cpp
src/api/cpp/cvc5.h
src/api/python/cvc5.pxi
src/parser/cvc/Cvc.g
src/parser/smt2/Smt2.g
test/python/unit/api/test_solver.py
test/python/unit/api/test_term.py
test/unit/api/solver_black.cpp
test/unit/api/term_black.cpp

index 0001f726b0e6875cac9c41de6420cb7e714ca842..d6ba8d7540d9b3355acb29bebd69093c6e9dcc58 100644 (file)
@@ -61,8 +61,14 @@ if __name__ == "__main__":
     slv.pop()
 
     # constrain x, y, z between -3.14 and 3.14 (also disallows NaN and infinity)
-    a = slv.mkFloatingPoint(8, 24, slv.mkBitVector("11000000010010001111010111000011", 2))  # -3.14
-    b = slv.mkFloatingPoint(8, 24, slv.mkBitVector("01000000010010001111010111000011", 2))  # 3.14
+    a = slv.mkFloatingPoint(
+            8,
+            24,
+            slv.mkBitVector(32, "11000000010010001111010111000011", 2)) # -3.14
+    b = slv.mkFloatingPoint(
+            8,
+            24,
+            slv.mkBitVector(32, "01000000010010001111010111000011", 2))  # 3.14
 
     bounds_x = slv.mkTerm(kinds.And, slv.mkTerm(kinds.FPLeq, a, x), slv.mkTerm(kinds.FPLeq, x, b))
     bounds_y = slv.mkTerm(kinds.And, slv.mkTerm(kinds.FPLeq, a, y), slv.mkTerm(kinds.FPLeq, y, b))
index f5e2c8f0ccd001d61cac470040684d634e015670..12c59c0debd133b701438692ac893c21ea7aac08 100644 (file)
@@ -5037,17 +5037,6 @@ Term Solver::mkBVFromIntHelper(uint32_t size, uint64_t val) const
   return mkValHelper<cvc5::BitVector>(cvc5::BitVector(size, val));
 }
 
-Term Solver::mkBVFromStrHelper(const std::string& s, uint32_t base) const
-{
-  CVC5_API_ARG_CHECK_EXPECTED(!s.empty(), s) << "a non-empty string";
-  CVC5_API_ARG_CHECK_EXPECTED(base == 2 || base == 10 || base == 16, base)
-      << "base 2, 10, or 16";
-  CVC5_API_ARG_CHECK_EXPECTED(s[0] != '-', s)
-      << "a positive value (since no size is specified)";
-  //////// all checks before this line
-  return mkValHelper<cvc5::BitVector>(cvc5::BitVector(s, base));
-}
-
 Term Solver::mkBVFromStrHelper(uint32_t size,
                                const std::string& s,
                                uint32_t base) const
@@ -5948,16 +5937,6 @@ Term Solver::mkBitVector(uint32_t size, uint64_t val) const
   CVC5_API_TRY_CATCH_END;
 }
 
-Term Solver::mkBitVector(const std::string& s, uint32_t base) const
-{
-  NodeManagerScope scope(getNodeManager());
-  CVC5_API_TRY_CATCH_BEGIN;
-  //////// all checks before this line
-  return mkBVFromStrHelper(s, base);
-  ////////
-  CVC5_API_TRY_CATCH_END;
-}
-
 Term Solver::mkBitVector(uint32_t size,
                          const std::string& s,
                          uint32_t base) const
index 3226dd4fdd091b0c5f6980bd236265570ca5811d..3c024131160b49d5067057073e54aca89dd30a7b 100644 (file)
@@ -3304,31 +3304,21 @@ class CVC5_EXPORT Solver
 
   /**
    * Create a bit-vector constant of given size and value.
+   *
+   * Note: The given value must fit into a bit-vector of the given size.
+   *
    * @param size the bit-width of the bit-vector sort
    * @param val the value of the constant
    * @return the bit-vector constant
    */
   Term mkBitVector(uint32_t size, uint64_t val = 0) const;
 
-  /**
-   * Create a bit-vector constant from a given string of base 2, 10 or 16.
-   *
-   * The size of resulting bit-vector is
-   * - base  2: the size of the binary string
-   * - base 10: the min. size required to represent the decimal as a bit-vector
-   * - base 16: the max. size required to represent the hexadecimal as a
-   *            bit-vector (4 * size of the given value string)
-   *
-   * @param s The string representation of the constant.
-   *          This cannot be negative.
-   * @param base the base of the string representation (2, 10, or 16)
-   * @return the bit-vector constant
-   */
-  Term mkBitVector(const std::string& s, uint32_t base = 2) const;
-
   /**
    * Create a bit-vector constant of a given bit-width from a given string of
    * base 2, 10 or 16.
+   *
+   * Note: The given value must fit into a bit-vector of the given size.
+   *
    * @param size the bit-width of the constant
    * @param s the string representation of the constant
    * @param base the base of the string representation (2, 10, or 16)
index 210eb0639a25c87628c442eb13be40845bc84cbd..7c9a70642db9980096457919d734c805e95a929e 100644 (file)
@@ -832,7 +832,8 @@ cdef class Solver:
         cdef Py_ssize_t size
         cdef wchar_t* tmp = PyUnicode_AsWideCharString(s, &size)
         if isinstance(useEscSequences, bool):
-            term.cterm = self.csolver.mkString(s.encode(), <bint> useEscSequences)
+            term.cterm = self.csolver.mkString(
+                s.encode(), <bint> useEscSequences)
         else:
             term.cterm = self.csolver.mkString(c_wstring(tmp, size))
         PyMem_Free(tmp)
@@ -853,62 +854,43 @@ cdef class Solver:
         '''
             Supports the following arguments:
             Term mkBitVector(int size, int val=0)
-            Term mkBitVector(string val, int base = 2)
             Term mkBitVector(int size, string val, int base)
          '''
         cdef Term term = Term(self)
+        if len(args) == 0:
+            raise ValueError("Missing arguments to mkBitVector")
+        size = args[0]
+        if not isinstance(size, int):
+            raise ValueError(
+                "Invalid first argument to mkBitVector '{}', "
+                "expected bit-vector size".format(size))
         if len(args) == 1:
-            size_or_val = args[0]
-            if isinstance(args[0], int):
-                size = args[0]
-                term.cterm = self.csolver.mkBitVector(<uint32_t> size)
-            else:
-                assert isinstance(args[0], str)
-                val = args[0]
-                term.cterm = self.csolver.mkBitVector(<const string&> str(val).encode())
+            term.cterm = self.csolver.mkBitVector(<uint32_t> size)
         elif len(args) == 2:
-            if isinstance(args[0], int):
-                size = args[0]
-                assert isinstance(args[1], int)
-                val = args[1]
-                term.cterm = self.csolver.mkBitVector(<uint32_t> size, <uint32_t> val)
-            else:
-                assert isinstance(args[0], str)
-                assert isinstance(args[1], int)
-                val = args[0]
-                base = args[1]
-                term.cterm = self.csolver.mkBitVector(<const string&> str(val).encode(), <uint32_t> base)
+            val = args[1]
+            if not isinstance(val, int):
+                raise ValueError(
+                    "Invalid second argument to mkBitVector '{}', "
+                    "expected integer value".format(size))
+            term.cterm = self.csolver.mkBitVector(
+                <uint32_t> size, <uint32_t> val)
         elif len(args) == 3:
-                assert isinstance(args[0], int)
-                assert isinstance(args[1], str)
-                assert isinstance(args[2], int)
-                size = args[0]
-                val = args[1]
-                base = args[2]
-                term.cterm = self.csolver.mkBitVector(<uint32_t> size, <const string&> str(val).encode(), <uint32_t> base)
-        return term
-
-
-    def mkBitVector(self, size_or_str, val = None):
-        cdef Term term = Term(self)
-        if isinstance(size_or_str, int):
-            if val is None:
-                term.cterm = self.csolver.mkBitVector(<uint32_t> size_or_str)
-            else:
-                term.cterm = self.csolver.mkBitVector(<uint32_t> size_or_str,
-                                                      <const string &> str(val).encode(),
-                                                      10)
-        elif isinstance(size_or_str, str):
-            # handle default value
-            if val is None:
-                term.cterm = self.csolver.mkBitVector(
-                    <const string &> size_or_str.encode())
-            else:
-                term.cterm = self.csolver.mkBitVector(
-                    <const string &> size_or_str.encode(), <uint32_t> val)
+            val = args[1]
+            base = args[2]
+            if not isinstance(val, str):
+                raise ValueError(
+                    "Invalid second argument to mkBitVector '{}', "
+                    "expected value string".format(size))
+            if not isinstance(base, int):
+                raise ValueError(
+                    "Invalid third argument to mkBitVector '{}', "
+                    "expected base given as integer".format(size))
+            term.cterm = self.csolver.mkBitVector(
+                <uint32_t> size,
+                <const string&> str(val).encode(),
+                <uint32_t> base)
         else:
-            raise ValueError("Unexpected inputs {} to"
-                             " mkBitVector".format((size_or_str, val)))
+            raise ValueError("Unexpected inputs to mkBitVector")
         return term
 
     def mkConstArray(self, Sort sort, Term val):
@@ -956,8 +938,9 @@ cdef class Solver:
         try:
             term.cterm = self.csolver.mkAbstractValue(str(index).encode())
         except:
-            raise ValueError("mkAbstractValue expects a str representing a number"
-                             " or an int, but got{}".format(index))
+            raise ValueError(
+                "mkAbstractValue expects a str representing a number"
+                " or an int, but got{}".format(index))
         return term
 
     def mkFloatingPoint(self, int exp, int sig, Term val):
index c0a42ac269bf50f48af768b7179dba6f18ca906b..f0cb0fc78969647d74c8bd305ff12f08160e2b50 100644 (file)
@@ -2196,12 +2196,12 @@ simpleTerm[cvc5::api::Term& f]
   | HEX_LITERAL
     { Assert( AntlrInput::tokenText($HEX_LITERAL).find("0hex") == 0 );
       std::string hexString = AntlrInput::tokenTextSubstr($HEX_LITERAL, 4);
-      f = SOLVER->mkBitVector(hexString, 16);
+      f = SOLVER->mkBitVector(hexString.size() * 4, hexString, 16);
     }
   | BINARY_LITERAL
     { Assert( AntlrInput::tokenText($BINARY_LITERAL).find("0bin") == 0 );
       std::string binString = AntlrInput::tokenTextSubstr($BINARY_LITERAL, 4);
-      f = SOLVER->mkBitVector(binString, 2);
+      f = SOLVER->mkBitVector(binString.size(), binString, 2);
     }
     /* record literals */
   | PARENHASH recordEntry[name,e] { names.push_back(name); args.push_back(e); }
index c3cf3ea667c25b88eb781befb612542fda817f4c..22a042951fb4187d632a7cdfbce4dbacb0107104 100644 (file)
@@ -1756,13 +1756,13 @@ termAtomic[cvc5::api::Term& atomTerm]
     {
       Assert(AntlrInput::tokenText($HEX_LITERAL).find("#x") == 0);
       std::string hexStr = AntlrInput::tokenTextSubstr($HEX_LITERAL, 2);
-      atomTerm = SOLVER->mkBitVector(hexStr, 16);
+      atomTerm = SOLVER->mkBitVector(hexStr.size() * 4, hexStr, 16);
     }
   | BINARY_LITERAL
     {
       Assert(AntlrInput::tokenText($BINARY_LITERAL).find("#b") == 0);
       std::string binStr = AntlrInput::tokenTextSubstr($BINARY_LITERAL, 2);
-      atomTerm = SOLVER->mkBitVector(binStr, 2);
+      atomTerm = SOLVER->mkBitVector(binStr.size(), binStr, 2);
     }
 
   // String constant
index 8b3ce944ed908a577880489c103a185b1c319c73..db49f8beafe43f35e1d87bd0f26a8632705be973 100644 (file)
@@ -291,35 +291,64 @@ def test_mk_tuple_sort(solver):
 
 
 def test_mk_bit_vector(solver):
-    size0 = 0
-    size1 = 8
-    size2 = 32
-    val1 = 2
-    val2 = 2
-    solver.mkBitVector(size1, val1)
-    solver.mkBitVector(size2, val2)
-    solver.mkBitVector("1010", 2)
-    solver.mkBitVector("1010", 10)
-    solver.mkBitVector("1234", 10)
-    solver.mkBitVector("1010", 16)
-    solver.mkBitVector("a09f", 16)
+    solver.mkBitVector(8, 2)
+    solver.mkBitVector(32, 2)
+
+    solver.mkBitVector(4, "1010", 2)
+    solver.mkBitVector(8, "0101", 2)
+    solver.mkBitVector(8, "-1111111", 2)
+    solver.mkBitVector(8, "00000101", 2)
     solver.mkBitVector(8, "-127", 10)
+    solver.mkBitVector(8, "255", 10)
+    solver.mkBitVector(10, "1010", 10)
+    solver.mkBitVector(11, "1234", 10)
+    solver.mkBitVector(8, "-7f", 16)
+    solver.mkBitVector(8, "a0", 16)
+    solver.mkBitVector(16, "1010", 16)
+    solver.mkBitVector(16, "a09f", 16)
+
     with pytest.raises(RuntimeError):
-        solver.mkBitVector(size0, val1)
+        solver.mkBitVector(0, 2)
     with pytest.raises(RuntimeError):
-        solver.mkBitVector(size0, val2)
+        solver.mkBitVector(0, "-127", 10)
     with pytest.raises(RuntimeError):
-        solver.mkBitVector("", 2)
+        solver.mkBitVector(0, "a0", 16)
+
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(2, "", 2)
+
     with pytest.raises(RuntimeError):
-        solver.mkBitVector("10", 3)
+        solver.mkBitVector(8, "101", 5)
     with pytest.raises(RuntimeError):
-        solver.mkBitVector("20", 2)
+        solver.mkBitVector(8, "127", 11)
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "a0", 21)
+
     with pytest.raises(RuntimeError):
         solver.mkBitVector(8, "101010101", 2)
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "-11111111", 2)
     with pytest.raises(RuntimeError):
         solver.mkBitVector(8, "-256", 10)
-    assert solver.mkBitVector("1010", 2) == solver.mkBitVector("10", 10)
-    assert solver.mkBitVector("1010", 2) == solver.mkBitVector("a", 16)
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "257", 10)
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "-a0", 16)
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "fffff", 16)
+
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "10201010", 2)
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "-25x", 10)
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "2x7", 10)
+    with pytest.raises(RuntimeError):
+        solver.mkBitVector(8, "fzff", 16)
+
+    assert solver.mkBitVector(8, "0101", 2) == solver.mkBitVector(8, "00000101", 2)
+    assert solver.mkBitVector(4, "1010", 2) == solver.mkBitVector(4, "10", 10)
+    assert solver.mkBitVector(4, "1010", 2) == solver.mkBitVector(4, "a", 16)
     assert str(solver.mkBitVector(8, "01010101", 2)) == "#b01010101"
     assert str(solver.mkBitVector(8, "F", 16)) == "#b00001111"
     assert solver.mkBitVector(8, "-1", 10) ==\
@@ -820,21 +849,21 @@ def test_mk_true(solver):
 
 
 def test_mk_tuple(solver):
-    solver.mkTuple([solver.mkBitVectorSort(3)], [solver.mkBitVector("101", 2)])
+    solver.mkTuple([solver.mkBitVectorSort(3)], [solver.mkBitVector(3, "101", 2)])
     solver.mkTuple([solver.getRealSort()], [solver.mkInteger("5")])
 
     with pytest.raises(RuntimeError):
-        solver.mkTuple([], [solver.mkBitVector("101", 2)])
+        solver.mkTuple([], [solver.mkBitVector(3, "101", 2)])
     with pytest.raises(RuntimeError):
         solver.mkTuple([solver.mkBitVectorSort(4)],
-                       [solver.mkBitVector("101", 2)])
+                       [solver.mkBitVector(3, "101", 2)])
     with pytest.raises(RuntimeError):
         solver.mkTuple([solver.getIntegerSort()], [solver.mkReal("5.3")])
     slv = pycvc5.Solver()
     with pytest.raises(RuntimeError):
-        slv.mkTuple([solver.mkBitVectorSort(3)], [slv.mkBitVector("101", 2)])
+        slv.mkTuple([solver.mkBitVectorSort(3)], [slv.mkBitVector(3, "101", 2)])
     with pytest.raises(RuntimeError):
-        slv.mkTuple([slv.mkBitVectorSort(3)], [solver.mkBitVector("101", 2)])
+        slv.mkTuple([slv.mkBitVectorSort(3)], [solver.mkBitVector(3, "101", 2)])
 
 
 def test_mk_universe_set(solver):
index e7818807908fb9c1fba416a777deb46bd8ad32cc..e6529967650177affe9bbc6b247f24f96f8b2bad 100644 (file)
@@ -1040,7 +1040,7 @@ def test_get_uninterpreted_const(solver):
 
 
 def test_get_floating_point(solver):
-    bvval = solver.mkBitVector("0000110000000011")
+    bvval = solver.mkBitVector(16, "0000110000000011", 2)
     fp = solver.mkFloatingPoint(5, 11, bvval)
 
     assert fp.isFloatingPointValue()
@@ -1181,12 +1181,12 @@ def test_get_boolean(solver):
 
 def test_get_bit_vector(solver):
     b1 = solver.mkBitVector(8, 15)
-    b2 = solver.mkBitVector("00001111", 2)
-    b3 = solver.mkBitVector("15", 10)
-    b4 = solver.mkBitVector("0f", 16)
-    b5 = solver.mkBitVector(8, "00001111", 2)
-    b6 = solver.mkBitVector(8, "15", 10)
-    b7 = solver.mkBitVector(8, "0f", 16)
+    b2 = solver.mkBitVector(8, "00001111", 2)
+    b3 = solver.mkBitVector(8, "15", 10)
+    b4 = solver.mkBitVector(8, "0f", 16)
+    b5 = solver.mkBitVector(9, "00001111", 2);
+    b6 = solver.mkBitVector(9, "15", 10);
+    b7 = solver.mkBitVector(9, "0f", 16);
 
     assert b1.isBitVectorValue()
     assert b2.isBitVectorValue()
@@ -1202,19 +1202,19 @@ def test_get_bit_vector(solver):
     assert "00001111" == b2.getBitVectorValue(2)
     assert "15" == b2.getBitVectorValue(10)
     assert "f" == b2.getBitVectorValue(16)
-    assert "1111" == b3.getBitVectorValue(2)
+    assert "00001111" == b3.getBitVectorValue(2)
     assert "15" == b3.getBitVectorValue(10)
     assert "f" == b3.getBitVectorValue(16)
     assert "00001111" == b4.getBitVectorValue(2)
     assert "15" == b4.getBitVectorValue(10)
     assert "f" == b4.getBitVectorValue(16)
-    assert "00001111" == b5.getBitVectorValue(2)
+    assert "000001111" == b5.getBitVectorValue(2)
     assert "15" == b5.getBitVectorValue(10)
     assert "f" == b5.getBitVectorValue(16)
-    assert "00001111" == b6.getBitVectorValue(2)
+    assert "000001111" == b6.getBitVectorValue(2)
     assert "15" == b6.getBitVectorValue(10)
     assert "f" == b6.getBitVectorValue(16)
-    assert "00001111" == b7.getBitVectorValue(2)
+    assert "000001111" == b7.getBitVectorValue(2)
     assert "15" == b7.getBitVectorValue(10)
     assert "f" == b7.getBitVectorValue(16)
 
index 0c40074113ec4e415a36152c241d213c12ebcce2..99a60aa76e1c7748c94777f159d53bfa9b4961e4 100644 (file)
@@ -306,34 +306,43 @@ TEST_F(TestApiBlackSolver, mkTupleSort)
 
 TEST_F(TestApiBlackSolver, mkBitVector)
 {
-  uint32_t size0 = 0, size1 = 8, size2 = 32, val1 = 2;
-  uint64_t val2 = 2;
-  ASSERT_NO_THROW(d_solver.mkBitVector(size1, val1));
-  ASSERT_NO_THROW(d_solver.mkBitVector(size2, val2));
-  ASSERT_NO_THROW(d_solver.mkBitVector("1010", 2));
-  ASSERT_NO_THROW(d_solver.mkBitVector("1010", 10));
-  ASSERT_NO_THROW(d_solver.mkBitVector("1234", 10));
-  ASSERT_NO_THROW(d_solver.mkBitVector("1010", 16));
-  ASSERT_NO_THROW(d_solver.mkBitVector("a09f", 16));
+  ASSERT_NO_THROW(d_solver.mkBitVector(8, 2));
+  ASSERT_NO_THROW(d_solver.mkBitVector(32, 2));
+  ASSERT_NO_THROW(d_solver.mkBitVector(8, "-1111111", 2));
+  ASSERT_NO_THROW(d_solver.mkBitVector(8, "0101", 2));
+  ASSERT_NO_THROW(d_solver.mkBitVector(8, "00000101", 2));
   ASSERT_NO_THROW(d_solver.mkBitVector(8, "-127", 10));
-  ASSERT_THROW(d_solver.mkBitVector(size0, val1), CVC5ApiException);
-  ASSERT_THROW(d_solver.mkBitVector(size0, val2), CVC5ApiException);
-  ASSERT_THROW(d_solver.mkBitVector("", 2), CVC5ApiException);
-  ASSERT_THROW(d_solver.mkBitVector("10", 3), CVC5ApiException);
-  ASSERT_THROW(d_solver.mkBitVector("20", 2), CVC5ApiException);
+  ASSERT_NO_THROW(d_solver.mkBitVector(8, "255", 10));
+  ASSERT_NO_THROW(d_solver.mkBitVector(8, "-7f", 16));
+  ASSERT_NO_THROW(d_solver.mkBitVector(8, "a0", 16));
+
+  ASSERT_THROW(d_solver.mkBitVector(0, 2), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(0, "-127", 10), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(0, "a0", 16), CVC5ApiException);
+
+  ASSERT_THROW(d_solver.mkBitVector(8, "", 2), CVC5ApiException);
+
+  ASSERT_THROW(d_solver.mkBitVector(8, "101", 5), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(8, "128", 11), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(8, "a0", 21), CVC5ApiException);
+
+  ASSERT_THROW(d_solver.mkBitVector(8, "-11111111", 2), CVC5ApiException);
   ASSERT_THROW(d_solver.mkBitVector(8, "101010101", 2), CVC5ApiException);
   ASSERT_THROW(d_solver.mkBitVector(8, "-256", 10), CVC5ApiException);
-  // No size and negative string -> error
-  ASSERT_THROW(d_solver.mkBitVector("-1", 2), CVC5ApiException);
-  ASSERT_THROW(d_solver.mkBitVector("-1", 10), CVC5ApiException);
-  ASSERT_THROW(d_solver.mkBitVector("-f", 16), CVC5ApiException);
-  // size and negative string -> ok
+  ASSERT_THROW(d_solver.mkBitVector(8, "257", 10), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(8, "-a0", 16), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(8, "fffff", 16), CVC5ApiException);
+
+  ASSERT_THROW(d_solver.mkBitVector(8, "10201010", 2), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(8, "-25x", 10), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(8, "2x7", 10), CVC5ApiException);
+  ASSERT_THROW(d_solver.mkBitVector(8, "fzff", 16), CVC5ApiException);
+
+  ASSERT_EQ(d_solver.mkBitVector(8, "0101", 2),
+            d_solver.mkBitVector(8, "00000101", 2));
   ASSERT_EQ(d_solver.mkBitVector(4, "-1", 2), d_solver.mkBitVector(4, "1111", 2));
   ASSERT_EQ(d_solver.mkBitVector(4, "-1", 16), d_solver.mkBitVector(4, "1111", 2));
   ASSERT_EQ(d_solver.mkBitVector(4, "-1", 10), d_solver.mkBitVector(4, "1111", 2));
-  ASSERT_EQ(d_solver.mkBitVector("1010", 2), d_solver.mkBitVector("10", 10));
-  ASSERT_EQ(d_solver.mkBitVector("1010", 2), d_solver.mkBitVector("10", 10));
-  ASSERT_EQ(d_solver.mkBitVector("1010", 2), d_solver.mkBitVector("a", 16));
   ASSERT_EQ(d_solver.mkBitVector(8, "01010101", 2).toString(), "#b01010101");
   ASSERT_EQ(d_solver.mkBitVector(8, "F", 16).toString(), "#b00001111");
   ASSERT_EQ(d_solver.mkBitVector(8, "-1", 10),
@@ -778,25 +787,25 @@ TEST_F(TestApiBlackSolver, mkTrue)
 TEST_F(TestApiBlackSolver, mkTuple)
 {
   ASSERT_NO_THROW(d_solver.mkTuple({d_solver.mkBitVectorSort(3)},
-                                   {d_solver.mkBitVector("101", 2)}));
+                                   {d_solver.mkBitVector(3, "101", 2)}));
   ASSERT_NO_THROW(
       d_solver.mkTuple({d_solver.getRealSort()}, {d_solver.mkInteger("5")}));
 
-  ASSERT_THROW(d_solver.mkTuple({}, {d_solver.mkBitVector("101", 2)}),
+  ASSERT_THROW(d_solver.mkTuple({}, {d_solver.mkBitVector(3, "101", 2)}),
                CVC5ApiException);
   ASSERT_THROW(d_solver.mkTuple({d_solver.mkBitVectorSort(4)},
-                                {d_solver.mkBitVector("101", 2)}),
+                                {d_solver.mkBitVector(3, "101", 2)}),
                CVC5ApiException);
   ASSERT_THROW(
       d_solver.mkTuple({d_solver.getIntegerSort()}, {d_solver.mkReal("5.3")}),
       CVC5ApiException);
   Solver slv;
-  ASSERT_THROW(
-      slv.mkTuple({d_solver.mkBitVectorSort(3)}, {slv.mkBitVector("101", 2)}),
-      CVC5ApiException);
-  ASSERT_THROW(
-      slv.mkTuple({slv.mkBitVectorSort(3)}, {d_solver.mkBitVector("101", 2)}),
-      CVC5ApiException);
+  ASSERT_THROW(slv.mkTuple({d_solver.mkBitVectorSort(3)},
+                           {slv.mkBitVector(3, "101", 2)}),
+               CVC5ApiException);
+  ASSERT_THROW(slv.mkTuple({slv.mkBitVectorSort(3)},
+                           {d_solver.mkBitVector(3, "101", 2)}),
+               CVC5ApiException);
 }
 
 TEST_F(TestApiBlackSolver, mkUniverseSet)
index 96ee1ba47a01d1d518201770c8379a41b0c7ce6a..fe5838cd4c34d14a14873e23bbb0d8cc20ca333b 100644 (file)
@@ -845,12 +845,12 @@ TEST_F(TestApiBlackTerm, getBoolean)
 TEST_F(TestApiBlackTerm, getBitVector)
 {
   Term b1 = d_solver.mkBitVector(8, 15);
-  Term b2 = d_solver.mkBitVector("00001111", 2);
-  Term b3 = d_solver.mkBitVector("15", 10);
-  Term b4 = d_solver.mkBitVector("0f", 16);
-  Term b5 = d_solver.mkBitVector(8, "00001111", 2);
-  Term b6 = d_solver.mkBitVector(8, "15", 10);
-  Term b7 = d_solver.mkBitVector(8, "0f", 16);
+  Term b2 = d_solver.mkBitVector(8, "00001111", 2);
+  Term b3 = d_solver.mkBitVector(8, "15", 10);
+  Term b4 = d_solver.mkBitVector(8, "0f", 16);
+  Term b5 = d_solver.mkBitVector(9, "00001111", 2);
+  Term b6 = d_solver.mkBitVector(9, "15", 10);
+  Term b7 = d_solver.mkBitVector(9, "0f", 16);
 
   ASSERT_TRUE(b1.isBitVectorValue());
   ASSERT_TRUE(b2.isBitVectorValue());
@@ -866,19 +866,19 @@ TEST_F(TestApiBlackTerm, getBitVector)
   ASSERT_EQ("00001111", b2.getBitVectorValue(2));
   ASSERT_EQ("15", b2.getBitVectorValue(10));
   ASSERT_EQ("f", b2.getBitVectorValue(16));
-  ASSERT_EQ("1111", b3.getBitVectorValue(2));
+  ASSERT_EQ("00001111", b3.getBitVectorValue(2));
   ASSERT_EQ("15", b3.getBitVectorValue(10));
   ASSERT_EQ("f", b3.getBitVectorValue(16));
   ASSERT_EQ("00001111", b4.getBitVectorValue(2));
   ASSERT_EQ("15", b4.getBitVectorValue(10));
   ASSERT_EQ("f", b4.getBitVectorValue(16));
-  ASSERT_EQ("00001111", b5.getBitVectorValue(2));
+  ASSERT_EQ("000001111", b5.getBitVectorValue(2));
   ASSERT_EQ("15", b5.getBitVectorValue(10));
   ASSERT_EQ("f", b5.getBitVectorValue(16));
-  ASSERT_EQ("00001111", b6.getBitVectorValue(2));
+  ASSERT_EQ("000001111", b6.getBitVectorValue(2));
   ASSERT_EQ("15", b6.getBitVectorValue(10));
   ASSERT_EQ("f", b6.getBitVectorValue(16));
-  ASSERT_EQ("00001111", b7.getBitVectorValue(2));
+  ASSERT_EQ("000001111", b7.getBitVectorValue(2));
   ASSERT_EQ("15", b7.getBitVectorValue(10));
   ASSERT_EQ("f", b7.getBitVectorValue(16));
 }
@@ -915,7 +915,7 @@ TEST_F(TestApiBlackTerm, getTuple)
 
 TEST_F(TestApiBlackTerm, getFloatingPoint)
 {
-  Term bvval = d_solver.mkBitVector("0000110000000011");
+  Term bvval = d_solver.mkBitVector(16, "0000110000000011", 2);
   Term fp = d_solver.mkFloatingPoint(5, 11, bvval);
 
   ASSERT_TRUE(fp.isFloatingPointValue());