Compare commits
No commits in common. "fce50dc9b01b235300e1a5eed421efcdfdb95b69" and "b10b6049c8decdca2ac8423e76c56508a6582783" have entirely different histories.
fce50dc9b0
...
b10b6049c8
|
|
@ -17,32 +17,18 @@
|
||||||
#define _EXPAND_MACRO(s) _EXPAND_STR(s)
|
#define _EXPAND_MACRO(s) _EXPAND_STR(s)
|
||||||
#define _LOCATION " (at " _EXPAND_MACRO(__FILE__) ":" _EXPAND_MACRO(__LINE__) ")"
|
#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_FAIL(msg) ret_val_s { "", ReturnCode::FAILED, msg }
|
||||||
#define TEST_PASS() ret_val_s { "", ReturnCode::PASSED, nullptr }
|
#define TEST_PASS() ret_val_s { "", ReturnCode::PASSED, nullptr }
|
||||||
#define TEST_PASS_MSG(msg) ret_val_s { "", ReturnCode::PASSED, msg }
|
#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 TEST_FAIL_TYPE(msg, type_hint) ret_val_s { "", ReturnCode::FAILED, msg, to_type_hint_str::value<type_hint> }
|
#define ASSERT(condition) ASSERT_MSG(condition, #condition "" _LOCATION)
|
||||||
#define TEST_PASS_TYPE(type_hint) ret_val_s { "", ReturnCode::PASSED, nullptr, to_type_hint_str::value<type_hint> }
|
#define ASSERT_MSG(condition, msg) { if (!(condition)) return TEST_FAIL(msg); } static_assert(true, "")
|
||||||
#define TEST_PASS_MSG_TYPE(msg, type_hint) ret_val_s { "", ReturnCode::PASSED, msg, to_type_hint_str::value<type_hint> }
|
#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 TEST_SKIP_TYPE(type_hint) ret_val_s { "", ReturnCode::SKIPPED, nullptr, to_type_hint_str::value<type_hint> }
|
#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 ASSERT_TYPE(condition, type) ASSERT_TYPE_MSG(condition, #condition "" _LOCATION, type)
|
#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_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>
|
template<typename T>
|
||||||
constexpr auto all_eq_arr_elem_test_func(T&& eq) {
|
constexpr auto all_eq_arr_elem_test_func(T&& eq) {
|
||||||
|
|
@ -66,18 +52,6 @@ enum class EvalFlag { RUNTIME, CONSTEVAL, RUNTIME_CONSTEVAL };
|
||||||
enum class ReturnCode { FAILED = -1, PASSED = 0, SKIPPED = 1, NOT_EVALUATED = 2 };
|
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>
|
template<typename Suite>
|
||||||
struct quick_test_def;
|
struct quick_test_def;
|
||||||
|
|
||||||
|
|
@ -88,7 +62,6 @@ struct ret_val_s {
|
||||||
const char *test_name = "";
|
const char *test_name = "";
|
||||||
ReturnCode val = ReturnCode::FAILED;
|
ReturnCode val = ReturnCode::FAILED;
|
||||||
const char *msg = "";
|
const char *msg = "";
|
||||||
const char *type_hint = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<std::size_t Nr>
|
template<std::size_t Nr>
|
||||||
|
|
@ -180,9 +153,6 @@ class test_suite {
|
||||||
if (ret.msg != nullptr) {
|
if (ret.msg != nullptr) {
|
||||||
std::cout << "\n\t" << ret.msg;
|
std::cout << "\n\t" << ret.msg;
|
||||||
}
|
}
|
||||||
if (ret.type_hint != nullptr) {
|
|
||||||
std::cout << "\n\t" << "with type '" << ret.type_hint << "'";
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
ret_vals[i][0] = ret.val;
|
ret_vals[i][0] = ret.val;
|
||||||
|
|
@ -194,9 +164,6 @@ class test_suite {
|
||||||
if (ret.msg != nullptr) {
|
if (ret.msg != nullptr) {
|
||||||
std::cout << "\n\t" << ret.msg;
|
std::cout << "\n\t" << ret.msg;
|
||||||
}
|
}
|
||||||
if (ret.type_hint != nullptr) {
|
|
||||||
std::cout << "\n\t" << "with type '" << ret.type_hint << "'";
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
ret_vals[i][1] = ret.val;
|
ret_vals[i][1] = ret.val;
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,11 @@
|
||||||
|
|
||||||
#include "test_args.h"
|
#include "test_args.h"
|
||||||
|
|
||||||
#define ASSERT_TYPE_ALL_VEC_EQ(vec, eq, type) ASSERT_ALL_EQ((vec).begin(), (vec).end(), eq)
|
#define ASSERT_ALL_VEC_EQ(vec, eq) 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_RANGE_VEC_EQ(vec, startI, endI, eq) 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_VEC_ARR_EQ(vec, eq) 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_VEC_EQ(vec1, vec2) 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_RANGE_VEC_ARR_EQ(vec, startI, endI, eq) 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")
|
constexpr test_suite tests = define_tests("Tests")
|
||||||
("const_vector()", []() constexpr {
|
("const_vector()", []() constexpr {
|
||||||
|
|
@ -644,7 +638,6 @@ constexpr test_suite tests = define_tests("Tests")
|
||||||
|
|
||||||
return TEST_PASS();
|
return TEST_PASS();
|
||||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||||
|
|
||||||
("const_vector::operator=(const const_vector& other)", []() constexpr {
|
("const_vector::operator=(const const_vector& other)", []() constexpr {
|
||||||
|
|
||||||
cc::const_vector vi1(test_defs::get<int>::arr<1>);
|
cc::const_vector vi1(test_defs::get<int>::arr<1>);
|
||||||
|
|
@ -1117,40 +1110,11 @@ constexpr test_suite tests = define_tests("Tests")
|
||||||
|
|
||||||
return TEST_PASS();
|
return TEST_PASS();
|
||||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
}, 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 {
|
/*("const_vector(const_vector&& other)", []() constexpr {
|
||||||
|
|
||||||
return TEST_PASS();
|
return TEST_PASS();
|
||||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
}, EvalFlag::RUNTIME_CONSTEVAL)*/
|
||||||
*/;
|
;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
return tests.run();
|
return tests.run();
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
#include <test.hpp>
|
|
||||||
|
|
||||||
#define C_ARR_LEN(arr) (sizeof(arr)/sizeof(arr[0]))
|
#define C_ARR_LEN(arr) (sizeof(arr)/sizeof(arr[0]))
|
||||||
|
|
||||||
struct TestStruct {
|
struct TestStruct {
|
||||||
|
|
@ -15,7 +13,6 @@ struct TestStruct {
|
||||||
|
|
||||||
constexpr bool operator==(const TestStruct &other) const { return x == other.x && c == other.c && std::string_view(s) == other.s; }
|
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 {
|
struct test_defs {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue