diff --git a/include/detail/list_storage.hpp b/include/detail/list_storage.hpp new file mode 100644 index 0000000..3a0d7f0 --- /dev/null +++ b/include/detail/list_storage.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include +#include + +#include "detail/node.hpp" + +namespace efesx { +namespace queue { +namespace detail +{ + + +class list_storage { +private: + std::list store; +public: + list_storage() = default; + list_storage(const list_storage&) = delete; + list_storage(list_storage&&) = delete; + list_storage& operator=(list_storage&&) = delete; + ~list_storage() = default; + + template + void insert(Args...args){ + store.emplace_back(args...); + store.sort(); + } + + template + std::optional extract(void* buf = nullptr){ + if(store.size() == 0) { + return std::optional{}; + } + + node& val = store.front(); + + if(!val.has_value() || val.size() == 0){ + return std::optional{}; + } + + if (buf != nullptr){ + val.blob_copy(buf); + return std::optional{}; + } + + try{ + return val.value_cast(); + } catch (std::runtime_error& e){ + return std::optional{}; + } + + } + + void pop(){ + store.pop_front(); + } + + template + std::optional extract_with_type(void* buf = nullptr){ + throw std::runtime_error("Not Yet Implemented Error"); + } + + + +}; + + + +}; // namespace detail +}; // namespace queue +}; // namespace efesxzc diff --git a/include/detail/meta.hpp b/include/detail/meta.hpp index 8dfd3ad..0e9b81f 100644 --- a/include/detail/meta.hpp +++ b/include/detail/meta.hpp @@ -10,37 +10,14 @@ namespace efesx { namespace queue { namespace detail { -//@brief Structure for convertig T to value_t template -struct detector { - inline static constexpr value_t type = value_t::null_t; -}; -template<> -struct detector{ - inline static constexpr value_t type = value_t::int_t; -}; -template<> -struct detector{ - inline static constexpr value_t type = value_t::bool_t; -}; -template<> -struct detector{ - inline static constexpr value_t type = value_t::string_t; -}; -template<> -struct detector{ - inline static constexpr value_t type = value_t::char_t; -}; +concept IsIntegral = std::is_integral_v; template -concept Container = - requires { typename T::iterator::iterator_category::forward_iterator_tag; } && - !std::is_same_v && - requires (T a) { - { a.begin()++ }; - { a.end() }; - { a.size() } -> std::convertible_to; - }; +concept IsFloating = std::is_floating_point_v>; + +template +concept IsString = std::is_convertible_v; }; // namespace detail }; // namespace queue diff --git a/include/detail/node.hpp b/include/detail/node.hpp index e55df53..f40079b 100644 --- a/include/detail/node.hpp +++ b/include/detail/node.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "types.hpp" #include "meta.hpp" @@ -7,154 +9,116 @@ namespace efesx { namespace queue { namespace detail { -class node { +struct node { private: -union node_value -{ - int int_value; - bool bool_value; - char char_value; - std::string* string_value; - std::vector* array_value; - - std::size_t v_size; - - node_value() = default; - node_value(const node_value&) = default; - node_value(node_value&& oth) = default; - - node_value(int v) : int_value(v) {} - node_value(bool v) : bool_value(v) {} - node_value(char v) : char_value(v) {} - - node_value(value_t t, std::size_t size) { - switch (t) - { - case value_t::container_t: { - array_value = create>(); - array_value->reserve(size); - break; - } - - default: break; - } - } - - node_value(const std::string& v) : string_value(create(v)) {} - node_value(const std::string&& v) : string_value(create(std::move(v))) {} - - template, int> = 0> - node_value(T arr, std::size_t size) { - array_value = create>(); - array_value->reserve(size); - - for (auto i = 0; i < size; i++){ - array_value->emplace_back(arr[i]); - } - } + const uint8_t m_priority = 0; + const value_t m_type; + const std::size_t m_size; + void* m_data; template - static T* create(Args&& ... args){ + T* create(Args&& ... args){ using allocator_traits = std::allocator_traits>; - std::allocator alloc; + + auto deleter = [&](T* obj){ allocator_traits::deallocate(alloc, obj, 1); }; + std::unique_ptr obj(allocator_traits::allocate(alloc, 1), deleter); allocator_traits::construct(alloc, obj.get(), std::forward(args)...); return obj.release(); } - void destroy(value_t t) { - switch (t) - { - case value_t::string_t: { - std::allocator alloc; - std::allocator_traits::destroy(alloc, string_value); - std::allocator_traits::deallocate(alloc, string_value, 1); - break; - } - case value_t::array_t: { - std::allocator> alloc; - std::allocator_traits::destroy(alloc, array_value); - std::allocator_traits::deallocate(alloc, array_value, 1); - break; - } - - default: break; - } + template + void destroy(T* mem, std::size_t size){ + std::allocator alloc; + std::allocator_traits::destroy(alloc, mem); + std::allocator_traits::deallocate(alloc, mem, size); + m_data = nullptr; } -}; public: - value_t m_type; - value_t m_subtype; + node() : m_type(value_t::null), m_size(0), m_data(nullptr) {} + + node(const node&) = delete; + node(node&&) = delete; + node& operator=(node&&) = delete; + ~node(){ + if (m_type == value_t::blob) { + std::free(m_data); + return; + } + destroy(static_cast(m_data), m_size); + } - node_value m_data; + template + node(const T& val) : m_size(Size), m_type(value_t::integer), m_data(create(val)) + {} - // ARRAY - template, int> = 0> requires (!Container) - node(const T val, std::size_t size, std::size_t priority = 0) : - m_data(val, size), - m_type(value_t::array_t), - m_subtype(detector>>::type) + template + node(const T& val) : m_size(Size), m_type(value_t::floating), m_data(create(val)) {} - // ANOTHER ALL - template && !std::is_pointer_v, int> = 0> - node(T val, std::size_t priority = 0) : - m_data(val), - m_type(detector::type) + template + node(const T& val) : m_size(val.size()), m_type(value_t::text), m_data(create(val)) {} - // STRING - template>, int> = 0> - node(T val, std::size_t priority = 0) : - m_data(val), - m_type(detector::type) + node(const char* val, std::size_t _size) : m_size(_size), m_type(value_t::text), m_data(create(std::string(val, _size))) {} - // CONTAINERS - template - node(const T& container, std::size_t priority = 0) : - m_data(value_t::container_t, container.size()), - m_type(value_t::container_t) - { - for (auto it = container.begin(); it != container.end(); it++){ - m_data.array_value->emplace_back(*it, priority); + node(const void* val, std::size_t _size) : m_size(_size), m_type(value_t::blob), m_data(std::malloc(_size)) { + std::memcpy(m_data, val, _size); + } + + template + T&& value_cast(){ + if (m_data == nullptr){ + throw std::runtime_error("Node Value Is Empty"); } + + if ((IsIntegral && (m_type != value_t::integer)) || + (IsFloating && (m_type != value_t::floating))|| + (IsString && (m_type != value_t::text))) + { + throw std::runtime_error("Bad Node Value Cast"); + } + + return std::forward(*static_cast(m_data)); } + - node(const node&) = default; - node(node&& oth) = default; + void blob_copy(void *dst){ + std::memcpy(dst, m_data, m_size); + } - ~node() { - m_data.destroy(m_type); + std::size_t size(){ + return m_size; } - // ANOTHER ALL - template && !std::is_pointer_v, int> = 0> - void restore(T& data){ - data = m_data.int_value; + bool has_value(){ + return (m_data != nullptr); } - // STRING - template>, int> = 0> - void restore(T& data){ - data = *m_data.string_value; + value_t value_type(){ + return m_type; } - // ARRAY - template, int> = 0> requires (!Container) - void restore(T val) { - std::size_t idx = 0; - for (auto it = m_data.array_value->begin(); it != m_data.array_value->end(); it++){ - it->restore(val[idx]); - idx++; - } + uint8_t priority(){ + return m_priority; + } + + bool operator<(node& rhs){ + return (m_priority > rhs.m_priority); } }; + + + + + + }; // namespace detail }; // namespace queue }; // namespace efesx diff --git a/include/detail/types.hpp b/include/detail/types.hpp index 27619ba..1d2ad1d 100644 --- a/include/detail/types.hpp +++ b/include/detail/types.hpp @@ -7,33 +7,14 @@ namespace efesx { namespace queue { namespace detail { -enum class value_t : uint8_t -{ - null_t = 0, - int_t, - char_t, - bool_t, - string_t, - array_t, - object_t, - container_t, +enum value_t { + null = 0, + integer, + floating, + text, + blob }; -std::ostream& operator<<(std::ostream& out, const value_t& val){ - switch (val) - { - case value_t::null_t: { out << "null_t"; break; } - case value_t::int_t: { out << "int_t"; break; } - case value_t::bool_t: { out << "bool_t"; break; } - case value_t::string_t: { out << "string_t"; break; } - case value_t::array_t: { out << "array_t"; break; } - case value_t::object_t: { out << "object_t"; break; } - case value_t::char_t: { out << "char_t"; break; } - case value_t::container_t: { out << "conteiner_t"; break; } - default: {out << "other_t"; break; } - } - return out; -} }; // namespace detail }; // namespace queue diff --git a/include/detail/utils.hpp b/include/detail/utils.hpp index 83dbd61..0c9f842 100644 --- a/include/detail/utils.hpp +++ b/include/detail/utils.hpp @@ -8,53 +8,6 @@ namespace efesx { namespace queue { namespace detail { -std::ostream& operator<<(std::ostream& out, const node& val){ - out << val.m_type << " : "; - - switch (val.m_type) - { - case value_t::int_t: { - out << val.m_data.int_value; - break; - } - case value_t::char_t: { - switch (val.m_data.char_value) - { - case '\n': out << "\\n"; break; - case '\r': out << "\\r"; break; - - default: out << std::string{val.m_data.char_value}; break; - } - break; - } - case value_t::bool_t: { - out << std::boolalpha << val.m_data.bool_value; - break; - } - case value_t::string_t: { - out << val.m_data.string_value->c_str(); - break; - } - - case value_t::container_t: - case value_t::array_t: { - out << "["; - - for(auto it = val.m_data.array_value->begin(); it != val.m_data.array_value->end();){ - out << *it; - - if(++it != val.m_data.array_value->end()){ - std::cout << ", "; - } - } - - out << "]"; - break; - } - default: {out << "other"; break; } - } - return out; -} }; // namespace detail diff --git a/include/queue.hpp b/include/queue.hpp index dbbbf30..9d9b2b8 100644 --- a/include/queue.hpp +++ b/include/queue.hpp @@ -4,49 +4,22 @@ #include #include "detail/node.hpp" +#include "detail/list_storage.hpp" namespace efesx { - //using namespace detail; +namespace queue { -class queue { +template +class basic_queue { private: - using node_t = detail::node; - - std::list pool; + Storage storage; public: - queue() = default; - queue(const queue&) = delete; - queue(const queue&&) = delete; - - template - void enqueue(const T& element, u_int8_t priority = 0){ - pool.emplace_back(element, priority); - if(priority > 0){ - pool.sort(); - } - } - - template - void enqueue(T* element, std::size_t size, u_int8_t priority = 0){ - pool.emplace_back(element, size, priority); - if(priority > 0){ - pool.sort(); - } - } - - template - void dequeue(T& element){ - pool.front().restore(element); - pool.pop_front(); - } - - template - void dequeue(T* element){ - pool.front().restore(element); - pool.pop_front(); - } }; +using queue = basic_queue; + + +}; // namespace queue }; // namespace efesx \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 41354bd..5980ae7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,28 +1,43 @@ -include(FetchContent) +find_package(GTest CONFIG) -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 -) +if(NOT ${GTest_FOUND}) + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0 + ) + FetchContent_MakeAvailable(googletest) + + include(GoogleTest) -FetchContent_MakeAvailable(googletest) + set(GTEST_LINK gtest gtest_main) + +else() + + set(GTEST_LINK GTest::gtest GTest::gtest_main) + +endif() -include(GoogleTest) add_executable(node_test node_test.cc) target_include_directories(node_test PUBLIC ../include) -target_link_libraries(node_test gtest gtest_main) +target_link_libraries(node_test ${GTEST_LINK}) add_executable(queue_test queue_test.cc) target_include_directories(queue_test PUBLIC ../include) -target_link_libraries(queue_test gtest gtest_main) +target_link_libraries(queue_test ${GTEST_LINK}) add_executable(meta_test meta_test.cc) target_include_directories(meta_test PUBLIC ../include) -target_link_libraries(meta_test gtest gtest_main) +target_link_libraries(meta_test ${GTEST_LINK}) + +add_executable(list_storage_test list_storage_test.cc) +target_include_directories(list_storage_test PUBLIC ../include) +target_link_libraries(list_storage_test ${GTEST_LINK}) enable_testing() add_test(meta_test meta_test) add_test(node_test node_test) add_test(queue_test queue_test) +add_test(list_storage_test list_storage_test) diff --git a/tests/list_storage_test.cc b/tests/list_storage_test.cc new file mode 100644 index 0000000..6b90ca7 --- /dev/null +++ b/tests/list_storage_test.cc @@ -0,0 +1,46 @@ +#include "gtest/gtest.h" + +#include +#include + +#include "detail/list_storage.hpp" + +using namespace efesx::queue::detail; + +TEST(list_storage_test, basic_test) +{ + list_storage ls; + unsigned int arr[2] = { 0x12345678, 0xdeadcafe }; + ls.insert(100500); + ls.insert("one", sizeof("one")); + ls.insert(std::string("two")); + ls.insert(2.3); + ls.insert(arr, 8); + + EXPECT_EQ(ls.extract().value_or(-1), 100500); + + EXPECT_EQ(ls.extract().value_or(-1.0), -1.0); + + ls.pop(); + EXPECT_EQ(ls.extract().value_or("-1"), std::string("one", sizeof("one"))); + ls.pop(); + EXPECT_EQ(ls.extract().value_or("-1"), std::string("two")); + ls.pop(); + EXPECT_TRUE((ls.extract().value_or(-1.0) > 2.25) && (ls.extract().value_or(-1.0) < 2.35)); + ls.pop(); + int res[2]; + ls.extract(res); + EXPECT_EQ(arr[0], res[0]); + EXPECT_EQ(arr[1], res[1]); + ls.pop(); + + EXPECT_EQ(ls.extract().value_or(-1), -1); +} + +TEST(list_storage_test, extract_types_test) +{ +} + +TEST(list_storage_test, extract_priority_test) +{ +} diff --git a/tests/meta_test.cc b/tests/meta_test.cc index 2200b79..715c4cb 100644 --- a/tests/meta_test.cc +++ b/tests/meta_test.cc @@ -2,55 +2,97 @@ #include "detail/meta.hpp" -#include -#include -#include -#include -#include -#include -#include - using namespace efesx::queue::detail; -template -bool test(T) requires (Container) { - return true; -} -template -bool test(T) requires (!Container) { - return false; +TEST(meta_test, is_integral_concept_test) +{ + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + EXPECT_TRUE(IsIntegral); + + EXPECT_FALSE(IsIntegral); + EXPECT_FALSE(IsIntegral); + EXPECT_FALSE(IsIntegral); + EXPECT_FALSE(IsIntegral); + + EXPECT_FALSE(IsIntegral); + EXPECT_FALSE(IsIntegral); + + EXPECT_FALSE(IsIntegral); + EXPECT_FALSE(IsIntegral); + + EXPECT_FALSE(IsIntegral); + EXPECT_FALSE(IsIntegral); + EXPECT_FALSE(IsIntegral); } -TEST(meta_test, detector_test) +TEST(meta_test, is_floating_concept_test) { - ASSERT_TRUE(detector::type == value_t::int_t); - ASSERT_TRUE(detector::type == value_t::bool_t); - ASSERT_TRUE(detector::type == value_t::string_t); - ASSERT_TRUE(detector::type == value_t::char_t); - - ASSERT_TRUE(detector::type == value_t::null_t); - ASSERT_TRUE(detector::type == value_t::null_t); - ASSERT_TRUE(detector::type == value_t::null_t); - ASSERT_TRUE(detector::type == value_t::null_t); - - ASSERT_TRUE(detector::type == value_t::null_t); - ASSERT_TRUE(detector::type == value_t::null_t); - ASSERT_TRUE(detector::type == value_t::null_t); - ASSERT_TRUE(detector::type == value_t::null_t); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + + EXPECT_TRUE(IsFloating); + EXPECT_TRUE(IsFloating); + + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); + EXPECT_FALSE(IsFloating); } -TEST(meta_test, container_test) +TEST(meta_test, is_string_concept_test) { - ASSERT_TRUE(test(std::vector{})); - ASSERT_TRUE(test(std::vector>{})); - ASSERT_TRUE(test(std::list{})); - ASSERT_TRUE(test(std::set{})); - ASSERT_TRUE(test(std::unordered_set{})); - ASSERT_TRUE(test(std::map{})); - ASSERT_TRUE(test(std::unordered_map{})); - - ASSERT_FALSE(test(int{})); - ASSERT_FALSE(test(char{})); - ASSERT_FALSE(test(bool{})); - ASSERT_FALSE(test(std::string{})); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + + EXPECT_FALSE(IsString); + EXPECT_FALSE(IsString); + + EXPECT_TRUE(IsString); + EXPECT_TRUE(IsString); + EXPECT_FALSE(IsString); } diff --git a/tests/node_test.cc b/tests/node_test.cc index 88e47f8..315f4d8 100644 --- a/tests/node_test.cc +++ b/tests/node_test.cc @@ -1,12 +1,6 @@ #include "gtest/gtest.h" #include -#include -#include -#include -#include -#include -#include #include "detail/node.hpp" @@ -15,70 +9,87 @@ using namespace efesx::queue::detail; TEST(simple_test, node_test_1) { { - int val; - node(5).restore(val); - ASSERT_TRUE(val == 5); + node n; + ASSERT_TRUE(n.size() == 0); + ASSERT_TRUE(n.has_value() == false); + ASSERT_TRUE(n.value_type() == value_t::null); } { - int val = 9; - int res[1]; - node(&val, 1).restore(res); - ASSERT_TRUE(res[0] == 9); + node n(54); + ASSERT_TRUE(n.size() == 4); + ASSERT_TRUE(n.has_value() == true); + ASSERT_TRUE(n.value_type() == value_t::integer); + ASSERT_TRUE(n.value_cast() == 54); } { - bool val; - node(true).restore(val); - ASSERT_TRUE(val == true); + node n(0x01234567); + ASSERT_TRUE(n.size() == 4); + ASSERT_TRUE(n.has_value() == true); + ASSERT_TRUE(n.value_type() == value_t::integer); + ASSERT_TRUE(n.value_cast() == 0x67); } { - char val; - node('\n').restore(val); - ASSERT_TRUE(val == '\n'); + node n(double{6.55}); + ASSERT_TRUE(n.size() == 8); + ASSERT_TRUE(n.has_value() == true); + ASSERT_TRUE(n.value_type() == value_t::floating); + ASSERT_TRUE((n.value_cast() > 6.50) && (n.value_cast() < 6.60)); } { - std::string val; - node(std::string("te\rst\n\0")).restore(val); - ASSERT_TRUE(val == "te\rst\n\0"); - } - { // test doesn't work on CI (WTF????) - // std::string val = "test"; - // void* res = std::malloc(val.size()); - // node(val.c_str(), val.size()).restore((char*)res); - // ASSERT_TRUE(std::string((char*)res) == val); + node n(float{6.55}); + ASSERT_TRUE(n.size() == 4); + ASSERT_TRUE(n.has_value() == true); + ASSERT_TRUE(n.value_type() == value_t::floating); + ASSERT_TRUE((n.value_cast() > 6.50) && (n.value_cast() < 6.60)); } { - - char* val = (char*)std::malloc(sizeof("test")); - node("test", sizeof("test")).restore(val); - ASSERT_TRUE(std::string(val) == "test"); + node n(std::string{"test"}); + EXPECT_EQ(n.size(), 4); + ASSERT_TRUE(n.has_value() == true); + ASSERT_TRUE(n.value_type() == value_t::text); + ASSERT_TRUE(n.value_cast() == "test"); } { - int arr[3] = {1, 2, 3}; - int res[3]; - node(arr, 3).restore(res); - ASSERT_TRUE(arr[0] == res[0]); - ASSERT_TRUE(arr[1] == res[1]); - ASSERT_TRUE(arr[2] == res[2]); - } - { // @todo node must keep another nodes - // kinda: node(node(node(5))); + node n("test", sizeof("test")); + EXPECT_EQ(n.size(), 5); + ASSERT_TRUE(n.has_value() == true); + ASSERT_TRUE(n.value_type() == value_t::text); + EXPECT_EQ(std::string("test", sizeof("test")), n.value_cast()); } { - node(std::vector{1, 2, 3}); + try { + node n(666); + EXPECT_EQ(4, n.size()); + EXPECT_EQ(true, n.has_value()); + EXPECT_EQ(value_t::integer, n.value_type()); + std::string val = n.value_cast(); + } catch (std::runtime_error& e){ + EXPECT_STREQ("Bad Node Value Cast", e.what()); + } } { - node(std::list{1, 2, 3}); + try { + node n; + EXPECT_EQ(n.size(), 0); + EXPECT_EQ(false, n.has_value()); + EXPECT_EQ(value_t::null, n.value_type()); + int val = n.value_cast(); + } catch (std::runtime_error& e){ + EXPECT_STREQ("Node Value Is Empty", e.what()); + } } { - node(std::set{1, 2, 3}); - } - { - node(std::unordered_set{1, 2, 3}); - } - { - //node(std::map{{1, 2}}); - } - { - //node(std::unordered_map{{1, 2}, {3, 4}, {5, 6}}); + int arr[3] = {0, 1, 2}; + node n(arr, 12); + EXPECT_EQ(12, n.size()); + EXPECT_EQ(true, n.has_value()); + EXPECT_EQ(value_t::blob, n.value_type()); + int* res = (int*)std::malloc(sizeof(int) * n.size()); + n.blob_copy(res); + EXPECT_EQ(arr[0], res[0]); + EXPECT_EQ(arr[1], res[1]); + EXPECT_EQ(arr[2], res[2]); + std::free(res); } + } diff --git a/tests/queue_test.cc b/tests/queue_test.cc index 1606362..7a9077b 100644 --- a/tests/queue_test.cc +++ b/tests/queue_test.cc @@ -3,83 +3,11 @@ #include #include -//#include "queue.hpp" +#include "queue.hpp" -//using namespace efesx; +using namespace efesx::queue; -TEST(queue_test, types_test) +TEST(queue_test, simple_test) { - /* - struct test_t { - int a; - bool b; - float c; - }; - - int arr[3] = {8, 7, 6}; - queue q; - q.enqueue(8, 0); - q.enqueue(9, 0); - q.enqueue(std::string{"string"}, 0); - q.enqueue(53.5, 0); - q.enqueue(true, 0); - q.enqueue(test_t{3, 1, 2}, 0); - q.enqueue(arr, 3, 0); - - int i; - std::string s; - double f; - bool b; - test_t st; - int a[3]; - - q.dequeue(i); ASSERT_EQ(i, 8); - q.dequeue(i); ASSERT_EQ(i, 9); - q.dequeue(s); ASSERT_EQ(s, "string"); - q.dequeue(f); EXPECT_TRUE((f < 53.55) && (f > 53.45)); - q.dequeue(b); EXPECT_TRUE(b); - q.dequeue(st); - ASSERT_EQ(st.a, 3); - ASSERT_EQ(st.b, 1); - ASSERT_EQ(st.c, 2); - q.dequeue(a); - ASSERT_EQ(a[0], 8); - ASSERT_EQ(a[1], 7); - ASSERT_EQ(a[2], 6); - */ -} - -TEST(queue_test, priority_test){ - /* - queue q; - - q.enqueue(0, 0); - q.enqueue(1, 0); - q.enqueue(3, 5); - q.enqueue(4, 3); - q.enqueue(5, 125); - q.enqueue(6, 254); - q.enqueue(7, 254); - q.enqueue(8, 254); - q.enqueue(9, 255); - q.enqueue(10, 255); - q.enqueue(11, 255); - q.enqueue(12, 0); - - int val; - q.dequeue(val); ASSERT_EQ(val, 9); - q.dequeue(val); ASSERT_EQ(val, 10); - q.dequeue(val); ASSERT_EQ(val, 11); - q.dequeue(val); ASSERT_EQ(val, 6); - q.dequeue(val); ASSERT_EQ(val, 7); - q.dequeue(val); ASSERT_EQ(val, 8); - q.dequeue(val); ASSERT_EQ(val, 5); - q.dequeue(val); ASSERT_EQ(val, 3); - q.dequeue(val); ASSERT_EQ(val, 4); - q.dequeue(val); ASSERT_EQ(val, 0); - q.dequeue(val); ASSERT_EQ(val, 1); - q.dequeue(val); ASSERT_EQ(val, 12); - */ - }