finished tests for const_vector
This commit is contained in:
parent
32ae9a2d3d
commit
fd180efb6c
|
|
@ -1,58 +1,10 @@
|
|||
#include <const_vector.hpp>
|
||||
|
||||
#include <test.hpp>
|
||||
#include <vector>
|
||||
#include <format>
|
||||
#include "test_params.h"
|
||||
|
||||
#include <format>
|
||||
#include <ranges>
|
||||
#include <sstream>
|
||||
|
||||
template<std::ranges::range R, typename CharT>
|
||||
struct std::formatter<R, CharT> {
|
||||
template<typename ParseContext>
|
||||
constexpr ParseContext::iterator parse(ParseContext& ctx) {
|
||||
auto it = ctx.begin();
|
||||
while (it != ctx.end() && *it != '}')
|
||||
++it;
|
||||
return it;
|
||||
}
|
||||
template<typename FmtContext>
|
||||
constexpr FmtContext::iterator format(const R& range, FmtContext& ctx) const {
|
||||
std::ostringstream out;
|
||||
out << '[';
|
||||
|
||||
auto it = std::ranges::begin(range);
|
||||
for (; it != std::next(std::ranges::begin(range), std::ranges::size(range) - 1); ++it) {
|
||||
out << std::format("{}, ", *it);
|
||||
}
|
||||
out << std::format("{}]", *it);
|
||||
|
||||
return std::ranges::copy(std::move(out).str(), ctx.out()).out;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename CharT>
|
||||
struct std::formatter<TestObj, CharT> {
|
||||
template<typename ParseContext>
|
||||
constexpr ParseContext::iterator parse(ParseContext &ctx)
|
||||
{
|
||||
auto it = ctx.begin();
|
||||
while (it != ctx.end() && *it != '}')
|
||||
++it;
|
||||
return it;
|
||||
}
|
||||
|
||||
template<typename FmtContext>
|
||||
constexpr FmtContext::iterator format(const TestObj &obj, FmtContext &ctx) const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << '(' << obj.x << ", '" << obj.c << "', \"" << obj.s << "\")";
|
||||
|
||||
return std::ranges::copy(std::move(out).str(), ctx.out()).out;
|
||||
}
|
||||
};
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
constexpr test_suite tests = define_tests("Data Augmentation")
|
||||
("const_vector::clear()", []() constexpr {
|
||||
|
|
@ -295,6 +247,112 @@ 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::push_back()", []() constexpr {
|
||||
|
||||
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() constexpr {
|
||||
|
||||
auto value = make_copy(get_test_param<ctx, "value">());
|
||||
|
||||
cc::const_vector<T, 3> v;
|
||||
|
||||
if constexpr (!std::is_same_v<T, const char*>) {
|
||||
v.push_back(T());
|
||||
} else {
|
||||
v.push_back("");
|
||||
}
|
||||
v.push_back(value);
|
||||
v.push_back(force_move(value));
|
||||
|
||||
ASSERT_THROWS(v.push_back(get_test_param<ctx, "value">()), std::length_error, ctx);
|
||||
|
||||
if constexpr (!std::is_same_v<T, const char*>) {
|
||||
ASSERT(v[0] == T());
|
||||
} else {
|
||||
ASSERT(v[0] == std::string_view(""));
|
||||
}
|
||||
ASSERT((v[1] == get_test_param<ctx, "value">()), ctx);
|
||||
ASSERT((v[2] == get_test_param<ctx, "value">()), ctx);
|
||||
|
||||
ASSERT(v.size() == 3);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
||||
return TEST_PASS();
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||
("const_vector::emplace_back()", []() constexpr {
|
||||
|
||||
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() constexpr {
|
||||
|
||||
auto value = make_copy(get_test_param<ctx, "value">());
|
||||
|
||||
cc::const_vector<T, 3> v;
|
||||
|
||||
if constexpr (!std::is_same_v<T, const char*>) {
|
||||
ASSERT(&v.emplace_back(T()) == v.begin(), ctx);
|
||||
} else {
|
||||
ASSERT(&v.emplace_back("") == v.begin(), ctx);
|
||||
}
|
||||
if constexpr (!std::is_same_v<T, TestObj>) {
|
||||
ASSERT(&v.emplace_back(value) == std::next(v.begin()), ctx);
|
||||
} else {
|
||||
ASSERT(&v.emplace_back(value.x, value.c, value.s) == std::next(v.begin()), ctx);
|
||||
}
|
||||
ASSERT(&v.emplace_back(force_move(value)) == std::next(v.begin(), 2), ctx);
|
||||
|
||||
ASSERT_THROWS(v.emplace_back(get_test_param<ctx, "value">()), std::length_error, ctx);
|
||||
|
||||
if constexpr (!std::is_same_v<T, const char*>) {
|
||||
ASSERT(v[0] == T());
|
||||
} else {
|
||||
ASSERT(v[0] == std::string_view(""));
|
||||
}
|
||||
ASSERT((v[1] == get_test_param<ctx, "value">()), ctx);
|
||||
ASSERT((v[2] == get_test_param<ctx, "value">()), ctx);
|
||||
|
||||
ASSERT(v.size() == 3);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
||||
return TEST_PASS();
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||
("const_vector::pop_back()", []() constexpr {
|
||||
|
||||
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() constexpr {
|
||||
|
||||
cc::const_vector v(get_test_param<ctx, "arr">());
|
||||
|
||||
v.pop_back();
|
||||
|
||||
auto& arr = get_test_param<ctx, "arr">();
|
||||
ASSERT(std::ranges::equal(v, arr | std::ranges::views::take(c_arr_len(arr) - 1)), ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
||||
return TEST_PASS();
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||
|
||||
("const_vector::swap()", []() constexpr {
|
||||
|
||||
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() constexpr {
|
||||
|
||||
cc::const_vector va(get_test_param<ctx, "arr">());
|
||||
cc::const_vector<T, get_test_param<ctx, "capacity">()> vv(c_arr_len(get_test_param<ctx, "arr">()), get_test_param<ctx, "value">());
|
||||
|
||||
va.swap(vv);
|
||||
|
||||
ASSERT(all_equal_to(va, get_test_param<ctx, "value">()));
|
||||
ASSERT(va.size() == c_arr_len(get_test_param<ctx, "arr">()), ctx);
|
||||
ASSERT(std::ranges::equal(vv, get_test_param<ctx, "arr">()), ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
||||
return TEST_PASS();
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue