2021-04-12 12:31:43 -07:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
|
|
|
|
* Aina Niemetz, Andres Noetzli
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the cvc5 project.
|
|
|
|
|
*
|
2022-04-05 13:38:57 -07:00
|
|
|
* Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
|
2021-04-12 12:31:43 -07:00
|
|
|
* 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.
|
|
|
|
|
* ****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* White box testing of cvc5::Node.
|
|
|
|
|
*/
|
2021-02-08 12:03:05 -08:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "base/check.h"
|
2021-04-06 09:33:52 -07:00
|
|
|
#include "expr/node_builder.h"
|
2021-02-08 12:03:05 -08:00
|
|
|
#include "test_node.h"
|
2021-05-26 07:30:17 -07:00
|
|
|
#include "util/rational.h"
|
2021-02-08 12:03:05 -08:00
|
|
|
|
2022-03-29 16:23:01 -07:00
|
|
|
namespace cvc5::internal {
|
2021-02-08 12:03:05 -08:00
|
|
|
|
|
|
|
|
using namespace kind;
|
|
|
|
|
using namespace expr;
|
|
|
|
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2021-02-25 11:44:48 -08:00
|
|
|
class TestNodeWhiteNode : public TestNode
|
2021-02-08 12:03:05 -08:00
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(TestNodeWhiteNode, null) { ASSERT_EQ(Node::null(), Node::s_null); }
|
|
|
|
|
|
|
|
|
|
TEST_F(TestNodeWhiteNode, copy_ctor) { Node e(Node::s_null); }
|
|
|
|
|
|
|
|
|
|
TEST_F(TestNodeWhiteNode, builder)
|
|
|
|
|
{
|
2021-04-06 09:33:52 -07:00
|
|
|
NodeBuilder b;
|
2021-02-08 12:03:05 -08:00
|
|
|
ASSERT_TRUE(b.d_nv->getId() == 0);
|
|
|
|
|
ASSERT_TRUE(b.d_nv->getKind() == UNDEFINED_KIND);
|
|
|
|
|
ASSERT_EQ(b.d_nv->d_nchildren, 0u);
|
|
|
|
|
/* etc. */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TestNodeWhiteNode, iterators)
|
|
|
|
|
{
|
|
|
|
|
Node x = d_nodeManager->mkVar("x", d_nodeManager->integerType());
|
|
|
|
|
Node y = d_nodeManager->mkVar("y", d_nodeManager->integerType());
|
2022-02-02 20:25:14 -08:00
|
|
|
Node x_plus_y = d_nodeManager->mkNode(ADD, x, y);
|
2022-05-02 21:36:33 -05:00
|
|
|
Node two = d_nodeManager->mkConstInt(Rational(2));
|
2021-02-08 12:03:05 -08:00
|
|
|
Node x_times_2 = d_nodeManager->mkNode(MULT, x, two);
|
|
|
|
|
|
2022-02-02 20:25:14 -08:00
|
|
|
Node n = d_nodeManager->mkNode(ADD, x_times_2, x_plus_y, y);
|
2021-02-08 12:03:05 -08:00
|
|
|
|
|
|
|
|
Node::iterator i;
|
|
|
|
|
|
|
|
|
|
i = std::find(n.begin(), n.end(), x_plus_y);
|
|
|
|
|
ASSERT_TRUE(i != n.end());
|
|
|
|
|
ASSERT_TRUE(*i == x_plus_y);
|
|
|
|
|
|
|
|
|
|
i = std::find(n.begin(), n.end(), x);
|
|
|
|
|
ASSERT_TRUE(i == n.end());
|
|
|
|
|
|
|
|
|
|
i = std::find(x_times_2.begin(), x_times_2.end(), two);
|
|
|
|
|
ASSERT_TRUE(i != x_times_2.end());
|
|
|
|
|
ASSERT_TRUE(*i == two);
|
|
|
|
|
|
|
|
|
|
i = std::find(n.begin(), n.end(), y);
|
|
|
|
|
ASSERT_TRUE(i != n.end());
|
|
|
|
|
ASSERT_TRUE(*i == y);
|
|
|
|
|
|
|
|
|
|
std::vector<Node> v;
|
|
|
|
|
copy(n.begin(), n.end(), back_inserter(v));
|
|
|
|
|
ASSERT_EQ(n.getNumChildren(), v.size());
|
|
|
|
|
ASSERT_EQ(3, v.size());
|
|
|
|
|
ASSERT_EQ(v[0], x_times_2);
|
|
|
|
|
ASSERT_EQ(v[1], x_plus_y);
|
|
|
|
|
ASSERT_EQ(v[2], y);
|
|
|
|
|
}
|
|
|
|
|
} // namespace test
|
2022-03-29 16:23:01 -07:00
|
|
|
} // namespace cvc5::internal
|