souffle  2.0.2-371-g6315b36
compiled_tuple_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 compiled_tuple_test.cpp
12  *
13  * Test cases for the RAM tuple data structure.
14  *
15  ***********************************************************************/
16 
17 #include "tests/test.h"
18 
19 #include "souffle/RamTypes.h"
20 #include <cstdint>
21 #include <iostream>
22 #include <string>
23 
24 namespace souffle {
25 
26 namespace ram {
27 
28 TEST(Tuple, Basic) {
29  Tuple<int, 3> t = {{1, 3, 2}};
30 
31  EXPECT_EQ(3 * sizeof(int), sizeof(t));
32 
33  std::cout << t << "\n";
34 
35  Tuple<int, 2> t2 = {{1, 5}};
36  EXPECT_EQ(2 * sizeof(int), sizeof(t2));
37  std::cout << t2 << "\n";
38 }
39 
40 TEST(Tuple, Assign) {
41  Tuple<int, 3> t1 = {{1, 2, 3}};
42  Tuple<int, 3> t2 = {{3, 2, 1}};
43 
44  Tuple<int, 3> t3 = t1;
45 
46  EXPECT_NE(t1, t2);
47  EXPECT_EQ(t1, t3);
48  EXPECT_NE(t2, t3);
49 
50  t3 = t2;
51 
52  EXPECT_NE(t1, t2);
53  EXPECT_NE(t1, t3);
54  EXPECT_EQ(t2, t3);
55 }
56 
57 TEST(Tuple, Compare) {
58  Tuple<int, 2> t1 = {{1, 2}};
59  Tuple<int, 2> t2 = {{2, 1}};
60 
61  EXPECT_LT(t1, t2);
62 }
63 
64 TEST(Tuple, CompareSpeed) {
65  // was used to evaluate various implementations of the == operator
66 
67  Tuple<int, 2> t1 = {{1, 2}};
68  Tuple<int, 2> t2 = {{2, 1}};
69 
70  uint32_t res = 0;
71  while (true) {
72  res += !(t1 == t2);
73  if (res & 0x10000000llu) break;
74  }
75  EXPECT_EQ(268435456llu, res);
76 }
77 
78 } // namespace ram
79 } // end namespace souffle
souffle::ram::TEST
TEST(Matching, StaticTest_1)
Definition: matching_test.cpp:55
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: test.h:191
EXPECT_LT
#define EXPECT_LT(a, b)
Definition: test.h:199
test.h
souffle::Tuple
std::array< A, N > Tuple
Definition: RamTypes.h:36
EXPECT_NE
#define EXPECT_NE(a, b)
Definition: test.h:195
RamTypes.h
souffle
Definition: AggregateOp.h:25