OmniSciDB  04ee39c94c
StringDictionaryTest.cpp File Reference
#include "../StringDictionary/StringDictionary.h"
#include "TestHelpers.h"
#include <limits>
#include <gtest/gtest.h>
+ Include dependency graph for StringDictionaryTest.cpp:

Go to the source code of this file.

Macros

#define BASE_PATH   "./tmp"
 

Functions

 TEST (StringDictionary, AddAndGet)
 
 TEST (StringDictionary, Recover)
 
 TEST (StringDictionary, HandleEmpty)
 
 TEST (StringDictionary, ManyAddsAndGets)
 
 TEST (StringDictionary, RecoverMany)
 
int main (int argc, char **argv)
 

Variables

const int g_op_count {250000}
 

Macro Definition Documentation

◆ BASE_PATH

#define BASE_PATH   "./tmp"

Definition at line 25 of file StringDictionaryTest.cpp.

Referenced by TEST().

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 89 of file StringDictionaryTest.cpp.

References logger::ERROR, TestHelpers::init_logger_stderr_only(), and LOG.

89  {
91  testing::InitGoogleTest(&argc, argv);
92 
93  int err{0};
94  try {
95  err = RUN_ALL_TESTS();
96  } catch (const std::exception& e) {
97  LOG(ERROR) << e.what();
98  }
99  return err;
100 }
#define LOG(tag)
Definition: Logger.h:182
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194
+ Here is the call graph for this function:

◆ TEST() [1/5]

TEST ( StringDictionary  ,
AddAndGet   
)

Definition at line 28 of file StringDictionaryTest.cpp.

References BASE_PATH, StringDictionary::getIdOfString(), StringDictionary::getOrAdd(), and StringDictionary::getString().

28  {
29  StringDictionary string_dict(BASE_PATH, false, false);
30  auto id1 = string_dict.getOrAdd("foo bar");
31  auto id2 = string_dict.getOrAdd("foo bar");
32  ASSERT_EQ(id1, id2);
33  ASSERT_EQ(0, id1);
34  auto id3 = string_dict.getOrAdd("baz");
35  ASSERT_EQ(1, id3);
36  auto id4 = string_dict.getIdOfString("foo bar");
37  ASSERT_EQ(id1, id4);
38  ASSERT_EQ("foo bar", string_dict.getString(id4));
39 }
#define BASE_PATH
+ Here is the call graph for this function:

◆ TEST() [2/5]

TEST ( StringDictionary  ,
Recover   
)

Definition at line 41 of file StringDictionaryTest.cpp.

References BASE_PATH, StringDictionary::getOrAdd(), and StringDictionary::getString().

41  {
42  StringDictionary string_dict(BASE_PATH, false, true);
43  auto id1 = string_dict.getOrAdd("baz");
44  ASSERT_EQ(1, id1);
45  auto id2 = string_dict.getOrAdd("baz");
46  ASSERT_EQ(1, id2);
47  auto id3 = string_dict.getOrAdd("foo bar");
48  ASSERT_EQ(0, id3);
49  auto id4 = string_dict.getOrAdd("fizzbuzz");
50  ASSERT_EQ(2, id4);
51  ASSERT_EQ("baz", string_dict.getString(id2));
52  ASSERT_EQ("foo bar", string_dict.getString(id3));
53  ASSERT_EQ("fizzbuzz", string_dict.getString(id4));
54 }
#define BASE_PATH
+ Here is the call graph for this function:

◆ TEST() [3/5]

TEST ( StringDictionary  ,
HandleEmpty   
)

Definition at line 56 of file StringDictionaryTest.cpp.

References BASE_PATH, and StringDictionary::getOrAdd().

56  {
57  StringDictionary string_dict(BASE_PATH, false, false);
58  auto id1 = string_dict.getOrAdd("");
59  auto id2 = string_dict.getOrAdd("");
60  ASSERT_EQ(id1, id2);
61  ASSERT_EQ(std::numeric_limits<int32_t>::min(), id1);
62 }
#define BASE_PATH
+ Here is the call graph for this function:

◆ TEST() [4/5]

TEST ( StringDictionary  ,
ManyAddsAndGets   
)

Definition at line 66 of file StringDictionaryTest.cpp.

References BASE_PATH, CHECK_EQ, g_op_count, StringDictionary::getOrAdd(), StringDictionary::getString(), and to_string().

66  {
67  StringDictionary string_dict(BASE_PATH, false, false);
68  for (int i = 0; i < g_op_count; ++i) {
69  CHECK_EQ(i, string_dict.getOrAdd(std::to_string(i)));
70  }
71  for (int i = 0; i < g_op_count; ++i) {
72  CHECK_EQ(i, string_dict.getOrAdd(std::to_string(i)));
73  }
74  for (int i = 0; i < g_op_count; ++i) {
75  CHECK_EQ(std::to_string(i), string_dict.getString(i));
76  }
77 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
#define BASE_PATH
std::string to_string(char const *&&v)
const int g_op_count
+ Here is the call graph for this function:

◆ TEST() [5/5]

TEST ( StringDictionary  ,
RecoverMany   
)

Definition at line 79 of file StringDictionaryTest.cpp.

References BASE_PATH, CHECK_EQ, g_op_count, StringDictionary::getOrAdd(), StringDictionary::getString(), and to_string().

79  {
80  StringDictionary string_dict(BASE_PATH, false, true);
81  for (int i = 0; i < g_op_count; ++i) {
82  CHECK_EQ(i, string_dict.getOrAdd(std::to_string(i)));
83  }
84  for (int i = 0; i < g_op_count; ++i) {
85  CHECK_EQ(std::to_string(i), string_dict.getString(i));
86  }
87 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
#define BASE_PATH
std::string to_string(char const *&&v)
const int g_op_count
+ Here is the call graph for this function:

Variable Documentation

◆ g_op_count

const int g_op_count {250000}

Definition at line 64 of file StringDictionaryTest.cpp.

Referenced by TEST().