souffle  2.0.2-371-g6315b36
Functions
util_test.cpp File Reference
#include "tests/test.h"
#include "souffle/utility/CacheUtil.h"
#include "souffle/utility/ContainerUtil.h"
#include "souffle/utility/FunctionalUtil.h"
#include "souffle/utility/StreamUtil.h"
#include "souffle/utility/StringUtil.h"
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <typeinfo>
#include <vector>
Include dependency graph for util_test.cpp:

Go to the source code of this file.

Functions

 TEST (Util, LambdaTraits)
 
 TEST (Util, LRUCache)
 
 TEST (Util, LRUCache_S0)
 
 TEST (Util, LRUCache_S1)
 
 TEST (Util, LRUCache_S2)
 
 TEST (Util, printMap)
 
 TEST (Util, printSet)
 
 TEST (Util, printVector)
 
 TEST (Util, Range)
 
 TEST (Util, toString)
 
 TEST (Util, toVector)
 

Function Documentation

◆ TEST() [1/11]

TEST ( Util  ,
LambdaTraits   
)

Definition at line 73 of file util_test.cpp.

73  {
74  auto lambda = [](int) -> bool { return true; };
75 
76  EXPECT_EQ(typeid(bool).name(), typeid(lambda_traits<decltype(lambda)>::result_type).name());
77  EXPECT_EQ(typeid(int).name(), typeid(lambda_traits<decltype(lambda)>::arg0_type).name());
78 }

References EXPECT_EQ.

◆ TEST() [2/11]

TEST ( Util  ,
LRUCache   
)

Definition at line 80 of file util_test.cpp.

80  {
81  using cache = LRUCache<int, 4>;
82  cache c;
83 
84  // check initial state
85  EXPECT_EQ("0,0,0,0", toString(c));
86 
87  // fill cache with new entries
88  c.access(4);
89  EXPECT_EQ("4,0,0,0", toString(c));
90 
91  c.access(3);
92  EXPECT_EQ("3,4,0,0", toString(c));
93 
94  c.access(7);
95  EXPECT_EQ("7,3,4,0", toString(c));
96 
97  c.access(2);
98  EXPECT_EQ("2,7,3,4", toString(c));
99 
100  c.access(5);
101  EXPECT_EQ("5,2,7,3", toString(c));
102 
103  // access elements present
104  c.access(5);
105  EXPECT_EQ("5,2,7,3", toString(c));
106 
107  c.access(2);
108  EXPECT_EQ("2,5,7,3", toString(c));
109 
110  c.access(7);
111  EXPECT_EQ("7,2,5,3", toString(c));
112 
113  c.access(3);
114  EXPECT_EQ("3,7,2,5", toString(c));
115 
116  c.access(2);
117  EXPECT_EQ("2,3,7,5", toString(c));
118 
119  // test clearing
120  c.clear();
121  EXPECT_EQ("0,0,0,0", toString(c));
122 
123  c.clear(5);
124  EXPECT_EQ("5,5,5,5", toString(c));
125 }

References EXPECT_EQ, and souffle::toString().

Here is the call graph for this function:

◆ TEST() [3/11]

TEST ( Util  ,
LRUCache_S0   
)

Definition at line 192 of file util_test.cpp.

192  {
193  using cache = LRUCache<int, 0>;
194  cache c;
195 
196  // check initial state
197  EXPECT_EQ("-empty-", toString(c));
198 
199  // fill cache with new entries
200  c.access(4);
201  EXPECT_EQ("-empty-", toString(c));
202 
203  c.access(3);
204  EXPECT_EQ("-empty-", toString(c));
205 
206  // access elements present
207  c.access(3);
208  EXPECT_EQ("-empty-", toString(c));
209 
210  // and again not present
211  c.access(2);
212  EXPECT_EQ("-empty-", toString(c));
213 
214  // test clearing
215  c.clear();
216  EXPECT_EQ("-empty-", toString(c));
217 
218  c.clear(5);
219  EXPECT_EQ("-empty-", toString(c));
220 }

References EXPECT_EQ, and souffle::toString().

Here is the call graph for this function:

◆ TEST() [4/11]

TEST ( Util  ,
LRUCache_S1   
)

Definition at line 162 of file util_test.cpp.

162  {
163  using cache = LRUCache<int, 1>;
164  cache c;
165 
166  // check initial state
167  EXPECT_EQ("0", toString(c));
168 
169  // fill cache with new entries
170  c.access(4);
171  EXPECT_EQ("4", toString(c));
172 
173  c.access(3);
174  EXPECT_EQ("3", toString(c));
175 
176  // access elements present
177  c.access(3);
178  EXPECT_EQ("3", toString(c));
179 
180  // and again not present
181  c.access(2);
182  EXPECT_EQ("2", toString(c));
183 
184  // test clearing
185  c.clear();
186  EXPECT_EQ("0", toString(c));
187 
188  c.clear(5);
189  EXPECT_EQ("5", toString(c));
190 }

References EXPECT_EQ, and souffle::toString().

Here is the call graph for this function:

◆ TEST() [5/11]

TEST ( Util  ,
LRUCache_S2   
)

Definition at line 127 of file util_test.cpp.

127  {
128  using cache = LRUCache<int, 2>;
129  cache c;
130 
131  // check initial state
132  EXPECT_EQ("0,0", toString(c));
133 
134  // fill cache with new entries
135  c.access(4);
136  EXPECT_EQ("4,0", toString(c));
137 
138  c.access(3);
139  EXPECT_EQ("3,4", toString(c));
140 
141  c.access(7);
142  EXPECT_EQ("7,3", toString(c));
143 
144  // access elements present
145  c.access(7);
146  EXPECT_EQ("7,3", toString(c));
147 
148  c.access(3);
149  EXPECT_EQ("3,7", toString(c));
150 
151  c.access(7);
152  EXPECT_EQ("7,3", toString(c));
153 
154  // test clearing
155  c.clear();
156  EXPECT_EQ("0,0", toString(c));
157 
158  c.clear(5);
159  EXPECT_EQ("5,5", toString(c));
160 }

References EXPECT_EQ, and souffle::toString().

Here is the call graph for this function:

◆ TEST() [6/11]

TEST ( Util  ,
printMap   
)

Definition at line 63 of file util_test.cpp.

63  {
64  std::map<int, std::string> m;
65 
66  EXPECT_EQ("{}", toString(m));
67  m[12] = "Hello";
68  EXPECT_EQ("{12->Hello}", toString(m));
69  m[14] = "World";
70  EXPECT_EQ("{12->Hello,14->World}", toString(m));
71 }

References EXPECT_EQ, m, and souffle::toString().

Here is the call graph for this function:

◆ TEST() [7/11]

TEST ( Util  ,
printSet   
)

Definition at line 53 of file util_test.cpp.

53  {
54  std::set<int> v;
55 
56  EXPECT_EQ("{}", toString(v));
57  v.insert(12);
58  EXPECT_EQ("{12}", toString(v));
59  v.insert(14);
60  EXPECT_EQ("{12,14}", toString(v));
61 }

References EXPECT_EQ, and souffle::toString().

Here is the call graph for this function:

◆ TEST() [8/11]

TEST ( Util  ,
printVector   
)

Definition at line 43 of file util_test.cpp.

43  {
44  std::vector<int> v;
45 
46  EXPECT_EQ("[]", toString(v));
47  v.push_back(12);
48  EXPECT_EQ("[12]", toString(v));
49  v.push_back(14);
50  EXPECT_EQ("[12,14]", toString(v));
51 }

References EXPECT_EQ, and souffle::toString().

Here is the call graph for this function:

◆ TEST() [9/11]

TEST ( Util  ,
Range   
)

Definition at line 222 of file util_test.cpp.

222  {
223  using container = std::vector<int>;
224  using iter = container::const_iterator;
225 
226  std::vector<int> list(9);
227 
228  for (int i = 0; i < 9; i++) {
229  list[i] = i;
230  }
231 
232  range<iter> range(list.begin(), list.end());
233 
234  {
235  int last = -1;
236  for (const auto& p : range.partition(4)) {
237  auto size = p.end() - p.begin();
238  EXPECT_TRUE(2 <= size && size <= 3);
239  for (const auto& cur : p) {
240  EXPECT_EQ(last + 1, cur);
241  last = cur;
242  }
243  }
244  EXPECT_EQ(last, 8);
245  }
246 
247  {
248  int last = -1;
249  for (const auto& p : range.partition(7)) {
250  auto size = p.end() - p.begin();
251  EXPECT_TRUE(1 <= size && size <= 2);
252  for (const auto& cur : p) {
253  EXPECT_EQ(last + 1, cur);
254  last = cur;
255  }
256  }
257  EXPECT_EQ(last, 8);
258  }
259 }

References EXPECT_EQ, EXPECT_TRUE, i, p, souffle::range< Iter >::partition(), and TCB_SPAN_NAMESPACE_NAME::detail::size().

Here is the call graph for this function:

◆ TEST() [10/11]

TEST ( Util  ,
toString   
)

Definition at line 33 of file util_test.cpp.

33  {
34  EXPECT_EQ("12", toString(12));
35  EXPECT_EQ("Hello", toString("Hello"));
36 }

References EXPECT_EQ, and souffle::toString().

Here is the call graph for this function:

◆ TEST() [11/11]

TEST ( Util  ,
toVector   
)

Definition at line 38 of file util_test.cpp.

38  {
39  EXPECT_EQ("[1,2,3]", toString(toVector(1, 2, 3)));
40  EXPECT_EQ("[]", toString(toVector<int>()));
41 }

References EXPECT_EQ, souffle::toString(), and souffle::toVector().

Here is the call graph for this function:
TCB_SPAN_NAMESPACE_NAME::detail::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: span.h:198
EXPECT_TRUE
#define EXPECT_TRUE(a)
Definition: test.h:189
souffle::range
A utility class enabling representation of ranges by pairing two iterator instances marking lower and...
Definition: ContainerUtil.h:313
m
var m
Definition: htmlJsChartistMin.h:15
souffle::lambda_traits
A type trait enabling the deduction of type properties of lambdas.
Definition: FunctionalUtil.h:94
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: test.h:191
souffle::LRUCache
An Least-Recently-Used cache for arbitrary element types.
Definition: CacheUtil.h:39
souffle::toString
const std::string & toString(const std::string &str)
A generic function converting strings into strings (trivial case).
Definition: StringUtil.h:234
i
size_t i
Definition: json11.h:663
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
souffle::range::partition
std::vector< range > partition(int np=100)
Definition: ContainerUtil.h:347
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