summaryrefslogtreecommitdiff
path: root/test/unit/api/grammar_black.h
blob: eee067ef2adb66269371937d3dbf59c20de78f80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*********************                                                        */
/*! \file grammar_black.h
 ** \verbatim
 ** Top contributors (to current version):
 **   Abdalrhman Mohamed, Aina Niemetz
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
 ** 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.\endverbatim
 **
 ** \brief Black box testing of the guards of the C++ API functions.
 **
 ** Black box testing of the guards of the C++ API functions.
 **/

#include <cxxtest/TestSuite.h>

#include "api/cvc4cpp.h"

using namespace CVC4::api;

class GrammarBlack : public CxxTest::TestSuite
{
 public:
  void setUp() override;
  void tearDown() override;

  void testAddRule();
  void testAddRules();
  void testAddAnyConstant();
  void testAddAnyVariable();

 private:
  std::unique_ptr<Solver> d_solver;
};

void GrammarBlack::setUp() { d_solver.reset(new Solver()); }

void GrammarBlack::tearDown() { d_solver.reset(nullptr); }

void GrammarBlack::testAddRule()
{
  Sort boolean = d_solver->getBooleanSort();
  Sort integer = d_solver->getIntegerSort();

  Term nullTerm;
  Term start = d_solver->mkVar(boolean);
  Term nts = d_solver->mkVar(boolean);

  Grammar g = d_solver->mkSygusGrammar({}, {start});

  TS_ASSERT_THROWS_NOTHING(g.addRule(start, d_solver->mkBoolean(false)));

  TS_ASSERT_THROWS(g.addRule(nullTerm, d_solver->mkBoolean(false)),
                   CVC4ApiException&);
  TS_ASSERT_THROWS(g.addRule(start, nullTerm), CVC4ApiException&);
  TS_ASSERT_THROWS(g.addRule(nts, d_solver->mkBoolean(false)),
                   CVC4ApiException&);
  TS_ASSERT_THROWS(g.addRule(start, d_solver->mkReal(0)), CVC4ApiException&);

  d_solver->synthFun("f", {}, boolean, g);

  TS_ASSERT_THROWS(g.addRule(start, d_solver->mkBoolean(false)),
                   CVC4ApiException&);
}

void GrammarBlack::testAddRules()
{
  Sort boolean = d_solver->getBooleanSort();
  Sort integer = d_solver->getIntegerSort();

  Term nullTerm;
  Term start = d_solver->mkVar(boolean);
  Term nts = d_solver->mkVar(boolean);

  Grammar g = d_solver->mkSygusGrammar({}, {start});

  TS_ASSERT_THROWS_NOTHING(g.addRules(start, {d_solver->mkBoolean(false)}));

  TS_ASSERT_THROWS(g.addRules(nullTerm, {d_solver->mkBoolean(false)}),
                   CVC4ApiException&);
  TS_ASSERT_THROWS(g.addRules(start, {nullTerm}), CVC4ApiException&);
  TS_ASSERT_THROWS(g.addRules(nts, {d_solver->mkBoolean(false)}),
                   CVC4ApiException&);
  TS_ASSERT_THROWS(g.addRules(start, {d_solver->mkReal(0)}), CVC4ApiException&);

  d_solver->synthFun("f", {}, boolean, g);

  TS_ASSERT_THROWS(g.addRules(start, {d_solver->mkBoolean(false)}),
                   CVC4ApiException&);
}

void GrammarBlack::testAddAnyConstant()
{
  Sort boolean = d_solver->getBooleanSort();

  Term nullTerm;
  Term start = d_solver->mkVar(boolean);
  Term nts = d_solver->mkVar(boolean);

  Grammar g = d_solver->mkSygusGrammar({}, {start});

  TS_ASSERT_THROWS_NOTHING(g.addAnyConstant(start));
  TS_ASSERT_THROWS_NOTHING(g.addAnyConstant(start));

  TS_ASSERT_THROWS(g.addAnyConstant(nullTerm), CVC4ApiException&);
  TS_ASSERT_THROWS(g.addAnyConstant(nts), CVC4ApiException&);

  d_solver->synthFun("f", {}, boolean, g);

  TS_ASSERT_THROWS(g.addAnyConstant(start), CVC4ApiException&);
}

void GrammarBlack::testAddAnyVariable()
{
  Sort boolean = d_solver->getBooleanSort();

  Term nullTerm;
  Term x = d_solver->mkVar(boolean);
  Term start = d_solver->mkVar(boolean);
  Term nts = d_solver->mkVar(boolean);

  Grammar g1 = d_solver->mkSygusGrammar({x}, {start});
  Grammar g2 = d_solver->mkSygusGrammar({}, {start});

  TS_ASSERT_THROWS_NOTHING(g1.addAnyVariable(start));
  TS_ASSERT_THROWS_NOTHING(g1.addAnyVariable(start));
  TS_ASSERT_THROWS_NOTHING(g2.addAnyVariable(start));

  TS_ASSERT_THROWS(g1.addAnyVariable(nullTerm), CVC4ApiException&);
  TS_ASSERT_THROWS(g1.addAnyVariable(nts), CVC4ApiException&);

  d_solver->synthFun("f", {}, boolean, g1);

  TS_ASSERT_THROWS(g1.addAnyVariable(start), CVC4ApiException&);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback