diff --git a/test/common_helper/test.hpp b/test/common_helper/test.hpp index 8e0a323..dac4f70 100644 --- a/test/common_helper/test.hpp +++ b/test/common_helper/test.hpp @@ -124,6 +124,16 @@ struct quick_test_def; inline std::ostream& operator<<(std::ostream& os, ReturnCode rc); +template +struct tstring { + char value[N]; + + constexpr tstring(const char (&str)[N]) { std::copy_n(str, N, value); } + + constexpr operator const char *() { return value; } +}; + + struct ret_val_s { const char *test_name = ""; ReturnCode val = ReturnCode::FAILED; @@ -143,6 +153,26 @@ struct ret_val { constexpr inline const ret_val_s& operator[](std::size_t i) const { return vals[i]; } }; +struct empty_param {}; + +struct test_params { + template + constexpr static auto value = empty_param{}; +}; + +template +struct test_context_params { + using type = T; + constexpr static std::size_t nr = Nr; + + template + constexpr static auto value = empty_param{}; +}; + +#define CONTEXT_PARAM(type, name, ...) template<> template<> constexpr type test_context_params<__VA_ARGS__>::value< #name > +#define CONTEXT_PARAM_ARR(type, name, ...) template<> template<> constexpr type test_context_params<__VA_ARGS__>::value< #name >[] + + class test_definition { public: [[nodiscard]] virtual constexpr ret_val_s evaluate() const = 0; @@ -366,7 +396,7 @@ template constexpr auto _repeat_for_types_n(auto f) { std::array rets = { [&](std::index_sequence) constexpr { - return std::array { f.template operator()()... }; + return std::array { f.template operator()>()... }; }.template operator()(std::make_index_sequence())... }; // Clion does not accept this as a constant expression diff --git a/test/const_vector/CMakeLists.txt b/test/const_vector/CMakeLists.txt index 67ab7c5..4798ffb 100644 --- a/test/const_vector/CMakeLists.txt +++ b/test/const_vector/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.26) set(CMAKE_CXX_STANDARD 23) add_executable(test_const_vector_constructor const_vector_constructor.test.cpp - test_args.h) + test_args.h + test_params.h) target_link_libraries(test_const_vector_constructor const_container test_common) add_test(NAME "const_vector constructor" COMMAND test_const_vector_constructor) diff --git a/test/const_vector/const_vector_constructor.test.cpp b/test/const_vector/const_vector_constructor.test.cpp index 268ec99..afa988e 100644 --- a/test/const_vector/const_vector_constructor.test.cpp +++ b/test/const_vector/const_vector_constructor.test.cpp @@ -3,6 +3,7 @@ #include #include "test.hpp" +#include "test_params.h" #include "test_args.h" #include @@ -1156,8 +1157,8 @@ constexpr test_suite tests = define_tests("Tests") }, EvalFlag::RUNTIME_CONSTEVAL) ("const_vector::assign(InputIt first, InputIt last)", []() constexpr { - REPEAT_FOR_TYPES_N(([]() constexpr { - + REPEAT_FOR_TYPES_N(([]() constexpr { + constexpr std::size_t N = n+1; cc::const_vector::template arr_len()> v1; cc::const_vector::template il_len()> v2; cc::const_vector::template il_len()> v3; @@ -1187,23 +1188,29 @@ constexpr test_suite tests = define_tests("Tests") }, EvalFlag::RUNTIME_CONSTEVAL) ("const_vector::assign(std::initializer_list values)", []() constexpr { - REPEAT_FOR_TYPES_N(([]() constexpr { + REPEAT_FOR_TYPES_N(([]() constexpr { - cc::const_vector::template il_len()> v1; - cc::const_vector::template il_len() - 1> v2; + cc::const_vector).size()> v1; + cc::const_vector).size() - 1> v2; - v1.assign(test_defs::get::template i_list); + v1.assign(params::template value<"ilist">); - ASSERT_TYPE_NUM_VEC_ARR_EQ(v1, test_defs::get::template i_list, T, N); - ASSERT_TYPE_NUM(v1.size() == test_defs::get::template il_len(), T, N); + ASSERT_TYPE_NUM_VEC_ARR_EQ(v1, params::template value<"ilist">, T, N); + ASSERT_TYPE_NUM(v1.size() == params::template value<"ilist">.size(), T, N); - ASSERT_TYPE_NUM_THROWS(v2.assign(test_defs::get::template i_list), std::invalid_argument, T, N); + ASSERT_TYPE_NUM_THROWS(v2.assign(params::template value<"ilist">), std::invalid_argument, T, N); return TEST_PASS(); - }), 2, int, char, const char *, TestStruct); + }), 2, int, char, const char *, TestObj); return TEST_PASS(); }, EvalFlag::RUNTIME_CONSTEVAL) + + ("const_vector::at(size_type pos)", []() constexpr { + + return TEST_PASS(); + }, EvalFlag::RUNTIME_CONSTEVAL) + /*("const_vector", []() constexpr { diff --git a/test/const_vector/test_params.h b/test/const_vector/test_params.h new file mode 100644 index 0000000..a9ede5c --- /dev/null +++ b/test/const_vector/test_params.h @@ -0,0 +1,86 @@ +#ifndef CONST_CONTAINER_TEST_ARGS_H +#define CONST_CONTAINER_TEST_ARGS_H + +#include "test.hpp" + +#define GEN_TEST_OBJ_FROM_ARR(nr, i) TestObj(test_context_params::value<"arr">[i], test_context_params::value<"arr">[i], test_context_params::value<"arr">[i]) + +struct TestObj { + int x = 0; + char c = 0; + const char * s = "This is a string"; + + constexpr bool operator==(const TestObj &other) const { return x == other.x && c == other.c && std::string_view(s) == other.s; } +}; +ADD_TYPE_HINT(TestObj); + +template<> template<> constexpr int test_context_params::value<"arr">[] = { 1, 2, 3, 4 }; +template<> template<> constexpr int test_context_params::value<"arr">[] = { 5, 6, 7, 8, 9, 10, 11, 12 }; +template<> template<> constexpr char test_context_params::value<"arr">[] = { 'a', 'B', 'c', 'D' }; +template<> template<> constexpr char test_context_params::value<"arr">[] = { 'e', 'F', 'g', 'H', 'i', 'J', '\n', '\0' }; +template<> template<> constexpr const char * test_context_params::value<"arr">[] = { "Lorem", "ipsum", "dolor", "sit" }; +template<> template<> constexpr const char * test_context_params::value<"arr">[] = { "amet", "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod", "tempor", "\0" }; +template<> template<> constexpr TestObj test_context_params::value<"arr">[] = { + GEN_TEST_OBJ_FROM_ARR(0, 0), + GEN_TEST_OBJ_FROM_ARR(0, 1), + GEN_TEST_OBJ_FROM_ARR(0, 2), + GEN_TEST_OBJ_FROM_ARR(0, 3) }; +template<> template<> constexpr TestObj test_context_params::value<"arr">[] = { + GEN_TEST_OBJ_FROM_ARR(1, 0), + GEN_TEST_OBJ_FROM_ARR(1, 1), + GEN_TEST_OBJ_FROM_ARR(1, 2), + GEN_TEST_OBJ_FROM_ARR(1, 3), + GEN_TEST_OBJ_FROM_ARR(1, 4), + GEN_TEST_OBJ_FROM_ARR(1, 5), + GEN_TEST_OBJ_FROM_ARR(1, 6), + GEN_TEST_OBJ_FROM_ARR(1, 7) }; + +template<> template<> constexpr std::initializer_list test_context_params::value<"ilist"> = { 1, 2, 3, 4 }; +template<> template<> constexpr std::initializer_list test_context_params::value<"ilist"> = { 5, 6, 7, 8, 9, 10, 11, 12 }; +template<> template<> constexpr std::initializer_list test_context_params::value<"ilist"> = { 'a', 'B', 'c', 'D' }; +template<> template<> constexpr std::initializer_list test_context_params::value<"ilist"> = { 'e', 'F', 'g', 'H', 'i', 'J', '\n', '\0' }; +template<> template<> constexpr std::initializer_list test_context_params::value<"ilist"> = { "Lorem", "ipsum", "dolor", "sit" }; +template<> template<> constexpr std::initializer_list test_context_params::value<"ilist"> = { "amet", "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod", "tempor", "\0" }; +template<> template<> constexpr std::initializer_list test_context_params::value<"ilist"> = { + GEN_TEST_OBJ_FROM_ARR(0, 0), + GEN_TEST_OBJ_FROM_ARR(0, 1), + GEN_TEST_OBJ_FROM_ARR(0, 2), + GEN_TEST_OBJ_FROM_ARR(0, 3) }; +template<> template<> constexpr std::initializer_list test_context_params::value<"ilist"> = { + GEN_TEST_OBJ_FROM_ARR(1, 0), + GEN_TEST_OBJ_FROM_ARR(1, 1), + GEN_TEST_OBJ_FROM_ARR(1, 2), + GEN_TEST_OBJ_FROM_ARR(1, 3), + GEN_TEST_OBJ_FROM_ARR(1, 4), + GEN_TEST_OBJ_FROM_ARR(1, 5), + GEN_TEST_OBJ_FROM_ARR(1, 6), + GEN_TEST_OBJ_FROM_ARR(1, 7) }; + +template<> template<> constexpr std::size_t test_context_params::value<"capacity"> = 10; +template<> template<> constexpr std::size_t test_context_params::value<"capacity"> = 10; +template<> template<> constexpr std::size_t test_context_params::value<"capacity"> = 10; +template<> template<> constexpr std::size_t test_context_params::value<"capacity"> = 10; +template<> template<> constexpr std::size_t test_context_params::value<"capacity"> = 200; +template<> template<> constexpr std::size_t test_context_params::value<"capacity"> = 200; +template<> template<> constexpr std::size_t test_context_params::value<"capacity"> = 200; +template<> template<> constexpr std::size_t test_context_params::value<"capacity"> = 200; + +template<> template<> constexpr std::size_t test_context_params::value<"size"> = 25; +template<> template<> constexpr std::size_t test_context_params::value<"size"> = 25; +template<> template<> constexpr std::size_t test_context_params::value<"size"> = 25; +template<> template<> constexpr std::size_t test_context_params::value<"size"> = 25; +template<> template<> constexpr std::size_t test_context_params::value<"size"> = 50; +template<> template<> constexpr std::size_t test_context_params::value<"size"> = 50; +template<> template<> constexpr std::size_t test_context_params::value<"size"> = 50; +template<> template<> constexpr std::size_t test_context_params::value<"size"> = 50; + +template<> template<> constexpr int test_context_params::value<"value"> = 5; +template<> template<> constexpr int test_context_params::value<"value"> = INT_MIN; +template<> template<> constexpr char test_context_params::value<"value"> = 'P'; +template<> template<> constexpr char test_context_params::value<"value"> = CHAR_MAX; +template<> template<> constexpr const char * test_context_params::value<"value"> = "Test string 1"; +template<> template<> constexpr const char * test_context_params::value<"value"> = "Test string 2"; +template<> template<> constexpr TestObj test_context_params::value<"value"> = TestObj(5, 'P', "Object String 1"); +template<> template<> constexpr TestObj test_context_params::value<"value"> = TestObj(INT_MAX, 'p', "2 Object String"); + +#endif //CONST_CONTAINER_TEST_ARGS_H