This PR adds tests for almost everything that is not yet covered by the java API tests.
private native void addConstructor(long pointer, long declPointer);
/** Get the number of constructors (so far) for this Datatype declaration. */
- int getNumConstructors()
+ public int getNumConstructors()
{
return getNumConstructors(pointer);
}
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
}
+/*
+ * Class: io_github_cvc5_Solver
+ * Method: declarePool
+ * Signature: (Ljava/lang/String;J[J])J
+ */
+JNIEXPORT jlong JNICALL Java_io_github_cvc5_Solver_declarePool(
+ JNIEnv* env, jobject, jlong pointer, jstring jsymbol, jlong sort, jlongArray initValuePointers)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Solver* solver = reinterpret_cast<Solver*>(pointer);
+ const char* s = env->GetStringUTFChars(jsymbol, nullptr);
+ std::string symbol(s);
+ Sort* sortptr = reinterpret_cast<Sort*>(sort);
+ std::vector<Term> initValue = getObjectsFromPointers<Term>(env, initValuePointers);
+ Term* retPointer = new Term(solver->declarePool(symbol, *sortptr, initValue));
+ return reinterpret_cast<jlong>(retPointer);
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
+}
+
/*
* Class: io_github_cvc5_Solver
* Method: pop
cvc5_add_java_api_test(ResultTest)
cvc5_add_java_api_test(SolverTest)
cvc5_add_java_api_test(SortTest)
+cvc5_add_java_api_test(SynthResultTest)
cvc5_add_java_api_test(TermTest)
cvc5_add_unit_test_white(UncoveredTest api/java)
assertDoesNotThrow(() -> nilConstr.getTerm());
}
+ @Test
+ void isNull() throws CVC5ApiException
+ {
+ // creating empty (null) objects.
+ DatatypeDecl dtypeSpec = null;
+ DatatypeConstructorDecl cons = null;
+ Datatype d = null;
+ DatatypeConstructor consConstr = null;
+ DatatypeSelector sel = null;
+
+ // verifying that the objects are considered null.
+ assertNull(dtypeSpec);
+ assertNull(cons);
+ assertNull(d);
+ assertNull(consConstr);
+ assertNull(sel);
+
+ // changing the objects to be non-null
+ dtypeSpec = d_solver.mkDatatypeDecl("list");
+ cons = d_solver.mkDatatypeConstructorDecl("cons");
+ cons.addSelector("head", d_solver.getIntegerSort());
+ dtypeSpec.addConstructor(cons);
+ assertEquals(dtypeSpec.getNumConstructors(), 1);
+ assertFalse(dtypeSpec.isParametric());
+ Sort listSort = d_solver.mkDatatypeSort(dtypeSpec);
+ d = listSort.getDatatype();
+ consConstr = d.getConstructor(0);
+ sel = consConstr.getSelector(0);
+
+ // verifying that the new objects are non-null
+ assertFalse(dtypeSpec.isNull());
+ assertFalse(cons.isNull());
+ assertFalse(d.isNull());
+ assertFalse(consConstr.isNull());
+ assertFalse(sel.isNull());
+
+ cons.toString();
+ sel.toString();
+ consConstr.toString();
+ d.toString();
+ }
+
@Test
void mkDatatypeSorts() throws CVC5ApiException
{
d_solver.close();
}
+ @Test
+ void testToString()
+ {
+ d_solver.setOption("sygus", "true");
+ Sort bool = d_solver.getBooleanSort();
+ Term start = d_solver.mkVar(bool);
+ Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
+ g.addRule(start, d_solver.mkBoolean(false));
+ g.toString();
+ }
+
@Test
void addRule()
{
int[] indices = {0, 3, 2, 0, 1, 2};
Op tupleProject = d_solver.mkOp(TUPLE_PROJECT, indices);
assertEquals(6, tupleProject.getNumIndices());
+
+ Op tableProject = d_solver.mkOp(TABLE_PROJECT, indices);
+ assertEquals(6, tableProject.getNumIndices());
}
@Test
}
}
+ @Test
+ void getAssertions()
+ {
+ Term a = d_solver.mkConst(d_solver.getBooleanSort(), "a");
+ Term b = d_solver.mkConst(d_solver.getBooleanSort(), "b");
+ d_solver.assertFormula(a);
+ d_solver.assertFormula(b);
+ Term[] asserts = d_solver.getAssertions();
+ assertEquals(asserts[0], a);
+ assertEquals(asserts[1], b);
+ }
+
@Test
void getInfo()
{
assertNotEquals(output, output2);
}
+ @Test
+ void declarePool() throws CVC5ApiException
+ {
+ Sort intSort = d_solver.getIntegerSort();
+ Sort setSort = d_solver.mkSetSort(intSort);
+ Term zero = d_solver.mkInteger(0);
+ Term x = d_solver.mkConst(intSort, "x");
+ Term y = d_solver.mkConst(intSort, "y");
+ // declare a pool with initial value { 0, x, y }
+ Term p = d_solver.declarePool("p", intSort, new Term[]{zero, x, y});
+ // pool should have the same sort
+ assertEquals(p.getSort(), setSort);
+ }
+
@Test
void getOp() throws CVC5ApiException
{
assertDoesNotThrow(() -> d_solver.getValue(sum));
assertDoesNotThrow(() -> d_solver.getValue(p_f_y));
+ Term[] b = d_solver.getValue(new Term[]{x, y, z});
+
Solver slv = new Solver();
assertThrows(CVC5ApiException.class, () -> slv.getValue(x));
slv.close();
assertDoesNotThrow(() -> d_solver.getNullSort().isDatatypeTester());
}
+ @Test
+ void isDatatypeUpdater() throws CVC5ApiException
+ {
+ Sort dt_sort = create_datatype_sort();
+ Datatype dt = dt_sort.getDatatype();
+ Sort updater_sort = dt.getConstructor(0).getSelector(0).getUpdaterTerm().getSort();
+ assertTrue(updater_sort.isDatatypeUpdater());
+ assertDoesNotThrow(() -> d_solver.getNullSort().isDatatypeUpdater());
+ }
+
@Test
void isFunction()
{
{
};
+TEST_F(TestApiBlackUncovered, comparison_operators)
+{
+ cvc5::Result res;
+ res != res;
+ cvc5::Sort sort;
+ sort != sort;
+ sort <= sort;
+ sort >= sort;
+ sort > sort;
+ cvc5::Op op;
+ op != op;
+ cvc5::Term term;
+ term != term;
+ term <= term;
+ term >= term;
+ term > term;
+}
+
TEST_F(TestApiBlackUncovered, exception_getmessage)
{
d_solver.setOption("produce-models", "true");
}
}
+TEST_F(TestApiBlackUncovered, term_native_types)
+{
+ Term t = d_solver.mkInteger(0);
+ t.isInt32Value();
+ t.getInt32Value();
+ t.isInt64Value();
+ t.getInt64Value();
+ t.isUInt32Value();
+ t.getUInt32Value();
+ t.isUInt64Value();
+ t.getUInt64Value();
+ t.isReal32Value();
+ t.getReal32Value();
+ t.isReal64Value();
+ t.getReal64Value();
+}
+
+TEST_F(TestApiBlackUncovered, term_iterators)
+{
+ Term t = d_solver.mkInteger(0);
+ t = d_solver.mkTerm(Kind::GT, {t, t});
+ Term::const_iterator it;
+ it = t.begin();
+ auto it2(it);
+ it == t.end();
+ it != it2;
+ *it2;
+ ++it;
+ it++;
+}
+
TEST_F(TestApiBlackUncovered, streaming_operators)
{
std::stringstream ss;
ss << cvc5::modes::LearnedLitType::PREPROCESS;
+ ss << cvc5::UnknownExplanation::UNKNOWN_REASON;
ss << cvc5::Result();
ss << cvc5::Op();
ss << cvc5::SynthResult();
+ ss << cvc5::Grammar();
Sort intsort = d_solver.getIntegerSort();
Term x = d_solver.mkConst(intsort, "x");
ss << std::unordered_set<Term>{x, x};
}
+TEST_F(TestApiBlackUncovered, mkString)
+{
+ std::wstring s;
+ ASSERT_EQ(d_solver.mkString(s).getStringValue(), s);
+}
+
TEST_F(TestApiBlackUncovered, hash)
{
std::hash<Op>()(Op());
testing::internal::GetCapturedStdout();
}
+TEST_F(TestApiBlackUncovered, Datatypes)
+{
+ // default constructors
+ DatatypeConstructorDecl dtcd;
+ DatatypeSelector dts;
+ DatatypeConstructor dc;
+ DatatypeDecl dtd;
+ Datatype d;
+
+ dtd = d_solver.mkDatatypeDecl("list");
+ dtcd = d_solver.mkDatatypeConstructorDecl("cons");
+ dtcd.addSelector("head", d_solver.getIntegerSort());
+ dtd.addConstructor(dtcd);
+ Sort s = d_solver.mkDatatypeSort(dtd);
+ d = s.getDatatype();
+ dc = d.getConstructor("cons");
+ dc.getSelector("head");
+
+ {
+ Datatype::const_iterator it;
+ it = d.begin();
+ it != d.end();
+ *it;
+ it->getName();
+ ++it;
+ it == d.end();
+ it++;
+ }
+ {
+ DatatypeConstructor::const_iterator it;
+ it = dc.begin();
+ it != dc.end();
+ *it;
+ it->getName();
+ ++it;
+ it = dc.begin();
+ it++;
+ it == dc.end();
+ }
+
+ {
+ std::stringstream ss;
+ ss << d;
+ ss << dtcd;
+ ss << dc;
+ ss << d.getSelector("head");
+ }
+}
+
} // namespace test
} // namespace cvc5::internal