1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Aina Niemetz, Mudathir Mohamed |
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 sets typing rules |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "expr/dtype.h" |
17 |
|
#include "test_api.h" |
18 |
|
#include "test_node.h" |
19 |
|
|
20 |
|
namespace cvc5 { |
21 |
|
|
22 |
|
using namespace cvc5::api; |
23 |
|
|
24 |
|
namespace test { |
25 |
|
|
26 |
4 |
class TestTheoryWhiteSetsTypeRuleApi : public TestApi |
27 |
|
{ |
28 |
|
}; |
29 |
8 |
class TestTheoryWhiteSetsTypeRuleInternal : public TestNode |
30 |
|
{ |
31 |
|
}; |
32 |
|
|
33 |
12 |
TEST_F(TestTheoryWhiteSetsTypeRuleInternal, is_comparable_to) |
34 |
|
{ |
35 |
4 |
TypeNode setRealType = d_nodeManager->mkSetType(d_nodeManager->realType()); |
36 |
4 |
TypeNode setIntType = d_nodeManager->mkSetType(d_nodeManager->integerType()); |
37 |
2 |
ASSERT_FALSE(setIntType.isComparableTo(setRealType)); |
38 |
2 |
ASSERT_FALSE(setIntType.isSubtypeOf(setRealType)); |
39 |
2 |
ASSERT_FALSE(setRealType.isComparableTo(setIntType)); |
40 |
2 |
ASSERT_FALSE(setRealType.isComparableTo(setIntType)); |
41 |
|
} |
42 |
|
|
43 |
12 |
TEST_F(TestTheoryWhiteSetsTypeRuleApi, singleton_term) |
44 |
|
{ |
45 |
4 |
Sort realSort = d_solver.getRealSort(); |
46 |
4 |
Sort intSort = d_solver.getIntegerSort(); |
47 |
4 |
Term emptyReal = d_solver.mkEmptySet(d_solver.mkSetSort(realSort)); |
48 |
4 |
Term integerOne = d_solver.mkInteger(1); |
49 |
4 |
Term realOne = d_solver.mkReal(1); |
50 |
4 |
Term singletonInt = d_solver.mkTerm(api::SINGLETON, integerOne); |
51 |
4 |
Term singletonReal = d_solver.mkTerm(api::SINGLETON, realOne); |
52 |
|
// (union |
53 |
|
// (singleton (singleton_op Int) 1) |
54 |
|
// (as emptyset (Set Real))) |
55 |
4 |
ASSERT_THROW(d_solver.mkTerm(UNION, singletonInt, emptyReal), |
56 |
2 |
CVC5ApiException); |
57 |
|
// (union |
58 |
|
// (singleton (singleton_op Real) 1) |
59 |
|
// (as emptyset (Set Real))) |
60 |
2 |
ASSERT_NO_THROW(d_solver.mkTerm(UNION, singletonReal, emptyReal)); |
61 |
|
} |
62 |
|
|
63 |
12 |
TEST_F(TestTheoryWhiteSetsTypeRuleInternal, singleton_node) |
64 |
|
{ |
65 |
|
Node singletonInt = |
66 |
4 |
d_nodeManager->mkConst(SingletonOp(d_nodeManager->integerType())); |
67 |
|
Node singletonReal = |
68 |
4 |
d_nodeManager->mkConst(SingletonOp(d_nodeManager->realType())); |
69 |
4 |
Node intConstant = d_nodeManager->mkConst(Rational(1)); |
70 |
4 |
Node realConstant = d_nodeManager->mkConst(Rational(1, 5)); |
71 |
|
// (singleton (singleton_op Real) 1) |
72 |
2 |
ASSERT_NO_THROW( |
73 |
|
d_nodeManager->mkSingleton(d_nodeManager->realType(), intConstant)); |
74 |
|
// (singleton (singleton_op Int) (/ 1 5)) |
75 |
2 |
ASSERT_DEATH( |
76 |
|
d_nodeManager->mkSingleton(d_nodeManager->integerType(), realConstant), |
77 |
|
"Invalid operands for mkSingleton"); |
78 |
|
|
79 |
4 |
Node n = d_nodeManager->mkSingleton(d_nodeManager->realType(), intConstant); |
80 |
|
// the type of (singleton (singleton_op Real) 1) is (Set Real) |
81 |
2 |
ASSERT_TRUE(n.getType() |
82 |
2 |
== d_nodeManager->mkSetType(d_nodeManager->realType())); |
83 |
|
// (singleton (singleton_op Real) 1) is a constant in normal form |
84 |
2 |
ASSERT_TRUE(n.isConst()); |
85 |
|
} |
86 |
|
} // namespace test |
87 |
27562 |
} // namespace cvc5 |