From f87b7ee8fb224eada44eda07a59e01d113f769df Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Tue, 18 Sep 2018 16:01:13 -0700 Subject: [PATCH] Fix issue with str.idof in evaluator (#2493) --- src/theory/evaluator.cpp | 2 +- test/unit/theory/evaluator_white.h | 37 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/theory/evaluator.cpp b/src/theory/evaluator.cpp index 4285a65cf..25e20451a 100644 --- a/src/theory/evaluator.cpp +++ b/src/theory/evaluator.cpp @@ -355,7 +355,7 @@ EvalResult Evaluator::evalInternal(TNode n, const String& x = results[currNode[1]].d_str; Integer i = results[currNode[2]].d_rat.getNumerator(); - if (i.strictlyNegative() || i >= s_len) + if (i.strictlyNegative()) { results[currNode] = EvalResult(Rational(-1)); } diff --git a/test/unit/theory/evaluator_white.h b/test/unit/theory/evaluator_white.h index 10cb15f6f..73556c388 100644 --- a/test/unit/theory/evaluator_white.h +++ b/test/unit/theory/evaluator_white.h @@ -26,6 +26,7 @@ #include "theory/evaluator.h" #include "theory/rewriter.h" #include "theory/theory_test_utils.h" +#include "util/rational.h" using namespace CVC4; using namespace CVC4::smt; @@ -119,4 +120,40 @@ class TheoryEvaluatorWhite : public CxxTest::TestSuite Rewriter::rewrite(t.substitute( args.begin(), args.end(), vals.begin(), vals.end()))); } + + void testStrIdOf() + { + Node a = d_nm->mkConst(String("A")); + Node empty = d_nm->mkConst(String("")); + Node one = d_nm->mkConst(Rational(1)); + Node two = d_nm->mkConst(Rational(2)); + + std::vector args; + std::vector vals; + Evaluator eval; + + { + Node n = d_nm->mkNode(kind::STRING_STRIDOF, a, empty, one); + Node r = eval.eval(n, args, vals); + TS_ASSERT_EQUALS(r, Rewriter::rewrite(n)); + } + + { + Node n = d_nm->mkNode(kind::STRING_STRIDOF, a, a, one); + Node r = eval.eval(n, args, vals); + TS_ASSERT_EQUALS(r, Rewriter::rewrite(n)); + } + + { + Node n = d_nm->mkNode(kind::STRING_STRIDOF, a, empty, two); + Node r = eval.eval(n, args, vals); + TS_ASSERT_EQUALS(r, Rewriter::rewrite(n)); + } + + { + Node n = d_nm->mkNode(kind::STRING_STRIDOF, a, a, two); + Node r = eval.eval(n, args, vals); + TS_ASSERT_EQUALS(r, Rewriter::rewrite(n)); + } + } }; -- 2.30.2