souffle  2.0.2-371-g6315b36
table_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 table_test.cpp
12  *
13  * Test cases for the Table data structure.
14  *
15  ***********************************************************************/
16 
17 #include "tests/test.h"
18 
20 #include <cstddef>
21 #include <string>
22 
23 namespace souffle {
24 
25 namespace test {
26 
27 template <typename C>
28 int count(const C& c) {
29  int res = 0;
30  for (auto it = c.begin(); it != c.end(); ++it) {
31  res++;
32  }
33  return res;
34 }
35 
36 TEST(Table, Basic) {
37  Table<int> table;
38  EXPECT_TRUE(table.empty());
39  EXPECT_EQ(0, table.size());
40  EXPECT_EQ(0, count(table));
41 
42  table.insert(1);
43 
44  EXPECT_FALSE(table.empty());
45  EXPECT_EQ(1, table.size());
46  EXPECT_EQ(1, count(table));
47 }
48 
49 TEST(Table, Stress) {
50  for (int i = 0; i < 10000; ++i) {
51  Table<int> table;
52 
53  for (int j = 0; j < i; ++j) {
54  table.insert(j);
55  }
56 
57  EXPECT_EQ((size_t)i, table.size());
58 
59  int last = -1;
60  for (const auto& cur : table) {
61  EXPECT_EQ(last + 1, cur);
62  last = cur;
63  }
64  EXPECT_EQ(last + 1, i);
65  }
66 }
67 } // namespace test
68 } // end namespace souffle
souffle::Table::size
std::size_t size() const
Definition: Table.h:115
EXPECT_TRUE
#define EXPECT_TRUE(a)
Definition: test.h:189
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: test.h:191
j
var j
Definition: htmlJsChartistMin.h:15
Table.h
i
size_t i
Definition: json11.h:663
souffle::test::count
int count(const C &c)
Definition: table_test.cpp:40
test.h
souffle::Table
Definition: Table.h:33
souffle::Table::insert
const T & insert(const T &element)
Definition: Table.h:119
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