GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/node/node_white.cpp Lines: 35 35 100.0 %
Date: 2021-09-17 Branches: 107 342 31.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Aina Niemetz, Andres Noetzli
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
 * White box testing of cvc5::Node.
14
 */
15
16
#include <string>
17
18
#include "base/check.h"
19
#include "expr/node_builder.h"
20
#include "test_node.h"
21
#include "util/rational.h"
22
23
namespace cvc5 {
24
25
using namespace kind;
26
using namespace expr;
27
28
namespace test {
29
30
16
class TestNodeWhiteNode : public TestNode
31
{
32
};
33
34
13
TEST_F(TestNodeWhiteNode, null) { ASSERT_EQ(Node::null(), Node::s_null); }
35
36
13
TEST_F(TestNodeWhiteNode, copy_ctor) { Node e(Node::s_null); }
37
38
13
TEST_F(TestNodeWhiteNode, builder)
39
{
40
4
  NodeBuilder b;
41
2
  ASSERT_TRUE(b.d_nv->getId() == 0);
42
2
  ASSERT_TRUE(b.d_nv->getKind() == UNDEFINED_KIND);
43
2
  ASSERT_EQ(b.d_nv->d_nchildren, 0u);
44
  /* etc. */
45
}
46
47
13
TEST_F(TestNodeWhiteNode, iterators)
48
{
49
4
  Node x = d_nodeManager->mkVar("x", d_nodeManager->integerType());
50
4
  Node y = d_nodeManager->mkVar("y", d_nodeManager->integerType());
51
4
  Node x_plus_y = d_nodeManager->mkNode(PLUS, x, y);
52
4
  Node two = d_nodeManager->mkConst(Rational(2));
53
4
  Node x_times_2 = d_nodeManager->mkNode(MULT, x, two);
54
55
4
  Node n = d_nodeManager->mkNode(PLUS, x_times_2, x_plus_y, y);
56
57
2
  Node::iterator i;
58
59
2
  i = std::find(n.begin(), n.end(), x_plus_y);
60
2
  ASSERT_TRUE(i != n.end());
61
2
  ASSERT_TRUE(*i == x_plus_y);
62
63
2
  i = std::find(n.begin(), n.end(), x);
64
2
  ASSERT_TRUE(i == n.end());
65
66
2
  i = std::find(x_times_2.begin(), x_times_2.end(), two);
67
2
  ASSERT_TRUE(i != x_times_2.end());
68
2
  ASSERT_TRUE(*i == two);
69
70
2
  i = std::find(n.begin(), n.end(), y);
71
2
  ASSERT_TRUE(i != n.end());
72
2
  ASSERT_TRUE(*i == y);
73
74
4
  std::vector<Node> v;
75
2
  copy(n.begin(), n.end(), back_inserter(v));
76
2
  ASSERT_EQ(n.getNumChildren(), v.size());
77
2
  ASSERT_EQ(3, v.size());
78
2
  ASSERT_EQ(v[0], x_times_2);
79
2
  ASSERT_EQ(v[1], x_plus_y);
80
2
  ASSERT_EQ(v[2], y);
81
}
82
}  // namespace test
83
34635
}  // namespace cvc5