summaryrefslogtreecommitdiff
path: root/test/unit/theory/strings_rewriter_white.h
blob: f5c7cced8f300d4bf502a99935dbc8b569511cf2 (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
/*********************                                                        */
/*! \file strings_rewriter_white.h
 ** \verbatim
 ** Top contributors (to current version):
 **   Andres Noetzli
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2020 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.\endverbatim
 **
 ** \brief Unit tests for the strings rewriter
 **
 ** Unit tests for the strings rewriter.
 **/

#include <cxxtest/TestSuite.h>

#include <iostream>
#include <memory>
#include <vector>

#include "expr/node.h"
#include "expr/node_manager.h"
#include "smt/smt_engine.h"
#include "smt/smt_engine_scope.h"
#include "theory/rewriter.h"
#include "theory/strings/strings_rewriter.h"

using namespace CVC4;
using namespace CVC4::kind;
using namespace CVC4::smt;
using namespace CVC4::theory;
using namespace CVC4::theory::strings;

class StringsRewriterWhite : public CxxTest::TestSuite
{
 public:
  StringsRewriterWhite() {}

  void setUp() override
  {
    Options opts;
    opts.setOutputLanguage(language::output::LANG_SMTLIB_V2);
    d_em = new ExprManager;
    d_nm = NodeManager::fromExprManager(d_em);
    d_smt = new SmtEngine(d_nm, &opts);
    d_scope = new SmtScope(d_smt);
    d_smt->finishInit();
  }

  void tearDown() override
  {
    delete d_scope;
    delete d_smt;
    delete d_em;
  }

  void testRewriteLeq()
  {
    TypeNode intType = d_nm->integerType();
    TypeNode strType = d_nm->stringType();

    Node a = d_nm->mkConst(::CVC4::String("A"));
    Node bc = d_nm->mkConst(::CVC4::String("BC"));
    Node x = d_nm->mkVar("x", strType);
    Node y = d_nm->mkVar("y", strType);

    Node ax = d_nm->mkNode(STRING_CONCAT, a, x);
    Node bcy = d_nm->mkNode(STRING_CONCAT, bc, y);

    {
      Node leq = d_nm->mkNode(STRING_LEQ, ax, bcy);
      TS_ASSERT_EQUALS(Rewriter::rewrite(leq), d_nm->mkConst(true));
    }

    {
      Node leq = d_nm->mkNode(STRING_LEQ, bcy, ax);
      TS_ASSERT_EQUALS(Rewriter::rewrite(leq), d_nm->mkConst(false));
    }
  }

 private:
  ExprManager* d_em;
  SmtEngine* d_smt;
  SmtScope* d_scope;

  NodeManager* d_nm;
};
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback