From cfb82ca1fe2d26eecf0313e12199711366119f09 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 29 Jul 2024 16:53:46 +0200 Subject: [PATCH] added test for emplace() --- .../const_vector_data_augmentation.test.cpp | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/const_vector/const_vector_data_augmentation.test.cpp b/test/const_vector/const_vector_data_augmentation.test.cpp index 6bd4a39..dbeb420 100644 --- a/test/const_vector/const_vector_data_augmentation.test.cpp +++ b/test/const_vector/const_vector_data_augmentation.test.cpp @@ -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(([]() constexpr { + + cc::const_vector()) + 3> v(get_test_param()); + + auto value = make_copy(get_test_param()); + auto value_comp = make_copy(get_test_param()); + + typename decltype(v)::iterator it; + if constexpr(!std::is_same_v) { + it = v.emplace(std::next(v.begin()), get_test_param()[0]); + } else { + auto obj = get_test_param()[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) { + v.emplace(v.end(), T()); + } else { + v.emplace(v.end(), ""); + } + + ASSERT_THROWS((v.emplace(v.end(), T())), std::length_error, ctx); + + std::vector comparable; + std::ranges::copy(get_test_param(), std::back_inserter(comparable)); + + typename decltype(comparable)::iterator cit; + if constexpr(!std::is_same_v) { + cit = comparable.emplace(std::next(comparable.begin()), get_test_param()[0]); + } else { + auto obj = get_test_param()[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) { + 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);