GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/theory/theory_sets_type_rules_white.cpp Lines: 32 32 100.0 %
Date: 2021-08-01 Branches: 104 315 33.0 %

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