GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/node/symbol_table_black.cpp Lines: 74 74 100.0 %
Date: 2021-08-06 Branches: 203 590 34.4 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Aina Niemetz, Morgan Deters, Christopher L. Conway
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
 * Black box testing of cvc5::SymbolTable.
14
 */
15
16
#include <sstream>
17
#include <string>
18
19
#include "base/check.h"
20
#include "base/exception.h"
21
#include "context/context.h"
22
#include "expr/kind.h"
23
#include "expr/symbol_table.h"
24
#include "test_api.h"
25
26
namespace cvc5 {
27
28
using namespace kind;
29
using namespace context;
30
31
namespace test {
32
33
36
class TestNodeBlackSymbolTable : public TestApi
34
{
35
};
36
37
18
TEST_F(TestNodeBlackSymbolTable, bind1)
38
{
39
4
  SymbolTable symtab;
40
4
  api::Sort booleanType = d_solver.getBooleanSort();
41
4
  api::Term x = d_solver.mkConst(booleanType);
42
2
  symtab.bind("x", x);
43
2
  ASSERT_TRUE(symtab.isBound("x"));
44
2
  ASSERT_EQ(symtab.lookup("x"), x);
45
}
46
47
18
TEST_F(TestNodeBlackSymbolTable, bind2)
48
{
49
4
  SymbolTable symtab;
50
4
  api::Sort booleanType = d_solver.getBooleanSort();
51
  // var name attribute shouldn't matter
52
4
  api::Term y = d_solver.mkConst(booleanType, "y");
53
2
  symtab.bind("x", y);
54
2
  ASSERT_TRUE(symtab.isBound("x"));
55
2
  ASSERT_EQ(symtab.lookup("x"), y);
56
}
57
58
18
TEST_F(TestNodeBlackSymbolTable, bind3)
59
{
60
4
  SymbolTable symtab;
61
4
  api::Sort booleanType = d_solver.getBooleanSort();
62
4
  api::Term x = d_solver.mkConst(booleanType);
63
2
  symtab.bind("x", x);
64
4
  api::Term y = d_solver.mkConst(booleanType);
65
  // new binding covers old
66
2
  symtab.bind("x", y);
67
2
  ASSERT_TRUE(symtab.isBound("x"));
68
2
  ASSERT_EQ(symtab.lookup("x"), y);
69
}
70
71
18
TEST_F(TestNodeBlackSymbolTable, bind4)
72
{
73
4
  SymbolTable symtab;
74
4
  api::Sort booleanType = d_solver.getBooleanSort();
75
4
  api::Term x = d_solver.mkConst(booleanType);
76
2
  symtab.bind("x", x);
77
78
4
  api::Sort t = d_solver.mkUninterpretedSort("T");
79
  // duplicate binding for type is OK
80
2
  symtab.bindType("x", t);
81
82
2
  ASSERT_TRUE(symtab.isBound("x"));
83
2
  ASSERT_EQ(symtab.lookup("x"), x);
84
2
  ASSERT_TRUE(symtab.isBoundType("x"));
85
2
  ASSERT_EQ(symtab.lookupType("x"), t);
86
}
87
88
18
TEST_F(TestNodeBlackSymbolTable, bind_type1)
89
{
90
4
  SymbolTable symtab;
91
4
  api::Sort s = d_solver.mkUninterpretedSort("S");
92
2
  symtab.bindType("S", s);
93
2
  ASSERT_TRUE(symtab.isBoundType("S"));
94
2
  ASSERT_EQ(symtab.lookupType("S"), s);
95
}
96
97
18
TEST_F(TestNodeBlackSymbolTable, bind_type2)
98
{
99
4
  SymbolTable symtab;
100
  // type name attribute shouldn't matter
101
4
  api::Sort s = d_solver.mkUninterpretedSort("S");
102
2
  symtab.bindType("T", s);
103
2
  ASSERT_TRUE(symtab.isBoundType("T"));
104
2
  ASSERT_EQ(symtab.lookupType("T"), s);
105
}
106
107
18
TEST_F(TestNodeBlackSymbolTable, bind_type3)
108
{
109
4
  SymbolTable symtab;
110
4
  api::Sort s = d_solver.mkUninterpretedSort("S");
111
2
  symtab.bindType("S", s);
112
4
  api::Sort t = d_solver.mkUninterpretedSort("T");
113
  // new binding covers old
114
2
  symtab.bindType("S", t);
115
2
  ASSERT_TRUE(symtab.isBoundType("S"));
116
2
  ASSERT_EQ(symtab.lookupType("S"), t);
117
}
118
119
18
TEST_F(TestNodeBlackSymbolTable, push_scope)
120
{
121
4
  SymbolTable symtab;
122
4
  api::Sort booleanType = d_solver.getBooleanSort();
123
4
  api::Term x = d_solver.mkConst(booleanType);
124
2
  symtab.bind("x", x);
125
2
  symtab.pushScope();
126
127
2
  ASSERT_TRUE(symtab.isBound("x"));
128
2
  ASSERT_EQ(symtab.lookup("x"), x);
129
130
4
  api::Term y = d_solver.mkConst(booleanType);
131
2
  symtab.bind("x", y);
132
133
2
  ASSERT_TRUE(symtab.isBound("x"));
134
2
  ASSERT_EQ(symtab.lookup("x"), y);
135
136
2
  symtab.popScope();
137
2
  ASSERT_TRUE(symtab.isBound("x"));
138
2
  ASSERT_EQ(symtab.lookup("x"), x);
139
}
140
141
18
TEST_F(TestNodeBlackSymbolTable, bad_pop)
142
{
143
4
  SymbolTable symtab;
144
4
  ASSERT_THROW(symtab.popScope(), ScopeException);
145
}
146
147
}  // namespace test
148
30
}  // namespace cvc5