souffle  2.0.2-371-g6315b36
graph_utils_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 graph_utils_test.cpp
12  *
13  * Tests souffle's type system operations.
14  *
15  ***********************************************************************/
16 
17 #include "tests/test.h"
18 
19 #include "GraphUtils.h"
21 #include <functional>
22 #include <map>
23 #include <set>
24 #include <string>
25 
26 namespace souffle {
27 
28 namespace test {
29 
30 TEST(Graph, Basic) {
31  Graph<int> g;
32 
33  EXPECT_FALSE(g.contains(1));
34  EXPECT_FALSE(g.contains(2));
35  EXPECT_FALSE(g.contains(3));
36 
37  EXPECT_FALSE(g.contains(1, 2));
38  EXPECT_FALSE(g.contains(1, 3));
39  EXPECT_FALSE(g.contains(2, 3));
40 
41  EXPECT_FALSE(g.reaches(1, 1));
42  EXPECT_FALSE(g.reaches(1, 2));
43  EXPECT_FALSE(g.reaches(1, 3));
44  EXPECT_FALSE(g.reaches(2, 1));
45  EXPECT_FALSE(g.reaches(2, 2));
46  EXPECT_FALSE(g.reaches(2, 3));
47  EXPECT_FALSE(g.reaches(3, 1));
48  EXPECT_FALSE(g.reaches(3, 2));
49  EXPECT_FALSE(g.reaches(3, 3));
50 
51  g.insert(1, 2);
52 
53  EXPECT_TRUE(g.contains(1));
54  EXPECT_TRUE(g.contains(2));
55  EXPECT_FALSE(g.contains(3));
56 
57  EXPECT_TRUE(g.contains(1, 2));
58  EXPECT_FALSE(g.contains(1, 3));
59  EXPECT_FALSE(g.contains(2, 3));
60 
61  EXPECT_FALSE(g.reaches(1, 1));
62  EXPECT_TRUE(g.reaches(1, 2));
63  EXPECT_FALSE(g.reaches(1, 3));
64  EXPECT_FALSE(g.reaches(2, 1));
65  EXPECT_FALSE(g.reaches(2, 2));
66  EXPECT_FALSE(g.reaches(2, 3));
67  EXPECT_FALSE(g.reaches(3, 1));
68  EXPECT_FALSE(g.reaches(3, 2));
69  EXPECT_FALSE(g.reaches(3, 3));
70 
71  g.insert(2, 3);
72 
73  EXPECT_TRUE(g.contains(1));
74  EXPECT_TRUE(g.contains(2));
75  EXPECT_TRUE(g.contains(3));
76 
77  EXPECT_TRUE(g.contains(1, 2));
78  EXPECT_FALSE(g.contains(1, 3));
79  EXPECT_TRUE(g.contains(2, 3));
80 
81  EXPECT_FALSE(g.reaches(1, 1));
82  EXPECT_TRUE(g.reaches(1, 2));
83  EXPECT_TRUE(g.reaches(1, 3));
84  EXPECT_FALSE(g.reaches(2, 1));
85  EXPECT_FALSE(g.reaches(2, 2));
86  EXPECT_TRUE(g.reaches(2, 3));
87  EXPECT_FALSE(g.reaches(3, 1));
88  EXPECT_FALSE(g.reaches(3, 2));
89  EXPECT_FALSE(g.reaches(3, 3));
90 
91  g.insert(3, 1);
92 
93  EXPECT_TRUE(g.contains(1));
94  EXPECT_TRUE(g.contains(2));
95  EXPECT_TRUE(g.contains(3));
96 
97  EXPECT_TRUE(g.contains(1, 2));
98  EXPECT_FALSE(g.contains(1, 3));
99  EXPECT_TRUE(g.contains(2, 3));
100 
101  EXPECT_TRUE(g.reaches(1, 1));
102  EXPECT_TRUE(g.reaches(1, 2));
103  EXPECT_TRUE(g.reaches(1, 3));
104  EXPECT_TRUE(g.reaches(2, 1));
105  EXPECT_TRUE(g.reaches(2, 2));
106  EXPECT_TRUE(g.reaches(2, 3));
107  EXPECT_TRUE(g.reaches(3, 1));
108  EXPECT_TRUE(g.reaches(3, 2));
109  EXPECT_TRUE(g.reaches(3, 3));
110 
111  EXPECT_EQ("{1->2,2->3,3->1}", toString(g));
112 }
113 
114 } // end namespace test
115 } // end namespace souffle
EXPECT_TRUE
#define EXPECT_TRUE(a)
Definition: test.h:189
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: test.h:191
souffle::toString
const std::string & toString(const std::string &str)
A generic function converting strings into strings (trivial case).
Definition: StringUtil.h:234
StringUtil.h
GraphUtils.h
test.h
souffle
Definition: AggregateOp.h:25
EXPECT_FALSE
#define EXPECT_FALSE(a)
Definition: test.h:190
souffle::test::TEST
TEST(EqRelTest, Scoping)
Definition: binary_relation_test.cpp:51