mistake, I forgot to add some changes

This commit is contained in:
Marko Budiselic 2016-12-22 19:28:21 +01:00
parent 12080e0c08
commit 422f6a9957
18 changed files with 232 additions and 350 deletions

View File

@ -1,34 +0,0 @@
#pragma once
#include <unordered_map>
#include "threading/sync/lockable.hpp"
#include "threading/sync/spinlock.hpp"
namespace lockfree
{
template <class K, class V>
class HashMap : Lockable<SpinLock>
{
public:
V at(const K& key)
{
auto guard = acquire_unique();
return hashmap[key];
}
void put(const K& key, const K& value)
{
auto guard = acquire_unique();
hashmap[key] = value;
}
private:
std::unordered_map<K, V> hashmap;
};
}

2
tests/unit/README.md Normal file
View File

@ -0,0 +1,2 @@
All unit test should be gtest because in that case the test infrastructure can
then visualize the results. (JUnit xml output)

View File

@ -1,18 +1,17 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "gtest/gtest.h"
#include "data_structures/concurrent/concurrent_list.hpp"
TEST_CASE("Conncurent List insert")
TEST(ConncurentList, Insert)
{
ConcurrentList<int> list;
auto it = list.begin();
it.push(32);
it.reset();
REQUIRE(*it == 32);
ASSERT_EQ(*it, 32);
}
TEST_CASE("Conncurent List iterate")
TEST(ConncurentList, Iterate)
{
ConcurrentList<int> list;
auto it = list.begin();
@ -22,33 +21,33 @@ TEST_CASE("Conncurent List iterate")
it.push(0);
it.reset();
REQUIRE(*it == 0);
ASSERT_EQ(*it, 0);
it++;
REQUIRE(*it == 9);
ASSERT_EQ(*it, 9);
it++;
REQUIRE(*it == 7);
ASSERT_EQ(*it, 7);
it++;
REQUIRE(*it == 32);
ASSERT_EQ(*it, 32);
it++;
REQUIRE(it == list.end());
ASSERT_EQ(it, list.end());
}
TEST_CASE("Conncurent List head remove")
TEST(ConncurentList, RemoveHead)
{
ConcurrentList<int> list;
auto it = list.begin();
it.push(32);
it.reset();
REQUIRE(it.remove());
REQUIRE(it.is_removed());
REQUIRE(!it.remove());
ASSERT_EQ(it.remove(), true);
ASSERT_EQ(it.is_removed(), true);
ASSERT_EQ(!it.remove(), true);
it.reset();
REQUIRE(it == list.end());
ASSERT_EQ(it, list.end());
}
TEST_CASE("Conncurent List remove")
TEST(ConncurentList, Remove)
{
ConcurrentList<int> list;
auto it = list.begin();
@ -60,16 +59,22 @@ TEST_CASE("Conncurent List remove")
it++;
it++;
REQUIRE(it.remove());
REQUIRE(it.is_removed());
REQUIRE(!it.remove());
ASSERT_EQ(it.remove(), true);
ASSERT_EQ(it.is_removed(), true);
ASSERT_EQ(!it.remove(), true);
it.reset();
REQUIRE(*it == 0);
ASSERT_EQ(*it, 0);
it++;
REQUIRE(*it == 9);
ASSERT_EQ(*it, 9);
it++;
REQUIRE(*it == 32);
ASSERT_EQ(*it, 32);
it++;
REQUIRE(it == list.end());
ASSERT_EQ(it, list.end());
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,5 +1,7 @@
#include <iostream>
#include "gtest/gtest.h"
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
#include "data_structures/concurrent/concurrent_map.hpp"
@ -7,26 +9,18 @@
#include "logging/streams/stdout.hpp"
#include "utils/assert.hpp"
using std::cout;
using std::endl;
using skiplist_t = ConcurrentMap<int, int>;
void print_skiplist(const skiplist_t::Accessor &skiplist)
{
cout << "---- skiplist now has: ";
logging::info("Skiplist now has: ");
for (auto &kv : skiplist)
cout << "(" << kv.first << ", " << kv.second << ") ";
cout << "----" << endl;
logging::info(" ({}, {})", kv.first, kv.second);
}
int main(void)
TEST(ConcurrentMapSkiplist, Mix)
{
logging::init_async();
logging::log->pipe(std::make_unique<Stdout>());
skiplist_t skiplist;
auto accessor = skiplist.access();
@ -71,6 +65,13 @@ int main(void)
"insert unique element");
print_skiplist(accessor);
return 0;
}
int main(int argc, char **argv)
{
logging::init_async();
logging::log->pipe(std::make_unique<Stdout>());
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,33 +1,28 @@
#include <iostream>
#include "gtest/gtest.h"
#include "data_structures/concurrent/concurrent_set.hpp"
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
#include "utils/assert.hpp"
using std::cout;
using std::endl;
void print_skiplist(const ConcurrentSet<int>::Accessor &skiplist)
{
cout << "---- skiplist set now has: ";
logging::info("Skiplist set now has:");
for (auto &item : skiplist)
cout << item << ", ";
cout << "----" << endl;
logging::info("{}", item);
}
int main(void)
TEST(ConcurrentSet, Mix)
{
logging::init_async();
logging::log->pipe(std::make_unique<Stdout>());
ConcurrentSet<int> set;
auto accessor = set.access();
cout << std::boolalpha;
permanent_assert(accessor.insert(1).second == true,
"added non-existing 1? (true)");
@ -57,6 +52,10 @@ int main(void)
permanent_assert(accessor.insert(4).second == true, "add 4");
print_skiplist(accessor);
return 0;
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,13 +1,12 @@
#include <iostream>
#include "gtest/gtest.h"
#include "query/backend/cpp_old/entity_search.hpp"
#include "utils/assert.hpp"
#include "utils/underlying_cast.hpp"
using std::cout;
using std::endl;
int main()
TEST(CypherStateMachine, Basic)
{
// initialize cypher state machine
CypherStateMachine csm;
@ -31,6 +30,10 @@ int main()
// check minimum cost
permanent_assert(csm.min("n") == entity_search::search_label_index,
"Search place should be label index");
return 0;
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,35 +0,0 @@
#include <iostream>
#include <utility>
#include "storage/indexes/index.hpp"
// boilerplate
using std::cout;
using std::endl;
// types
using StringUniqueKeyAsc = UniqueKeyAsc<std::shared_ptr<std::string>>;
using index_t = Index<StringUniqueKeyAsc, std::string>;
int main(void)
{
// index creation
auto index = std::make_shared<index_t>();
// prepare values
StringUniqueKeyAsc key(std::make_shared<std::string>("test_key"));
auto value_ptr = std::make_shared<std::string>("test_value");
// insert into and unpack pair
index_t::skiplist_t::Iterator find_iterator;
bool insertion_succeeded;
std::tie(find_iterator, insertion_succeeded) =
index->insert(key, value_ptr.get());
assert(insertion_succeeded == true);
// get inserted value
auto inserted_value = *index->find(key);
assert(*inserted_value.second == *value_ptr);
return 0;
}

View File

@ -1,20 +1,25 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "gtest/gtest.h"
#include "data_structures/bitset/dynamic_bitset.hpp"
TEST_CASE("Dynamic bitset basic functionality")
TEST(DynamicBitset, BasicFunctionality)
{
DynamicBitset<> db;
db.set(222555, 1);
bool value = db.at(222555, 1);
REQUIRE(value == true);
ASSERT_EQ(value, true);
db.set(32, 1);
value = db.at(32, 1);
REQUIRE(value == true);
ASSERT_EQ(value, true);
db.clear(32, 1);
value = db.at(32, 1);
REQUIRE(value == false);
ASSERT_EQ(value, false);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,83 +0,0 @@
// TODO: include this into CMakeLists
// compile the shared library
// clang++ -std=c++1y mysql.cpp -o ../tmp/mysql.so -shared -fPIC
// clang++ -std=c++1y memsql.cpp -o ../tmp/memsql.so -shared -fPIC
// clang++ -std=c++1y dynamic_lib.cpp -o test.out -ldl
#include <iostream>
#include <fstream>
#include <vector>
#include <iterator>
#include <cstdlib>
#include "dc/dynamic_lib.hpp"
#include "utils/string/file.hpp"
class db
{
public:
// If virtual methods don't have = 0 the compiler
// won't create appropriate _ZTI symbol inside
// the .so lib. That will lead to undefined symbol
// error while the library is loading.
//
// TODO: why?
virtual void name() const = 0;
virtual void type() const = 0;
virtual ~db() {}
};
typedef db* (*produce_t)();
typedef void (*destruct_t)(db*);
using std::cout;
using std::endl;
// dependent on specific dynamic code
// "configuration" of DynamicLib
// DynamicLib<MemgraphDynamicLib>
class MemgraphDynamicLib
{
public:
const static std::string produce_name;
const static std::string destruct_name;
using produce = produce_t;
using destruct = destruct_t;
};
const std::string MemgraphDynamicLib::produce_name = "produce";
const std::string MemgraphDynamicLib::destruct_name = "destruct";
int main()
{
// -- compile example
// string tmp_file_path = "tmp/tmp.cpp";
// string tmp_so_path = "tmp/tmp.so";
// string for_compile = "#include <iostream>\nint main() { std::cout << \"test\" << std::endl; return 0; }";
// write(tmp_file_path, for_compile);
// string test_command = prints("clang++", tmp_file_path, "-o", "test.out");
// system(test_command.c_str());
// -- end compile example
// -- load example
using db_lib = DynamicLib<MemgraphDynamicLib>;
db_lib mysql_db("./tmp/mysql.so");
mysql_db.load();
auto mysql = mysql_db.produce_method();
if (mysql) {
mysql->name();
}
mysql_db.destruct_method(mysql);
db_lib memsql_db("./tmp/memsql.so");
memsql_db.load();
auto memsql = memsql_db.produce_method();
if (memsql) {
memsql->name();
}
memsql_db.destruct_method(memsql);
return 0;
}

View File

@ -1,11 +0,0 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "data_structures/map/hashmap.hpp"
TEST_CASE("Lockfree HashMap basic functionality")
{
lockfree::HashMap<int, int> hashmap;
hashmap.put(32, 10);
REQUIRE(hashmap.at(32) == 10);
}

View File

@ -1,4 +1,4 @@
#include <iostream>
#include "gtest/gtest.h"
#include "query/backend/cpp_old/query_action_data.hpp"
#include "utils/assert.hpp"
@ -6,7 +6,7 @@
using ParameterIndexKey::Type::InternalId;
using ParameterIndexKey::Type::Projection;
auto main() -> int
TEST(ParameterIndexKey, Basic)
{
std::map<ParameterIndexKey, uint64_t> parameter_index;
@ -15,6 +15,10 @@ auto main() -> int
permanent_assert(parameter_index.size() == 2,
"Parameter index size should be 2");
return 0;
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,12 +1,13 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "gtest/gtest.h"
#include "utils/command_line/arguments.hpp"
// beacuse of c++ 11
// TODO: figure out better solution
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wwritable-strings"
TEST_CASE("ProgramArgument FlagOnly Test")
TEST(ProgramArgument, FlagOnly)
{
CLEAR_ARGS();
@ -16,10 +17,10 @@ TEST_CASE("ProgramArgument FlagOnly Test")
REGISTER_ARGS(argc, argv);
REGISTER_REQUIRED_ARGS({"-test"});
REQUIRE(CONTAINS_FLAG("-test") == true);
ASSERT_EQ(CONTAINS_FLAG("-test"), true);
}
TEST_CASE("ProgramArgument Single Entry Test")
TEST(ProgramArgument, SingleEntry)
{
CLEAR_ARGS();
@ -29,10 +30,10 @@ TEST_CASE("ProgramArgument Single Entry Test")
REGISTER_REQUIRED_ARGS({"-bananas"});
REGISTER_ARGS(argc, argv);
REQUIRE(GET_ARG("-bananas", "100").get_int() == 99);
ASSERT_EQ(GET_ARG("-bananas", "100").get_int(), 99);
}
TEST_CASE("ProgramArgument Multiple Entries Test")
TEST(ProgramArgument, MultipleEntries)
{
CLEAR_ARGS();
@ -44,10 +45,10 @@ TEST_CASE("ProgramArgument Multiple Entries Test")
auto files = GET_ARGS("-files", {});
REQUIRE(files[0].get_string() == "first_file.txt");
ASSERT_EQ(files[0].get_string(), "first_file.txt");
}
TEST_CASE("ProgramArgument Combination Test")
TEST(ProgramArgument, Combination)
{
CLEAR_ARGS();
@ -69,21 +70,27 @@ TEST_CASE("ProgramArgument Combination Test")
REGISTER_ARGS(argc, argv);
REQUIRE(CONTAINS_FLAG("-run_tests") == true);
ASSERT_EQ(CONTAINS_FLAG("-run_tests"), true);
auto tests = GET_ARGS("-tests", {});
REQUIRE(tests[0].get_string() == "Test1");
REQUIRE(tests[1].get_string() == "Test2");
REQUIRE(tests[2].get_string() == "Test3");
ASSERT_EQ(tests[0].get_string(), "Test1");
ASSERT_EQ(tests[1].get_string(), "Test2");
ASSERT_EQ(tests[2].get_string(), "Test3");
REQUIRE(GET_ARG("-run_times", "0").get_int() == 10);
ASSERT_EQ(GET_ARG("-run_times", "0").get_int(), 10);
auto exports = GET_ARGS("-export", {});
REQUIRE(exports[0].get_string() == "test1.txt");
REQUIRE(exports[1].get_string() == "test2.txt");
REQUIRE(exports[2].get_string() == "test3.txt");
ASSERT_EQ(exports[0].get_string(), "test1.txt");
ASSERT_EQ(exports[1].get_string(), "test2.txt");
ASSERT_EQ(exports[2].get_string(), "test3.txt");
REQUIRE(GET_ARG("-import", "test.txt").get_string() == "data.txt");
ASSERT_EQ(GET_ARG("-import", "test.txt").get_string(), "data.txt");
}
#pragma clang diagnostic pop
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,25 +1,30 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "gtest/gtest.h"
#include "data_structures/ptr_int.hpp"
TEST_CASE("Size of pointer integer object")
TEST(PtrInt, SizeOf)
{
REQUIRE(sizeof(PtrInt<int *, 1, int>) == sizeof(uintptr_t));
ASSERT_EQ(sizeof(PtrInt<int *, 1, int>), sizeof(uintptr_t));
}
TEST_CASE("Construct and read pointer integer pair type")
TEST(PtrInt, ConstructionAndRead)
{
auto ptr1 = std::make_unique<int>(2);
PtrInt<int *, 2, int> pack1(ptr1.get(), 1);
REQUIRE(pack1.get_int() == 1);
REQUIRE(pack1.get_ptr() == ptr1.get());
ASSERT_EQ(pack1.get_int(), 1);
ASSERT_EQ(pack1.get_ptr(), ptr1.get());
auto ptr2 = std::make_unique<int>(2);
PtrInt<int *, 3, int> pack2(ptr2.get(), 4);
REQUIRE(pack2.get_int() == 4);
REQUIRE(pack2.get_ptr() == ptr2.get());
ASSERT_EQ(pack2.get_int(), 4);
ASSERT_EQ(pack2.get_ptr(), ptr2.get());
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,5 +1,4 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "gtest/gtest.h"
#include "data_structures/map/rh_hashmap.hpp"
@ -18,82 +17,82 @@ public:
void cross_validate(RhHashMap<int, Data> &map, std::map<int, Data *> &s_map);
TEST_CASE("Robin hood hashmap basic functionality")
TEST(RobinHoodHashmap, BasicFunctionality)
{
RhHashMap<int, Data> map;
REQUIRE(map.size() == 0);
REQUIRE(map.insert(new Data(0)));
REQUIRE(map.size() == 1);
ASSERT_EQ(map.size(), 0);
ASSERT_EQ(map.insert(new Data(0)), true);
ASSERT_EQ(map.size(), 1);
}
TEST_CASE("Robin hood hashmap remove functionality")
TEST(RobinHoodHashmap, RemoveFunctionality)
{
RhHashMap<int, Data> map;
REQUIRE(map.insert(new Data(0)));
REQUIRE(map.remove(0).is_present());
REQUIRE(map.size() == 0);
REQUIRE(!map.find(0).is_present());
ASSERT_EQ(map.insert(new Data(0)), true);
ASSERT_EQ(map.remove(0).is_present(), true);
ASSERT_EQ(map.size(), 0);
ASSERT_EQ(!map.find(0).is_present(), true);
}
TEST_CASE("Robin hood hashmap insert/get check")
TEST(RobinHoodHashmap, InsertGetCheck)
{
RhHashMap<int, Data> map;
REQUIRE(!map.find(0).is_present());
ASSERT_EQ(!map.find(0).is_present(), true);
auto ptr0 = new Data(0);
REQUIRE(map.insert(ptr0));
REQUIRE(map.find(0).is_present());
REQUIRE(map.find(0).get() == ptr0);
ASSERT_EQ(map.insert(ptr0), true);
ASSERT_EQ(map.find(0).is_present(), true);
ASSERT_EQ(map.find(0).get(), ptr0);
}
TEST_CASE("Robin hood hashmap double insert")
TEST(RobinHoodHashmap, DoubleInsert)
{
RhHashMap<int, Data> map;
REQUIRE(map.insert(new Data(0)));
REQUIRE(!map.insert(new Data(0)));
ASSERT_EQ(map.insert(new Data(0)), true);
ASSERT_EQ(!map.insert(new Data(0)), true);
}
TEST_CASE("Robin hood hashmap")
TEST(RobinHoodHashmap, FindInsertFind)
{
RhHashMap<int, Data> map;
for (int i = 0; i < 128; i++) {
REQUIRE(!map.find(i).is_present());
REQUIRE(map.insert(new Data(i)));
REQUIRE(map.find(i).is_present());
ASSERT_EQ(!map.find(i).is_present(), true);
ASSERT_EQ(map.insert(new Data(i)), true);
ASSERT_EQ(map.find(i).is_present(), true);
}
for (int i = 0; i < 128; i++) {
REQUIRE(map.find(i).is_present());
REQUIRE(map.find(i).get()->get_key() == i);
ASSERT_EQ(map.find(i).is_present(), true);
ASSERT_EQ(map.find(i).get()->get_key(), i);
}
}
TEST_CASE("Robin hood hashmap iterate")
TEST(RobinHoodHashmap, Iterate)
{
RhHashMap<int, Data> map;
for (int i = 0; i < 128; i++) {
REQUIRE(!map.find(i).is_present());
REQUIRE(map.insert(new Data(i)));
REQUIRE(map.find(i).is_present());
ASSERT_EQ(!map.find(i).is_present(), true);
ASSERT_EQ(map.insert(new Data(i)), true);
ASSERT_EQ(map.find(i).is_present(), true);
}
bool seen[128] = {false};
for (auto e : map) {
auto key = e->get_key();
REQUIRE(!seen[key]);
ASSERT_EQ(!seen[key], true);
seen[key] = true;
}
for (int i = 0; i < 128; i++) {
REQUIRE(seen[i]);
ASSERT_EQ(seen[i], true);
}
}
TEST_CASE("Robin hood hashmap checked")
TEST(RobinHoodHashmap, Checked)
{
RhHashMap<int, Data> map;
std::map<int, Data *> s_map;
@ -102,17 +101,17 @@ TEST_CASE("Robin hood hashmap checked")
int key = std::rand();
auto data = new Data(key);
if (map.insert(data)) {
REQUIRE(s_map.find(key) == s_map.end());
ASSERT_EQ(s_map.find(key), s_map.end());
s_map[key] = data;
} else {
REQUIRE(s_map.find(key) != s_map.end());
ASSERT_NE(s_map.find(key), s_map.end());
}
}
cross_validate(map, s_map);
}
TEST_CASE("Robin hood hashmap checked with remove")
TEST(RobinHoodHashMap, CheckWithRemove)
{
RhHashMap<int, Data> map;
std::map<int, Data *> s_map;
@ -121,12 +120,12 @@ TEST_CASE("Robin hood hashmap checked with remove")
int key = std::rand() % 100;
auto data = new Data(key);
if (map.insert(data)) {
REQUIRE(s_map.find(key) == s_map.end());
ASSERT_EQ(s_map.find(key), s_map.end());
s_map[key] = data;
cross_validate(map, s_map);
} else {
REQUIRE(map.remove(key).is_present());
REQUIRE(s_map.erase(key) == 1);
ASSERT_EQ(map.remove(key).is_present(), true);
ASSERT_EQ(s_map.erase(key), 1);
cross_validate(map, s_map);
}
}
@ -137,10 +136,16 @@ TEST_CASE("Robin hood hashmap checked with remove")
void cross_validate(RhHashMap<int, Data> &map, std::map<int, Data *> &s_map)
{
for (auto e : map) {
REQUIRE(s_map.find(e->get_key()) != s_map.end());
ASSERT_NE(s_map.find(e->get_key()), s_map.end());
}
for (auto e : s_map) {
REQUIRE(map.find(e.first).get() == e.second);
ASSERT_EQ(map.find(e.first).get(), e.second);
}
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,5 +1,4 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "gtest/gtest.h"
#include "data_structures/map/rh_hashmultimap.hpp"
@ -22,43 +21,43 @@ void cross_validate(RhHashMultiMap<int, Data> &map,
void cross_validate_weak(RhHashMultiMap<int, Data> &map,
std::multimap<int, Data *> &s_map);
TEST_CASE("Robin hood hashmultimap basic functionality")
TEST(RobinHoodHashmultimap, BasicFunctionality)
{
RhHashMultiMap<int, Data> map;
REQUIRE(map.size() == 0);
ASSERT_EQ(map.size(), 0);
map.add(new Data(0));
REQUIRE(map.size() == 1);
ASSERT_EQ(map.size(), 1);
}
TEST_CASE("Robin hood hashmultimap insert/get check")
TEST(RobinHoodHashmultimap, InsertGetCheck)
{
RhHashMultiMap<int, Data> map;
REQUIRE(map.find(0) == map.end());
ASSERT_EQ(map.find(0), map.end());
auto ptr0 = new Data(0);
map.add(ptr0);
REQUIRE(map.find(0) != map.end());
REQUIRE(*map.find(0) == ptr0);
ASSERT_NE(map.find(0), map.end());
ASSERT_EQ(*map.find(0), ptr0);
}
TEST_CASE("Robin hood hashmultimap extreme same key valus full")
TEST(RobinHoodHashmultimap, ExtremeSameKeyValusFull)
{
RhHashMultiMap<int, Data> map;
for (int i = 0; i < 128; i++) {
map.add(new Data(7));
}
REQUIRE(map.size() == 128);
REQUIRE(map.find(7) != map.end());
REQUIRE(map.find(0) == map.end());
ASSERT_EQ(map.size(), 128);
ASSERT_NE(map.find(7), map.end());
ASSERT_EQ(map.find(0), map.end());
auto ptr0 = new Data(0);
map.add(ptr0);
REQUIRE(map.find(0) != map.end());
REQUIRE(*map.find(0) == ptr0);
ASSERT_NE(map.find(0), map.end());
ASSERT_EQ(*map.find(0), ptr0);
}
TEST_CASE("Robin hood hashmultimap extreme same key valus full with remove")
TEST(RobinHoodHashmultimap, ExtremeSameKeyValusFullWithRemove)
{
RhHashMultiMap<int, Data> map;
@ -67,25 +66,25 @@ TEST_CASE("Robin hood hashmultimap extreme same key valus full with remove")
}
auto ptr = new Data(7);
map.add(ptr);
REQUIRE(map.size() == 128);
REQUIRE(!map.remove(new Data(0)));
REQUIRE(map.remove(ptr));
ASSERT_EQ(map.size(), 128);
ASSERT_EQ(!map.remove(new Data(0)), true);
ASSERT_EQ(map.remove(ptr), true);
}
TEST_CASE("Robin hood hasmultihmap remove functionality")
TEST(RobinHoodHasmultihmap, RemoveFunctionality)
{
RhHashMultiMap<int, Data> map;
REQUIRE(map.find(0) == map.end());
ASSERT_EQ(map.find(0), map.end());
auto ptr0 = new Data(0);
map.add(ptr0);
REQUIRE(map.find(0) != map.end());
REQUIRE(*map.find(0) == ptr0);
REQUIRE(map.remove(ptr0));
REQUIRE(map.find(0) == map.end());
ASSERT_NE(map.find(0), map.end());
ASSERT_EQ(*map.find(0), ptr0);
ASSERT_EQ(map.remove(ptr0), true);
ASSERT_EQ(map.find(0), map.end());
}
TEST_CASE("Robin hood hashmultimap double insert")
TEST(RobinHoodHashmultimap, DoubleInsert)
{
RhHashMultiMap<int, Data> map;
@ -103,48 +102,48 @@ TEST_CASE("Robin hood hashmultimap double insert")
ptr1 = nullptr;
continue;
}
REQUIRE(false);
ASSERT_EQ(true, false);
}
}
TEST_CASE("Robin hood hashmultimap")
TEST(RobinHoodHashmultimap, FindAddFind)
{
RhHashMultiMap<int, Data> map;
for (int i = 0; i < 128; i++) {
REQUIRE(map.find(i) == map.end());
ASSERT_EQ(map.find(i), map.end());
map.add(new Data(i));
REQUIRE(map.find(i) != map.end());
ASSERT_NE(map.find(i), map.end());
}
for (int i = 0; i < 128; i++) {
REQUIRE(map.find(i) != map.end());
REQUIRE(map.find(i)->get_key() == i);
ASSERT_NE(map.find(i), map.end());
ASSERT_EQ(map.find(i)->get_key(), i);
}
}
TEST_CASE("Robin hood hashmultimap iterate")
TEST(RobinHoodHashmultimap, Iterate)
{
RhHashMultiMap<int, Data> map;
for (int i = 0; i < 128; i++) {
REQUIRE(map.find(i) == map.end());
ASSERT_EQ(map.find(i), map.end());
map.add(new Data(i));
REQUIRE(map.find(i) != map.end());
ASSERT_NE(map.find(i), map.end());
}
bool seen[128] = {false};
for (auto e : map) {
auto key = e->get_key();
REQUIRE(!seen[key]);
ASSERT_EQ(!seen[key], true);
seen[key] = true;
}
for (int i = 0; i < 128; i++) {
REQUIRE(seen[i]);
ASSERT_EQ(seen[i], true);
}
}
TEST_CASE("Robin hood hashmultimap checked")
TEST(RobinHoodHashmultimap, Checked)
{
RhHashMultiMap<int, Data> map;
std::multimap<int, Data *> s_map;
@ -159,7 +158,7 @@ TEST_CASE("Robin hood hashmultimap checked")
cross_validate(map, s_map);
}
TEST_CASE("Robin hood hashmultimap checked rand")
TEST(RobinHoodHashmultimap, CheckedRand)
{
RhHashMultiMap<int, Data> map;
std::multimap<int, Data *> s_map;
@ -174,7 +173,7 @@ TEST_CASE("Robin hood hashmultimap checked rand")
cross_validate(map, s_map);
}
TEST_CASE("Robin hood hashmultimap with remove data checked")
TEST(RobinHoodHashmultimap, WithRemoveDataChecked)
{
RhHashMultiMap<int, Data> map;
std::multimap<int, Data *> s_map;
@ -185,10 +184,10 @@ TEST_CASE("Robin hood hashmultimap with remove data checked")
if ((std::rand() % 2) == 0) {
auto it = s_map.find(key);
if (it == s_map.end()) {
REQUIRE(map.find(key) == map.end());
ASSERT_EQ(map.find(key), map.end());
} else {
s_map.erase(it);
REQUIRE(map.remove(it->second));
ASSERT_EQ(map.remove(it->second), true);
}
} else {
auto data = new Data(key);
@ -210,7 +209,7 @@ void cross_validate(RhHashMultiMap<int, Data> &map,
while (it != s_map.end() && it->second != e) {
it++;
}
REQUIRE(it != s_map.end());
ASSERT_NE(it, s_map.end());
}
for (auto e : s_map) {
@ -219,7 +218,7 @@ void cross_validate(RhHashMultiMap<int, Data> &map,
while (it != map.end() && *it != e.second) {
it++;
}
REQUIRE(it != map.end());
ASSERT_NE(it, map.end());
}
}
@ -238,7 +237,7 @@ void cross_validate_weak(RhHashMultiMap<int, Data> &map,
it++;
count--;
}
REQUIRE(count == 0);
ASSERT_EQ(count, 0);
key = e->get_key();
count = 1;
}
@ -250,7 +249,7 @@ void cross_validate_weak(RhHashMultiMap<int, Data> &map,
it++;
count--;
}
REQUIRE(count == 0);
ASSERT_EQ(count, 0);
}
for (auto e : s_map) {
@ -263,7 +262,7 @@ void cross_validate_weak(RhHashMultiMap<int, Data> &map,
it++;
count--;
}
REQUIRE(count == 0);
ASSERT_EQ(count, 0);
key = e.first;
count = 1;
}
@ -275,6 +274,6 @@ void cross_validate_weak(RhHashMultiMap<int, Data> &map,
it++;
count--;
}
REQUIRE(count == 0);
ASSERT_EQ(count, 0);
}
}

View File

@ -1,5 +1,4 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "gtest/gtest.h"
#include <iostream>
#include <string>
@ -8,7 +7,7 @@
#include "utils/signals/handler.hpp"
#include "utils/stacktrace/stacktrace.hpp"
TEST_CASE("SignalHandler Segmentation Fault Test")
TEST(SignalHandler, SegmentationFaultTest)
{
SignalHandler::register_handler(Signal::SegmentationFault, []() {
std::cout << "Segmentation Fault" << std::endl;
@ -18,3 +17,9 @@ TEST_CASE("SignalHandler Segmentation Fault Test")
std::raise(SIGSEGV);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,12 +1,17 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "gtest/gtest.h"
#include "template_engine/engine.hpp"
TEST_CASE("Template Engine - basic placeholder replacement")
TEST(TemplateEngine, BasicPlaceholderReplacement)
{
auto rendered = template_engine::render("{{one}} {{two}}",
{{"one", "two"}, {"two", "one"}});
REQUIRE(rendered == "two one");
ASSERT_EQ(rendered, "two one");
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}