added test for emplace()

This commit is contained in:
Patrick 2024-07-29 16:53:46 +02:00
parent 6ebec36b2d
commit cfb82ca1fe
1 changed files with 54 additions and 0 deletions

View File

@ -215,6 +215,60 @@ constexpr test_suite tests = define_tests("Data Augmentation")
return TEST_PASS();
}), 2, int, char, const char *, TestObj);
return TEST_PASS();
}, EvalFlag::RUNTIME_CONSTEVAL)
("const_vector::emplace(const_iterator pos, Args &&... args)", []() constexpr {
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() constexpr {
cc::const_vector<T, c_arr_len(get_test_param<ctx, "arr">()) + 3> v(get_test_param<ctx, "arr">());
auto value = make_copy(get_test_param<ctx, "value">());
auto value_comp = make_copy(get_test_param<ctx, "value">());
typename decltype(v)::iterator it;
if constexpr(!std::is_same_v<T, TestObj>) {
it = v.emplace(std::next(v.begin()), get_test_param<ctx, "arr">()[0]);
} else {
auto obj = get_test_param<ctx, "arr">()[0];
it = v.emplace(std::next(v.begin()), obj.x, obj.c, obj.s);
}
v.emplace(it, force_move(value));
if constexpr (!std::is_same_v<T, const char*>) {
v.emplace(v.end(), T());
} else {
v.emplace(v.end(), "");
}
ASSERT_THROWS((v.emplace(v.end(), T())), std::length_error, ctx);
std::vector<T> comparable;
std::ranges::copy(get_test_param<ctx, "arr">(), std::back_inserter(comparable));
typename decltype(comparable)::iterator cit;
if constexpr(!std::is_same_v<T, TestObj>) {
cit = comparable.emplace(std::next(comparable.begin()), get_test_param<ctx, "arr">()[0]);
} else {
auto obj = get_test_param<ctx, "arr">()[0];
cit = comparable.emplace(std::next(comparable.begin()), obj.x, obj.c, obj.s);
}
comparable.emplace(cit, force_move(value_comp));
if constexpr (!std::is_same_v<T, const char *>) {
comparable.emplace(comparable.end(), T());
} else {
comparable.emplace(comparable.end(), "");
}
ASSERT(ranges_equal(v, comparable), ctx);
return TEST_PASS();
}), 2, int, char, const char *, TestObj);
return TEST_PASS();
}, EvalFlag::RUNTIME_CONSTEVAL);