souffle  2.0.2-371-g6315b36
Functions
souffle::ast::test Namespace Reference

Functions

bool isNotSubtypeOf (const analysis::Type &a, const analysis::Type &b)
 
Own< TranslationUnitmakeATU (std::string program=".decl A,B,C(x:number)")
 
Own< ClausemakeClause (std::string name, Own< Argument > headArgument)
 
Own< ClausemakeClauseA (Own< Argument > headArgument)
 
Own< TranslationUnitmakePrintedATU (Own< TranslationUnit > &tu)
 
 TEST (AstPrint, AggregatorCount)
 
 TEST (AstPrint, AggregatorMax)
 
 TEST (AstPrint, AggregatorMin)
 
 TEST (AstPrint, AggregatorSum)
 
 TEST (AstPrint, Counter)
 
 TEST (AstPrint, NilConstant)
 
 TEST (AstPrint, NumberConstant)
 
 TEST (AstPrint, StringConstant)
 
 TEST (AstPrint, UnnamedVariable)
 
 TEST (AstPrint, Variable)
 
 TEST (AstUtils, Grounded)
 
 TEST (AstUtils, GroundedRecords)
 
 TEST (AstUtils, ReorderClauseAtoms)
 
 TEST (Constraints, Basic)
 
 TEST (Program, AppendRelation)
 
 TEST (Program, Parse)
 
 TEST (Program, RemoveClause)
 test removeClause, addRelation and removeRelation More...
 
 TEST (Program, RemoveRelation)
 
 TEST (RuleBody, Basic)
 
 TEST (RuleBody, ClauseBodyExtraction)
 
 TEST (RuleBody, Negation)
 
 TEST (TypeSystem, AlgebraicDataType)
 
 TEST (TypeSystem, Basic)
 
 TEST (TypeSystem, complexSubsetTypes)
 
 TEST (TypeSystem, EquivTypes)
 
 TEST (TypeSystem, GreatestCommonSubtype)
 
 TEST (TypeSystem, isNumberType)
 
 TEST (TypeSystem, isSubtypeOf_Basic)
 
 TEST (TypeSystem, isSubtypeOf_Records)
 
 TEST (TypeSystem, RecordSubsets)
 
 TESTASTCLONEANDEQUAL (ChainedTypes, R"( .type D <: symbol .type C = D .type B = C .type A = B .decl R1(x:A,y:B) .decl R2(x:C,y:D) .decl R4(x:A) output R4(x) :- R2(x,x),R1(x,x). )")
 
 TESTASTCLONEANDEQUAL (ComplexTypes, R"( .type A <: symbol .type B <: number .type U = B .decl a ( x : A ) .decl b ( x : B ) .decl u ( x : U ) a(X) :- X < 10. b(X) :- X < 10. u(X) :- X < 10. )")
 
 TESTASTCLONEANDEQUAL (NestedAggregates, R"( .type D <: symbol .decl r(x:D) r(x) :- r(y), x=cat(cat(x,x),x). )")
 
 TESTASTCLONEANDEQUAL (Program, R"( .decl r(a:number,b:number,c:number,d:number) .decl s(x:symbol) .decl a(x:number) s("xxx"). r(X,Y,Z,W) :- a(X), 10 = Y, Y = Z, 8 + W = 12 + 14. r(z + 2, x, y, a) :- s(b), b = to_string(a), z = x, a = y, x = 2, a = 2 + x. )")
 
 TESTASTCLONEANDEQUAL (Record, R"( .type N <: symbol .type R = [ a : N, B : N ] .decl r ( r : R ) .decl s ( r : N ) s(x) :- r([x,y]). )")
 
 TESTASTCLONEANDEQUAL (RelationCopies, R"( .type D = number .decl a(a:D,b:D) .decl b(a:D,b:D) .decl c(a:D,b:D) .decl d(a:D,b:D) a(1,2). b(x,y) :- a(x,y). c(x,y) :- b(x,y). d(x,y) :- b(x,y), c(y,x). )")
 
 TESTASTCLONEANDEQUAL (SimpleTypes, R"( .type A <: symbol .type B <: symbol .type U = A | B .decl a ( x : A ) .decl b ( x : B ) .decl u ( x : U ) a(X) :- u(X). b(X) :- u(X). u(X) :- u(X). a(X) :- b(X). a(X) :- b(Y). )")
 

Function Documentation

◆ isNotSubtypeOf()

bool souffle::ast::test::isNotSubtypeOf ( const analysis::Type a,
const analysis::Type b 
)

Definition at line 90 of file type_system_test.cpp.

◆ makeATU()

Own< TranslationUnit > souffle::ast::test::makeATU ( std::string  program = ".decl A,B,C(x:number)")
inline

Definition at line 52 of file ast_print_test.cpp.

52  {
53  std::stringstream ss;
54  ss << tu->getProgram();
55  return makeATU(ss.str());
56 }

References souffle::profile::ss.

◆ makeClause()

Own<Clause> souffle::ast::test::makeClause ( std::string  name,
Own< Argument headArgument 
)
inline

Definition at line 56 of file ast_program_test.cpp.

58  {
59  ErrorReport e;
60  DebugReport d;
61  // check the empty program
62  Own<TranslationUnit> empty = ParserDriver::parseTranslationUnit("", e, d);

◆ makeClauseA()

Own<Clause> souffle::ast::test::makeClauseA ( Own< Argument headArgument)
inline

Definition at line 64 of file ast_print_test.cpp.

66  {
67  auto testArgument = mk<NilConstant>();
68 
69  auto tu1 = makeATU();
70  tu1->getProgram().addClause(makeClauseA(std::move(testArgument)));

◆ makePrintedATU()

Own<TranslationUnit> souffle::ast::test::makePrintedATU ( Own< TranslationUnit > &  tu)
inline

Definition at line 58 of file ast_print_test.cpp.

58  {
59  auto headAtom = mk<Atom>("A");
60  headAtom->addArgument(std::move(headArgument));
61  auto clause = mk<Clause>();
62  clause->setHead(std::move(headAtom));

◆ TEST() [1/30]

souffle::ast::test::TEST ( AstPrint  ,
AggregatorCount   
)

Definition at line 163 of file ast_print_test.cpp.

173  {
174  auto atom = mk<Atom>("B");
175  atom->addArgument(mk<Variable>("x"));
176  auto sum = mk<Aggregator>(AggregateOp::SUM, mk<Variable>("x"));
177 

◆ TEST() [2/30]

souffle::ast::test::TEST ( AstPrint  ,
AggregatorMax   
)

Definition at line 147 of file ast_print_test.cpp.

157  {
158  auto atom = mk<Atom>("B");
159  atom->addArgument(mk<Variable>("x"));
160  auto count = mk<Aggregator>(AggregateOp::COUNT);
161 

◆ TEST() [3/30]

souffle::ast::test::TEST ( AstPrint  ,
AggregatorMin   
)

Definition at line 130 of file ast_print_test.cpp.

141  {
142  auto atom = mk<Atom>("B");
143  atom->addArgument(mk<Variable>("x"));
144  auto max = mk<Aggregator>(AggregateOp::MAX, mk<Variable>("x"));
145 

◆ TEST() [4/30]

souffle::ast::test::TEST ( AstPrint  ,
AggregatorSum   
)

Definition at line 179 of file ast_print_test.cpp.

◆ TEST() [5/30]

souffle::ast::test::TEST ( AstPrint  ,
Counter   
)

Definition at line 121 of file ast_print_test.cpp.

124  {
125  auto atom = mk<Atom>("B");
126  atom->addArgument(mk<Variable>("x"));
127  auto min = mk<Aggregator>(AggregateOp::MIN, mk<Variable>("x"));
128 

◆ TEST() [6/30]

souffle::ast::test::TEST ( AstPrint  ,
NilConstant   
)

Definition at line 72 of file ast_print_test.cpp.

75  {
76  auto testArgument = mk<NumericConstant>("2");
77 
78  EXPECT_EQ(testArgument, testArgument);
79 

◆ TEST() [7/30]

souffle::ast::test::TEST ( AstPrint  ,
NumberConstant   
)

Definition at line 81 of file ast_print_test.cpp.

86  {
87  ErrorReport e;
88  DebugReport d;
89  auto testArgument = mk<StringConstant>("test string");
90 

◆ TEST() [8/30]

souffle::ast::test::TEST ( AstPrint  ,
StringConstant   
)

Definition at line 92 of file ast_print_test.cpp.

97  {
98  auto testArgument = mk<Variable>("testVar");
99 
100  auto tu1 = makeATU();
101  tu1->getProgram().addClause(makeClauseA(std::move(testArgument)));

◆ TEST() [9/30]

souffle::ast::test::TEST ( AstPrint  ,
UnnamedVariable   
)

Definition at line 112 of file ast_print_test.cpp.

115  {
116  auto testArgument = mk<Counter>();
117 
118  auto tu1 = makeATU();
119  tu1->getProgram().addClause(makeClauseA(std::move(testArgument)));

◆ TEST() [10/30]

souffle::ast::test::TEST ( AstPrint  ,
Variable   
)

Definition at line 103 of file ast_print_test.cpp.

106  {
107  auto testArgument = mk<UnnamedVariable>();
108 
109  auto tu1 = makeATU();
110  tu1->getProgram().addClause(makeClauseA(std::move(testArgument)));

◆ TEST() [11/30]

souffle::ast::test::TEST ( AstUtils  ,
Grounded   
)

Definition at line 61 of file ast_utils_test.cpp.

80  :- \n a(X),\n X = Y,\n !b(Z).", toString(*clause));
81 
82  auto program = mk<Program>();
83  program->addClause(std::move(clause));
84  DebugReport dbgReport;
85  ErrorReport errReport;
86  TranslationUnit tu{std::move(program), errReport, dbgReport};
87 
88  // obtain groundness
89  auto isGrounded = analysis::getGroundedTerms(tu, *tu.getProgram().getClauses()[0]);
90 
91  auto args = head->getArguments();
92  // check selected sub-terms
93  EXPECT_TRUE(isGrounded[args[0]]); // X
94  EXPECT_TRUE(isGrounded[args[1]]); // Y
95  EXPECT_FALSE(isGrounded[args[2]]); // Z
96 }
97 
98 TEST(AstUtils, GroundedRecords) {
99  ErrorReport e;
100  DebugReport d;
101  Own<TranslationUnit> tu = ParserDriver::parseTranslationUnit(
102  R"(
103  .type N <: symbol
104  .type R = [ a : N, B : N ]
105 
106  .decl r ( r : R )
107  .decl s ( r : N )
108 

◆ TEST() [12/30]

souffle::ast::test::TEST ( AstUtils  ,
GroundedRecords   
)

Definition at line 110 of file ast_utils_test.cpp.

119  :- \n r([x,y]).", toString(*clause));
120 
121  // obtain groundness
122  auto isGrounded = analysis::getGroundedTerms(*tu, *clause);
123 
124  const Atom* s = clause->getHead();
125  const auto* r = dynamic_cast<const Atom*>(clause->getBodyLiterals()[0]);
126 
127  EXPECT_TRUE(s);
128  EXPECT_TRUE(r);
129 
130  // check selected sub-terms
131  EXPECT_TRUE(isGrounded[s->getArguments()[0]]);
132  EXPECT_TRUE(isGrounded[r->getArguments()[0]]);
133 }
134 
135 TEST(AstUtils, ReorderClauseAtoms) {
136  ErrorReport e;

◆ TEST() [13/30]

souffle::ast::test::TEST ( AstUtils  ,
ReorderClauseAtoms   
)

Definition at line 138 of file ast_utils_test.cpp.

141  :number)
142  a(x) :- b(x), c(x), 1 != 2, d(y), !e(z), c(z), e(x).
143  .output a()
144  )",
145  e, d);
146 
147  Program& program = tu->getProgram();
148  EXPECT_EQ(5, program.getRelations().size());
149 
150  Relation* a = getRelation(program, "a");
151  EXPECT_NE(a, nullptr);
152  const auto& clauses = getClauses(program, *a);
153  EXPECT_EQ(1, clauses.size());
154 
155  Clause* clause = clauses[0];
156  EXPECT_EQ("a(x) :- \n b(x),\n c(x),\n 1 != 2,\n d(y),\n !e(z),\n c(z),\n e(x).",
157  toString(*clause));
158 
159  // Check trivial permutation
160  Own<Clause> reorderedClause0 =
161  Own<Clause>(reorderAtoms(clause, std::vector<unsigned int>({0, 1, 2, 3, 4})));
162  EXPECT_EQ("a(x) :- \n b(x),\n c(x),\n 1 != 2,\n d(y),\n !e(z),\n c(z),\n e(x).",
163  toString(*reorderedClause0));
164 
165  // Check more complex permutation
166  Own<Clause> reorderedClause1 =
167  Own<Clause>(reorderAtoms(clause, std::vector<unsigned int>({2, 3, 4, 1, 0})));
168  EXPECT_EQ("a(x) :- \n d(y),\n c(z),\n 1 != 2,\n e(x),\n !e(z),\n c(x),\n b(x).",
169  toString(*reorderedClause1));

◆ TEST() [14/30]

souffle::ast::test::TEST ( Constraints  ,
Basic   
)

Definition at line 38 of file constraints_test.cpp.

41  {}", toString(p));
42  EXPECT_EQ("{}", toString(p.solve()));
43 
44  // add a constraint
45  p.add(sub(A, B));
46  EXPECT_EQ("{\n\tA ⊑ B\n}", toString(p));
47  EXPECT_EQ("{A->{},B->{}}", toString(p.solve()));
48 
49  // add another constraints
50  std::set<int> s = {1, 2};
51  p.add(sub(s, A));
52  EXPECT_EQ("{\n\tA ⊑ B,\n\t{1,2} ⊑ A\n}", toString(p));
53  EXPECT_EQ("{A->{1,2},B->{1,2}}", toString(p.solve()));
54 
55  // and one more
56  std::set<int> s2 = {3};
57  p.add(sub(s2, B));
58  EXPECT_EQ("{\n\tA ⊑ B,\n\t{1,2} ⊑ A,\n\t{3} ⊑ B\n}", toString(p));
59  EXPECT_EQ("{A->{1,2},B->{1,2,3}}", toString(p.solve()));
60 }
61 
62 } // end namespace test
63 } // namespace souffle::ast

◆ TEST() [15/30]

souffle::ast::test::TEST ( Program  ,
AppendRelation   
)

Definition at line 139 of file ast_program_test.cpp.

139  :- b(Y).
140 
141  )");
142 
143 TESTASTCLONEANDEQUAL(ComplexTypes,
144  R"(
145  .type A <: symbol
146  .type B <: number
147  .type U = B
148 

◆ TEST() [16/30]

souffle::ast::test::TEST ( Program  ,
Parse   
)

Definition at line 64 of file ast_program_test.cpp.

70  : symbol
71  .decl e ( a : Node , b : Node )
72  .decl r ( from : Node , to : Node )
73 
74  r(X,Y) :- e(X,Y).
75  r(X,Z) :- r(X,Y), r(Y,Z).
76  )",
77  e, d);
78 
79  auto& prog = tu->getProgram();
80  std::cout << prog << "\n";
81 
82  EXPECT_EQ(1, prog.getTypes().size());
83  EXPECT_EQ(2, prog.getRelations().size());
84 
85  EXPECT_TRUE(getRelation(prog, "e"));
86  EXPECT_TRUE(getRelation(prog, "r"));
87  EXPECT_FALSE(getRelation(prog, "n"));

◆ TEST() [17/30]

souffle::ast::test::TEST ( Program  ,
RemoveClause   
)

test removeClause, addRelation and removeRelation

Definition at line 123 of file ast_program_test.cpp.

126  : symbol
127  .type B <: symbol
128  .type U = A | B
129 
130  .decl a ( x : A )
131  .decl b ( x : B )
132  .decl u ( x : U )
133 
134  a(X) :- u(X).
135  b(X) :- u(X).
136  u(X) :- u(X).
137 

◆ TEST() [18/30]

souffle::ast::test::TEST ( Program  ,
RemoveRelation   
)

Definition at line 150 of file ast_program_test.cpp.

150  : B )
151  .decl u ( x : U )
152 
153  a(X) :- X < 10.
154  b(X) :- X < 10.
155  u(X) :- X < 10.

◆ TEST() [19/30]

souffle::ast::test::TEST ( RuleBody  ,
Basic   
)

Definition at line 46 of file ast_parser_utils_test.cpp.

48  {
49  RuleBody body = RuleBody::getTrue();
50 
51  RuleBody AB = RuleBody::getTrue();
52  AB.conjunct(RuleBody::atom(mk<Atom>("A")));
53  AB.conjunct(RuleBody::atom(mk<Atom>("B")));
54  EXPECT_EQ("A(),B()", toString(AB));
55 
56  RuleBody CD = RuleBody::getTrue();
57  CD.conjunct(RuleBody::atom(mk<Atom>("C")));
58  CD.conjunct(RuleBody::atom(mk<Atom>("D")));

◆ TEST() [20/30]

souffle::ast::test::TEST ( RuleBody  ,
ClauseBodyExtraction   
)

Definition at line 94 of file ast_parser_utils_test.cpp.

110  :- \n A(),\n B().", toString(*list[0]));
111  EXPECT_EQ(" :- \n C(),\n D().", toString(*list[1]));
112  EXPECT_EQ(" :- \n E(),\n F().", toString(*list[2]));
113 }
114 
115 } // end namespace test
116 } // namespace souffle::ast

◆ TEST() [21/30]

souffle::ast::test::TEST ( RuleBody  ,
Negation   
)

Definition at line 60 of file ast_parser_utils_test.cpp.

82  {
83  RuleBody body = RuleBody::getTrue();
84 
85  RuleBody AB = RuleBody::getTrue();
86  AB.conjunct(RuleBody::atom(mk<Atom>("A")));
87  AB.conjunct(RuleBody::atom(mk<Atom>("B")));
88  EXPECT_EQ("A(),B()", toString(AB));
89 
90  RuleBody CD = RuleBody::getTrue();
91  CD.conjunct(RuleBody::atom(mk<Atom>("C")));
92  CD.conjunct(RuleBody::atom(mk<Atom>("D")));

◆ TEST() [22/30]

souffle::ast::test::TEST ( TypeSystem  ,
AlgebraicDataType   
)

Definition at line 277 of file type_system_test.cpp.

277  {A}", toString(getGreatestCommonSubtypes(A, A)));
278 }
279 
280 } // namespace souffle::ast::test

◆ TEST() [23/30]

souffle::ast::test::TEST ( TypeSystem  ,
Basic   
)

Definition at line 37 of file type_system_test.cpp.

42  : number", toString(A));
43  EXPECT_EQ("B <: symbol", toString(B));
44 
45  EXPECT_EQ("U = A | B", toString(U));
46  EXPECT_EQ("R = (A, B)", toString(R));
47 }
48 
49 TEST(TypeSystem, isNumberType) {
50  TypeEnvironment env;
51 
52  const analysis::Type& N = env.getType("number");
53 

◆ TEST() [24/30]

souffle::ast::test::TEST ( TypeSystem  ,
complexSubsetTypes   
)

Definition at line 238 of file type_system_test.cpp.

239  {B}", toString(getGreatestCommonSubtypes(A, BfromA)));
240  EXPECT_EQ("{C}", toString(getGreatestCommonSubtypes(A, CfromA)));
241  EXPECT_EQ("{}", toString(getGreatestCommonSubtypes(A, BfromA, CfromA)));
242  EXPECT_EQ("{}", toString(getGreatestCommonSubtypes(BfromA, CfromA)));
243 
244  auto* base = &env.createType<SubsetType>("B0", BfromA);
245  for (size_t i = 1; i <= 10; ++i) {
246  base = &env.createType<SubsetType>("B" + std::to_string(i), *base);
247  EXPECT_PRED2(isSubtypeOf, *base, A);
248  }
249 }
250 
251 TEST(TypeSystem, RecordSubsets) {
252  TypeEnvironment env;
253 
254  auto& R = env.createType<RecordType>("R");
255 

◆ TEST() [25/30]

souffle::ast::test::TEST ( TypeSystem  ,
EquivTypes   
)

Definition at line 268 of file type_system_test.cpp.

271  {
272  TypeEnvironment env;
273 
274  auto& A = env.createType<AlgebraicDataType>("A");
275 

◆ TEST() [26/30]

souffle::ast::test::TEST ( TypeSystem  ,
GreatestCommonSubtype   
)

Definition at line 163 of file type_system_test.cpp.

166  {number}", toString(getGreatestCommonSubtypes(N, N)));
167 
168  EXPECT_EQ("{A}", toString(getGreatestCommonSubtypes(A, A)));
169  EXPECT_EQ("{B}", toString(getGreatestCommonSubtypes(B, B)));
170  EXPECT_EQ("{C}", toString(getGreatestCommonSubtypes(C, C)));
171 
172  EXPECT_EQ("{}", toString(getGreatestCommonSubtypes(A, B)));
173  EXPECT_EQ("{}", toString(getGreatestCommonSubtypes(A, C)));
174  EXPECT_EQ("{}", toString(getGreatestCommonSubtypes(B, C)));
175 
176  EXPECT_EQ("{}", toString(getGreatestCommonSubtypes(A, B, C)));
177 
178  EXPECT_EQ("{A}", toString(getGreatestCommonSubtypes(A, N)));
179  EXPECT_EQ("{A}", toString(getGreatestCommonSubtypes(N, A)));
180 
181  EXPECT_EQ("{B}", toString(getGreatestCommonSubtypes(B, N)));
182  EXPECT_EQ("{B}", toString(getGreatestCommonSubtypes(N, B)));
183 
184  EXPECT_EQ("{}", toString(getGreatestCommonSubtypes(C, N)));
185  EXPECT_EQ("{}", toString(getGreatestCommonSubtypes(N, C)));
186 
187  // // bring in unions
188 
189  auto& U = env.createType<UnionType>("U");
190  auto& S = env.createType<UnionType>("S");
191 
192  U.setElements(toVector(&A));
193  EXPECT_EQ("{S}", toString(getGreatestCommonSubtypes(U, S)));
194 
195  S.setElements(toVector(&A));
196  EXPECT_EQ("{U}", toString(getGreatestCommonSubtypes(U, S)));
197 
198  U.setElements(toVector(&A, &B));
199  EXPECT_EQ("{S}", toString(getGreatestCommonSubtypes(U, S)));
200  EXPECT_EQ("{S}", toString(getGreatestCommonSubtypes(U, S, N)));
201 
202  S.setElements(toVector(&A, &B));
203  EXPECT_EQ("{U}", toString(getGreatestCommonSubtypes(U, S)));
204  EXPECT_EQ("{U}", toString(getGreatestCommonSubtypes(U, S, N)));
205 
206  // bring in a union of unions
207  auto& R = env.createType<UnionType>("R");
208 
209  EXPECT_EQ("{R}", toString(getGreatestCommonSubtypes(U, R)));
210  EXPECT_EQ("{R}", toString(getGreatestCommonSubtypes(S, R)));
211 
212  EXPECT_EQ("{R}", toString(getGreatestCommonSubtypes(U, R, N)));
213  EXPECT_EQ("{R}", toString(getGreatestCommonSubtypes(S, R, N)));
214 
215  R.setElements(toVector(static_cast<const analysis::Type*>(&U))); // R = U = S
216 
217  EXPECT_EQ("{U}", toString(getGreatestCommonSubtypes(U, R)));
218  EXPECT_EQ("{S}", toString(getGreatestCommonSubtypes(S, R)));
219 
220  EXPECT_EQ("{U}", toString(getGreatestCommonSubtypes(U, R, N)));
221  EXPECT_EQ("{S}", toString(getGreatestCommonSubtypes(S, R, N)));
222 
223  R.setElements(toVector(static_cast<const analysis::Type*>(&U), static_cast<const analysis::Type*>(&S)));
224 
225  EXPECT_EQ("{U}", toString(getGreatestCommonSubtypes(U, R)));
226  EXPECT_EQ("{S}", toString(getGreatestCommonSubtypes(S, R)));
227 
228  EXPECT_EQ("{U}", toString(getGreatestCommonSubtypes(U, R, N)));
229  EXPECT_EQ("{S}", toString(getGreatestCommonSubtypes(S, R, N)));
230 }
231 
232 TEST(TypeSystem, complexSubsetTypes) {
233  TypeEnvironment env;
234 
235  auto& A = env.createType<SubsetType>("A", env.getType("number"));
236  auto& BfromA = env.createType<SubsetType>("B", A);

◆ TEST() [27/30]

souffle::ast::test::TEST ( TypeSystem  ,
isNumberType   
)

Definition at line 55 of file type_system_test.cpp.

70  {
71  const analysis::Type& U = env.createType<UnionType>("U", toVector(&A, &B));
72  EXPECT_TRUE(isOfKind(U, TypeAttribute::Signed));
73  EXPECT_FALSE(isOfKind(U, TypeAttribute::Symbol));
74  const analysis::Type& U2 = env.createType<UnionType>("U2", toVector(&A, &B, &C));
75  EXPECT_FALSE(isOfKind(U2, TypeAttribute::Signed));
76  EXPECT_FALSE(isOfKind(U2, TypeAttribute::Symbol));
77  }
78  {
79  const analysis::Type& U3 = env.createType<UnionType>("U3", toVector(&A));
80  EXPECT_TRUE(isOfKind(U3, TypeAttribute::Signed));
81  }
82 }
83 
84 bool isNotSubtypeOf(const analysis::Type& a, const analysis::Type& b) {
85  return !isSubtypeOf(a, b);
86 }
87 
88 TEST(TypeSystem, isSubtypeOf_Basic) {

◆ TEST() [28/30]

souffle::ast::test::TEST ( TypeSystem  ,
isSubtypeOf_Basic   
)

Definition at line 94 of file type_system_test.cpp.

138  {
139  TypeEnvironment env;
140 
141  const analysis::Type& A = env.createType<SubsetType>("A", env.getType("number"));
142  const analysis::Type& B = env.createType<SubsetType>("B", env.getType("number"));

◆ TEST() [29/30]

souffle::ast::test::TEST ( TypeSystem  ,
isSubtypeOf_Records   
)

Definition at line 144 of file type_system_test.cpp.

157  {
158  TypeEnvironment env;
159 
160  const analysis::Type& N = env.getType("number");
161 

◆ TEST() [30/30]

souffle::ast::test::TEST ( TypeSystem  ,
RecordSubsets   
)

Definition at line 257 of file type_system_test.cpp.

259  {A}", toString(getGreatestCommonSubtypes(A, R)));
260 }
261 
262 TEST(TypeSystem, EquivTypes) {
263  TypeEnvironment env;
264 
265  auto& A = env.createType<SubsetType>("A", env.getType("number"));
266  auto& U = env.createType<UnionType>("U", toVector(dynamic_cast<const analysis::Type*>(&A)));

◆ TESTASTCLONEANDEQUAL() [1/7]

souffle::ast::test::TESTASTCLONEANDEQUAL ( ChainedTypes  ,
R"( .type D <: symbol .type C = D .type B = C .type A = B .decl R1(x:A,y:B) .decl R2(x:C,y:D) .decl R4(x:A) output R4(x) :- R2(x,x),R1(x,x). )"   
)

◆ TESTASTCLONEANDEQUAL() [2/7]

souffle::ast::test::TESTASTCLONEANDEQUAL ( ComplexTypes  ,
R"( .type A <: symbol .type B <: number .type U = B .decl a ( x : A ) .decl b ( x : B ) .decl u ( x : U ) a(X) :- X < 10. b(X) :- X < 10. u(X) :- X < 10. )"   
)

◆ TESTASTCLONEANDEQUAL() [3/7]

souffle::ast::test::TESTASTCLONEANDEQUAL ( NestedAggregates  ,
R"( .type D <: symbol .decl r(x:D) r(x) :- r(y), x=cat(cat(x,x),x). )"   
)

◆ TESTASTCLONEANDEQUAL() [4/7]

souffle::ast::test::TESTASTCLONEANDEQUAL ( Program  ,
R"( .decl r(a:number,b:number,c:number,d:number) .decl s(x:symbol) .decl a(x:number) s("xxx"). r(X,Y,Z,W) :- a(X), 10 = Y, Y = Z, 8 + W = 12 + 14. r(z + 2, x, y, a) :- s(b), b = to_string(a), z = x, a = y, x = 2, a = 2 + x. )"   
)

◆ TESTASTCLONEANDEQUAL() [5/7]

souffle::ast::test::TESTASTCLONEANDEQUAL ( Record  ,
R"( .type N <: symbol .type R = [ a : N, B : N ] .decl r ( r : R ) .decl s ( r : N ) s(x) :- r([x,y]). )"   
)

◆ TESTASTCLONEANDEQUAL() [6/7]

souffle::ast::test::TESTASTCLONEANDEQUAL ( RelationCopies  ,
R"( .type D = number .decl a(a:D,b:D) .decl b(a:D,b:D) .decl c(a:D,b:D) .decl d(a:D,b:D) a(1,2). b(x,y) :- a(x,y). c(x,y) :- b(x,y). d(x,y) :- b(x,y), c(y,x). )"   
)

◆ TESTASTCLONEANDEQUAL() [7/7]

souffle::ast::test::TESTASTCLONEANDEQUAL ( SimpleTypes  ,
R"( .type A <: symbol .type B <: symbol .type U = A | B .decl a ( x : A ) .decl b ( x : B ) .decl u ( x : U ) a(X) :- u(X). b(X) :- u(X). u(X) :- u(X). a(X) :- b(X). a(X) :- b(Y). )"   
)
souffle::ast::analysis::isOfKind
bool isOfKind(const Type &type, TypeAttribute kind)
Check if the type is of a kind corresponding to the TypeAttribute.
Definition: TypeSystem.cpp:189
EXPECT_TRUE
#define EXPECT_TRUE(a)
Definition: test.h:189
souffle::ast::test::TEST
TEST(TypeSystem, AlgebraicDataType)
Definition: type_system_test.cpp:277
souffle::ast::test::makeATU
Own< TranslationUnit > makeATU(std::string program=".decl A,B,C(x:number)")
Definition: ast_print_test.cpp:52
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: test.h:191
S
#define S(x)
Definition: test.h:179
e
l j a showGridBackground &&c b raw series this eventEmitter e
Definition: htmlJsChartistMin.h:15
souffle::ast::test::isNotSubtypeOf
bool isNotSubtypeOf(const analysis::Type &a, const analysis::Type &b)
Definition: type_system_test.cpp:90
n
var n
Definition: htmlJsChartistMin.h:15
souffle::toString
const std::string & toString(const std::string &str)
A generic function converting strings into strings (trivial case).
Definition: StringUtil.h:234
souffle::ast::analysis::isSubtypeOf
static TypeConstraint isSubtypeOf(const TypeVar &a, const TypeVar &b)
A constraint factory ensuring that all the types associated to the variable a are subtypes of the var...
Definition: TypeConstraints.cpp:27
souffle::ast::test::makeClauseA
Own< Clause > makeClauseA(Own< Argument > headArgument)
Definition: ast_print_test.cpp:64
souffle::test::count
int count(const C &c)
Definition: table_test.cpp:40
souffle::toVector
std::vector< T > toVector()
A utility function enabling the creation of a vector with a fixed set of elements within a single exp...
Definition: ContainerUtil.h:128
b
l j a showGridBackground &&c b raw series this eventEmitter b
Definition: htmlJsChartistMin.h:15
d
else d
Definition: htmlJsChartistMin.h:15
EXPECT_FALSE
#define EXPECT_FALSE(a)
Definition: test.h:190
std::type
ElementType type
Definition: span.h:640
souffle::profile::ss
class souffle::profile::Tui ss
Definition: Tui.h:336