GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/theory/theory_arith_white.cpp Lines: 52 52 100.0 %
Date: 2021-08-06 Branches: 155 402 38.6 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Aina Niemetz, Tim King, Gereon Kremer
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Whitebox tests for theory Arithmetic.
14
 */
15
16
#include <list>
17
#include <vector>
18
19
#include "context/context.h"
20
#include "expr/node.h"
21
#include "test_smt.h"
22
#include "theory/arith/theory_arith.h"
23
#include "theory/quantifiers_engine.h"
24
#include "theory/theory.h"
25
#include "theory/theory_engine.h"
26
#include "util/rational.h"
27
28
namespace cvc5 {
29
30
using namespace theory;
31
using namespace theory::arith;
32
using namespace expr;
33
using namespace context;
34
using namespace kind;
35
using namespace smt;
36
37
namespace test {
38
39
8
class TestTheoryWhiteArith : public TestSmtNoFinishInit
40
{
41
 protected:
42
4
  void SetUp() override
43
  {
44
4
    TestSmtNoFinishInit::SetUp();
45
4
    d_smtEngine->setOption("incremental", "false");
46
4
    d_smtEngine->finishInit();
47
4
    d_arith = static_cast<TheoryArith*>(
48
4
        d_smtEngine->getTheoryEngine()->d_theoryTable[THEORY_ARITH]);
49
50
4
    d_realType.reset(new TypeNode(d_nodeManager->realType()));
51
4
    d_intType.reset(new TypeNode(d_nodeManager->integerType()));
52
4
  }
53
54
2
  void fakeTheoryEnginePreprocess(TNode input)
55
  {
56
2
    Assert(input == Rewriter::rewrite(input));
57
2
    d_smtEngine->getTheoryEngine()->preRegister(input);
58
2
  }
59
60
  Theory::Effort d_level = Theory::EFFORT_FULL;
61
  TheoryArith* d_arith;
62
  std::unique_ptr<TypeNode> d_realType;
63
  std::unique_ptr<TypeNode> d_intType;
64
  const Rational d_zero = 0;
65
  const Rational d_one = 1;
66
};
67
68
11
TEST_F(TestTheoryWhiteArith, assert)
69
{
70
4
  Node x = d_nodeManager->mkVar(*d_realType);
71
4
  Node c = d_nodeManager->mkConst<Rational>(d_zero);
72
73
4
  Node gt = d_nodeManager->mkNode(GT, x, c);
74
4
  Node leq = Rewriter::rewrite(gt.notNode());
75
2
  fakeTheoryEnginePreprocess(leq);
76
77
2
  d_arith->assertFact(leq, true);
78
79
2
  d_arith->check(d_level);
80
2
}
81
82
11
TEST_F(TestTheoryWhiteArith, int_normal_form)
83
{
84
4
  Node x = d_nodeManager->mkVar(*d_intType);
85
4
  Node xr = d_nodeManager->mkVar(*d_realType);
86
4
  Node c0 = d_nodeManager->mkConst<Rational>(d_zero);
87
4
  Node c1 = d_nodeManager->mkConst<Rational>(d_one);
88
4
  Node c2 = d_nodeManager->mkConst<Rational>(Rational(2));
89
90
4
  Node geq0 = d_nodeManager->mkNode(GEQ, x, c0);
91
4
  Node geq1 = d_nodeManager->mkNode(GEQ, x, c1);
92
4
  Node geq2 = d_nodeManager->mkNode(GEQ, x, c2);
93
94
2
  ASSERT_EQ(Rewriter::rewrite(geq0), geq0);
95
2
  ASSERT_EQ(Rewriter::rewrite(geq1), geq1);
96
97
4
  Node gt0 = d_nodeManager->mkNode(GT, x, c0);
98
4
  Node gt1 = d_nodeManager->mkNode(GT, x, c1);
99
100
2
  ASSERT_EQ(Rewriter::rewrite(gt0), Rewriter::rewrite(geq1));
101
2
  ASSERT_EQ(Rewriter::rewrite(gt1), Rewriter::rewrite(geq2));
102
103
4
  Node lt0 = d_nodeManager->mkNode(LT, x, c0);
104
4
  Node lt1 = d_nodeManager->mkNode(LT, x, c1);
105
106
2
  ASSERT_EQ(Rewriter::rewrite(lt0), Rewriter::rewrite(geq0.notNode()));
107
2
  ASSERT_EQ(Rewriter::rewrite(lt1), Rewriter::rewrite(geq1.notNode()));
108
109
4
  Node leq0 = d_nodeManager->mkNode(LEQ, x, c0);
110
4
  Node leq1 = d_nodeManager->mkNode(LEQ, x, c1);
111
112
2
  ASSERT_EQ(Rewriter::rewrite(leq0), Rewriter::rewrite(geq1.notNode()));
113
2
  ASSERT_EQ(Rewriter::rewrite(leq1), Rewriter::rewrite(geq2.notNode()));
114
115
  // (abs x) --> (abs x)
116
4
  Node absX = d_nodeManager->mkNode(ABS, x);
117
2
  ASSERT_EQ(Rewriter::rewrite(absX), absX);
118
119
  // (exp (+ 2 + x)) --> (* (exp x) (exp 1) (exp 1))
120
  Node t =
121
4
      d_nodeManager->mkNode(EXPONENTIAL, d_nodeManager->mkNode(PLUS, c2, xr))
122
4
          .eqNode(c0);
123
2
  ASSERT_EQ(Rewriter::rewrite(Rewriter::rewrite(t)), Rewriter::rewrite(t));
124
}
125
}  // namespace test
126
213523
}  // namespace cvc5