Compare commits
2 Commits
b10b6049c8
...
fce50dc9b0
| Author | SHA1 | Date |
|---|---|---|
|
|
fce50dc9b0 | |
|
|
856c76375e |
|
|
@ -17,18 +17,32 @@
|
|||
#define _EXPAND_MACRO(s) _EXPAND_STR(s)
|
||||
#define _LOCATION " (at " _EXPAND_MACRO(__FILE__) ":" _EXPAND_MACRO(__LINE__) ")"
|
||||
|
||||
#define ADD_TYPE_HINT(type) template <> constexpr const char* const to_type_hint_str::value<type> = #type
|
||||
|
||||
#define TEST_FAIL(msg) ret_val_s { "", ReturnCode::FAILED, msg }
|
||||
#define TEST_PASS() ret_val_s { "", ReturnCode::PASSED, nullptr }
|
||||
#define TEST_PASS_MSG(msg) ret_val_s { "", ReturnCode::PASSED, msg }
|
||||
#define TEST_SKIP() ret_val_s { "", ReturnCode::SKIPPED, nullptr }
|
||||
#define TEST_SKIP() ret_val_s { "", ReturnCode::SKIPPED, nullptr}
|
||||
|
||||
#define ASSERT(condition) ASSERT_MSG(condition, #condition "" _LOCATION)
|
||||
#define ASSERT_MSG(condition, msg) { if (!(condition)) return TEST_FAIL(msg); } static_assert(true, "")
|
||||
#define ASSERT_ALL_EQ(first, last, eq) ASSERT_MSG(std::all_of(first, last, all_eq_arr_elem_test_func(eq)), "Not all elements in (" #first ", " #last ") equal " #eq "" _LOCATION)
|
||||
#define ASSERT_C_ARR_EQ(first, last, eq) ASSERT_MSG(std::equal(first, last, eq, all_eq_arr_arr_test_func<decltype(eq)>()), "Elements in (" #first ", " #last ") and " #eq " differ" _LOCATION)
|
||||
#define ASSERT_ITER_EQ(first, last, eq) ASSERT_MSG(std::equal(first, last, (eq).begin(), all_eq_arr_arr_test_func<std::iterator_traits<decltype(eq)::iterator>::value_type>()), "Elements in (" #first ", " #last ") and " #eq " differ" _LOCATION)
|
||||
#define TEST_FAIL_TYPE(msg, type_hint) ret_val_s { "", ReturnCode::FAILED, msg, to_type_hint_str::value<type_hint> }
|
||||
#define TEST_PASS_TYPE(type_hint) ret_val_s { "", ReturnCode::PASSED, nullptr, to_type_hint_str::value<type_hint> }
|
||||
#define TEST_PASS_MSG_TYPE(msg, type_hint) ret_val_s { "", ReturnCode::PASSED, msg, to_type_hint_str::value<type_hint> }
|
||||
#define TEST_SKIP_TYPE(type_hint) ret_val_s { "", ReturnCode::SKIPPED, nullptr, to_type_hint_str::value<type_hint> }
|
||||
|
||||
#define ASSERT_THROWS(operation, exception_type) if not consteval { try { operation; ASSERT_MSG(false, #operation " did not throw " #exception_type _LOCATION); } catch (exception_type &e) {} } static_assert(true, "")
|
||||
#define ASSERT_TYPE(condition, type) ASSERT_TYPE_MSG(condition, #condition "" _LOCATION, type)
|
||||
#define ASSERT_TYPE_MSG(condition, msg, type) { if (!(condition)) return TEST_FAIL_TYPE(msg, type); } static_assert(true, "")
|
||||
#define ASSERT_TYPE_ALL_EQ(first, last, eq, type) ASSERT_TYPE_MSG(std::all_of(first, last, all_eq_arr_elem_test_func(eq)), "Not all elements in (" #first ", " #last ") equal " #eq "" _LOCATION, type)
|
||||
#define ASSERT_TYPE_C_ARR_EQ(first, last, eq, type) ASSERT_TYPE_MSG(std::equal(first, last, eq, all_eq_arr_arr_test_func<decltype(eq)>()), "Elements in (" #first ", " #last ") and " #eq " differ" _LOCATION, type)
|
||||
#define ASSERT_TYPE_ITER_EQ(first, last, eq, type) ASSERT_TYPE_MSG(std::equal(first, last, (eq).begin(), all_eq_arr_arr_test_func<std::iterator_traits<decltype(eq)::iterator>::value_type>()), "Elements in (" #first ", " #last ") and " #eq " differ" _LOCATION, type)
|
||||
|
||||
#define ASSERT(condition) ASSERT_TYPE(condition, std::nullptr_t)
|
||||
#define ASSERT_MSG(condition, msg) ASSERT_TYPE_MSG(condition, msg, std::nullptr_t)
|
||||
#define ASSERT_ALL_EQ(first, last, eq) ASSERT_TYPE_ALL_EQ(first, last, eq, std::nullptr_t)
|
||||
#define ASSERT_C_ARR_EQ(first, last, eq) ASSERT_TYPE_C_ARR_EQ(first, last, eq, std::nullptr_t)
|
||||
#define ASSERT_ITER_EQ(first, last, eq) ASSERT_TYPE_ITER_EQ(first, last, eq, std::nullptr_t)
|
||||
|
||||
#define ASSERT_TYPE_THROWS(operation, exception_type, type) if not consteval { try { operation; ASSERT_TYPE_MSG(false, #operation " did not throw " #exception_type _LOCATION, type); } catch (exception_type &e) {} } static_assert(true, "")
|
||||
#define ASSERT_THROWS(operation, exception_type) ASSERT_TYPE_THROWS(operation, exception_type, std::nullptr_t)
|
||||
|
||||
template<typename T>
|
||||
constexpr auto all_eq_arr_elem_test_func(T&& eq) {
|
||||
|
|
@ -52,6 +66,18 @@ enum class EvalFlag { RUNTIME, CONSTEVAL, RUNTIME_CONSTEVAL };
|
|||
enum class ReturnCode { FAILED = -1, PASSED = 0, SKIPPED = 1, NOT_EVALUATED = 2 };
|
||||
|
||||
|
||||
struct to_type_hint_str {
|
||||
template<typename T>
|
||||
static constexpr const char *value = nullptr;
|
||||
};
|
||||
|
||||
ADD_TYPE_HINT(bool);
|
||||
ADD_TYPE_HINT(int);
|
||||
ADD_TYPE_HINT(char);
|
||||
ADD_TYPE_HINT(const char *);
|
||||
ADD_TYPE_HINT(float);
|
||||
ADD_TYPE_HINT(double);
|
||||
|
||||
template<typename Suite>
|
||||
struct quick_test_def;
|
||||
|
||||
|
|
@ -62,6 +88,7 @@ struct ret_val_s {
|
|||
const char *test_name = "";
|
||||
ReturnCode val = ReturnCode::FAILED;
|
||||
const char *msg = "";
|
||||
const char *type_hint = nullptr;
|
||||
};
|
||||
|
||||
template<std::size_t Nr>
|
||||
|
|
@ -153,6 +180,9 @@ class test_suite {
|
|||
if (ret.msg != nullptr) {
|
||||
std::cout << "\n\t" << ret.msg;
|
||||
}
|
||||
if (ret.type_hint != nullptr) {
|
||||
std::cout << "\n\t" << "with type '" << ret.type_hint << "'";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
ret_vals[i][0] = ret.val;
|
||||
|
|
@ -164,6 +194,9 @@ class test_suite {
|
|||
if (ret.msg != nullptr) {
|
||||
std::cout << "\n\t" << ret.msg;
|
||||
}
|
||||
if (ret.type_hint != nullptr) {
|
||||
std::cout << "\n\t" << "with type '" << ret.type_hint << "'";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
ret_vals[i][1] = ret.val;
|
||||
|
|
|
|||
|
|
@ -6,11 +6,17 @@
|
|||
|
||||
#include "test_args.h"
|
||||
|
||||
#define ASSERT_ALL_VEC_EQ(vec, eq) ASSERT_ALL_EQ((vec).begin(), (vec).end(), eq)
|
||||
#define ASSERT_RANGE_VEC_EQ(vec, startI, endI, eq) ASSERT_ALL_EQ(((vec).data() + startI), ((vec).data() + endI), eq)
|
||||
#define ASSERT_VEC_ARR_EQ(vec, eq) ASSERT_C_ARR_EQ((vec).data(), (vec).data() + (vec).size(), std::begin(eq))
|
||||
#define ASSERT_VEC_EQ(vec1, vec2) ASSERT_C_ARR_EQ((vec1).data(), (vec1).data() + (vec1).size(), (vec2).data())
|
||||
#define ASSERT_RANGE_VEC_ARR_EQ(vec, startI, endI, eq) ASSERT_C_ARR_EQ(((vec).begin() + startI), ((vec).begin() + endI), std::begin(eq))
|
||||
#define ASSERT_TYPE_ALL_VEC_EQ(vec, eq, type) ASSERT_ALL_EQ((vec).begin(), (vec).end(), eq)
|
||||
#define ASSERT_TYPE_RANGE_VEC_EQ(vec, startI, endI, eq, type) ASSERT_ALL_EQ(((vec).data() + startI), ((vec).data() + endI), eq)
|
||||
#define ASSERT_TYPE_VEC_ARR_EQ(vec, eq, type) ASSERT_C_ARR_EQ((vec).data(), (vec).data() + (vec).size(), std::begin(eq))
|
||||
#define ASSERT_TYPE_VEC_EQ(vec1, vec2, type) ASSERT_C_ARR_EQ((vec1).data(), (vec1).data() + (vec1).size(), (vec2).data())
|
||||
#define ASSERT_TYPE_RANGE_VEC_ARR_EQ(vec, startI, endI, eq, type) ASSERT_C_ARR_EQ(((vec).begin() + startI), ((vec).begin() + endI), std::begin(eq))
|
||||
|
||||
#define ASSERT_ALL_VEC_EQ(vec, eq) ASSERT_TYPE_ALL_VEC_EQ(vec, eq, std::nullptr_t)
|
||||
#define ASSERT_RANGE_VEC_EQ(vec, startI, endI, eq) ASSERT_TYPE_RANGE_VEC_EQ(vec, startI, endI, eq, std::nullptr_t)
|
||||
#define ASSERT_VEC_ARR_EQ(vec, eq) ASSERT_TYPE_VEC_ARR_EQ(vec, eq, std::nullptr_t)
|
||||
#define ASSERT_VEC_EQ(vec1, vec2) ASSERT_TYPE_VEC_EQ(vec1, vec2, std::nullptr_t)
|
||||
#define ASSERT_RANGE_VEC_ARR_EQ(vec, startI, endI, eq) ASSERT_TYPE_RANGE_VEC_ARR_EQ(vec, startI, endI, eq, std::nullptr_t)
|
||||
|
||||
constexpr test_suite tests = define_tests("Tests")
|
||||
("const_vector()", []() constexpr {
|
||||
|
|
@ -638,6 +644,7 @@ constexpr test_suite tests = define_tests("Tests")
|
|||
|
||||
return TEST_PASS();
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||
|
||||
("const_vector::operator=(const const_vector& other)", []() constexpr {
|
||||
|
||||
cc::const_vector vi1(test_defs::get<int>::arr<1>);
|
||||
|
|
@ -1110,11 +1117,40 @@ constexpr test_suite tests = define_tests("Tests")
|
|||
|
||||
return TEST_PASS();
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||
|
||||
("const_vector::assign(size_type count, const value_type& value)", []() constexpr {
|
||||
|
||||
REPEAT_FOR_TYPES(([]<typename T>() constexpr {
|
||||
|
||||
cc::const_vector v1(test_defs::get<T>::template arr<1>);
|
||||
cc::const_vector v2(test_defs::get<T>::template arr<2>);
|
||||
cc::const_vector<T, test_defs::get<T>::template capacity<1>()> v3;
|
||||
|
||||
auto count1 = test_defs::get<T>::template arr_len<1>() / 2;
|
||||
auto count2 = test_defs::get<T>::template arr_len<2>() / 2;
|
||||
|
||||
v1.assign(count1, test_defs::get<T>::template value<1>());
|
||||
v2.assign(count2, test_defs::get<T>::template value<2>());
|
||||
v3.assign(test_defs::get<T>::template capacity<1>() + 1, test_defs::get<T>::template value<1>());
|
||||
|
||||
ASSERT_TYPE(v1.size() == count1, T);
|
||||
ASSERT_TYPE(v2.size() == count2, T);
|
||||
ASSERT_TYPE_ALL_VEC_EQ(v1, test_defs::get<T>::template value<1>(), T);
|
||||
ASSERT_TYPE_ALL_VEC_EQ(v2, test_defs::get<T>::template value<2>(), T);
|
||||
|
||||
ASSERT_TYPE(v3.size() == test_defs::get<T>::template capacity<1>(), T);
|
||||
ASSERT_TYPE_ALL_VEC_EQ(v1, test_defs::get<T>::template value<1>(), T);
|
||||
|
||||
return TEST_PASS();
|
||||
}), int, char, const char*, TestStruct)
|
||||
|
||||
return TEST_PASS();
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||
/*("const_vector(const_vector&& other)", []() constexpr {
|
||||
|
||||
return TEST_PASS();
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL)*/
|
||||
;
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||
*/;
|
||||
|
||||
int main() {
|
||||
return tests.run();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <array>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#define C_ARR_LEN(arr) (sizeof(arr)/sizeof(arr[0]))
|
||||
|
||||
struct TestStruct {
|
||||
|
|
@ -13,6 +15,7 @@ struct TestStruct {
|
|||
|
||||
constexpr bool operator==(const TestStruct &other) const { return x == other.x && c == other.c && std::string_view(s) == other.s; }
|
||||
};
|
||||
ADD_TYPE_HINT(TestStruct);
|
||||
|
||||
struct test_defs {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue