Fix issue with str.idof in evaluator (#2493)
authorAndres Noetzli <andres.noetzli@gmail.com>
Tue, 18 Sep 2018 23:01:13 +0000 (16:01 -0700)
committerAndrew Reynolds <andrew.j.reynolds@gmail.com>
Tue, 18 Sep 2018 23:01:13 +0000 (18:01 -0500)
src/theory/evaluator.cpp
test/unit/theory/evaluator_white.h

index 4285a65cf209aaa83b615a869e679d6657df0904..25e20451ae7d1042722d41b234759beda2afff2a 100644 (file)
@@ -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));
           }
index 10cb15f6fc53e95442a42b5e3d655719cb9a8e1c..73556c388fd2d2f2ab17c3994fef1dfc173fb8ba 100644 (file)
@@ -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<Node> args;
+    std::vector<Node> 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));
+    }
+  }
 };