souffle  2.0.2-371-g6315b36
constraints_test.cpp
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file constraints_test.cpp
12  *
13  * Tests souffle's type system operations.
14  *
15  ***********************************************************************/
16 
17 #include "tests/test.h"
18 
21 #include <algorithm>
22 #include <iosfwd>
23 #include <set>
24 #include <string>
25 
26 namespace souffle::ast {
27 
28 using namespace analysis;
29 
30 namespace test {
31 
32 TEST(Constraints, Basic) {
33  using Vars = Variable<std::string, set_property_space<int>>;
34 
35  Vars A("A");
36  Vars B("B");
37 
39 
40  // check empty problem
41  EXPECT_EQ("{}", 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
souffle::ast::analysis::sub
std::shared_ptr< Constraint< Var > > sub(const Var &a, const Var &b, const std::string &symbol="⊑")
A generic factory for constraints of the form.
Definition: ConstraintSystem.h:228
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: test.h:191
souffle::ast::analysis::Problem
A problem is a list of constraints for which a solution is desired.
Definition: ConstraintSystem.h:50
ConstraintSystem.h
souffle::toString
const std::string & toString(const std::string &str)
A generic function converting strings into strings (trivial case).
Definition: StringUtil.h:234
souffle::TEST
TEST(SparseArray, Basic)
Definition: brie_test.cpp:45
StringUtil.h
test.h
souffle::ast
Definition: Aggregator.h:35
p
a horizontalBars(j=m=void 0===a.axisX.type?new c.AutoScaleAxis(c.Axis.units.x, b.normalized.series, o, c.extend({}, a.axisX,{highLow:d, referenceValue:0})):a.axisX.type.call(c, c.Axis.units.x, b.normalized.series, o, c.extend({}, a.axisX,{highLow:d, referenceValue:0})), l=n=void 0===a.axisY.type?new c.StepAxis(c.Axis.units.y, b.normalized.series, o,{ticks:k}):a.axisY.type.call(c, c.Axis.units.y, b.normalized.series, o, a.axisY)) var p
Definition: htmlJsChartistMin.h:15