178 lines
6.4 KiB
C++
178 lines
6.4 KiB
C++
#include <const_vector.hpp>
|
|
|
|
#include <test.hpp>
|
|
#include "test_params.h"
|
|
|
|
#include <vector>
|
|
|
|
constexpr test_suite tests = define_tests("Assignment")
|
|
("const_vector::operator=(const const_vector& other)", []() constexpr {
|
|
|
|
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() {
|
|
|
|
cc::const_vector original(get_test_param<ctx, "arr">());
|
|
|
|
decltype(original) v1;
|
|
cc::const_vector<T, get_test_param<ctx, "capacity">()> v2;
|
|
cc::const_vector<T, c_arr_len(get_test_param<ctx, "arr">()) - 1> too_small;
|
|
|
|
v1 = original;
|
|
v2 = original;
|
|
ASSERT_THROWS((too_small = original), std::invalid_argument, ctx);
|
|
|
|
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "arr">()), ctx);
|
|
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "arr">()), ctx);
|
|
ASSERT(std::ranges::equal(original, get_test_param<ctx, "arr">()), ctx);
|
|
|
|
return TEST_PASS();
|
|
}), 2, int, char, const char *, TestObj);
|
|
|
|
return TEST_PASS();
|
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
|
("const_vector::operator=(const_vector&& other)", []() constexpr {
|
|
|
|
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() {
|
|
|
|
cc::const_vector original1(get_test_param<ctx, "arr">());
|
|
cc::const_vector original2(get_test_param<ctx, "arr">());
|
|
cc::const_vector original3(get_test_param<ctx, "arr">());
|
|
|
|
decltype(original1) v1;
|
|
cc::const_vector<T, get_test_param<ctx, "capacity">()> v2;
|
|
cc::const_vector<T, c_arr_len(get_test_param<ctx, "arr">()) - 1> too_small;
|
|
|
|
v1 = force_move(original1);
|
|
v2 = force_move(original2);
|
|
ASSERT_THROWS((too_small = force_move(original3)), std::invalid_argument, ctx);
|
|
|
|
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "arr">()), ctx);
|
|
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "arr">()), ctx);
|
|
|
|
return TEST_PASS();
|
|
}), 2, int, char, const char *, TestObj);
|
|
|
|
return TEST_PASS();
|
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
|
("const_vector::operator=(const value_type (&array)[])", []() constexpr {
|
|
|
|
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() {
|
|
|
|
std::remove_cvref_t<decltype(get_test_param<ctx, "arr">())> arr = {};
|
|
std::copy(std::begin(get_test_param<ctx, "arr">()), std::end(get_test_param<ctx, "arr">()), std::begin(arr));
|
|
|
|
cc::const_vector<T, c_arr_len(arr)> v1;
|
|
cc::const_vector<T, get_test_param<ctx, "capacity">()> v2;
|
|
cc::const_vector<T, c_arr_len(get_test_param<ctx, "arr">()) - 1> too_small;
|
|
|
|
v1 = arr;
|
|
v2 = arr;
|
|
ASSERT_THROWS((too_small = arr), std::invalid_argument, ctx);
|
|
|
|
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "arr">()), ctx);
|
|
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "arr">()), ctx);
|
|
ASSERT(std::ranges::equal(arr, get_test_param<ctx, "arr">()), ctx);
|
|
|
|
return TEST_PASS();
|
|
}), 2, int, char, const char *, TestObj);
|
|
|
|
return TEST_PASS();
|
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
|
("const_vector::operator=(std::initializer_list<value_type> values)", []() constexpr {
|
|
|
|
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() {
|
|
|
|
cc::const_vector<T, get_test_param<ctx, "ilist">().size()> v1;
|
|
cc::const_vector<T, get_test_param<ctx, "capacity">()> v2;
|
|
cc::const_vector<T, get_test_param<ctx, "ilist">().size() - 1> too_small;
|
|
|
|
v1 = get_test_param<ctx, "ilist">();
|
|
v2 = get_test_param<ctx, "ilist">();
|
|
ASSERT_THROWS((too_small = get_test_param<ctx, "ilist">()), std::invalid_argument, ctx);
|
|
|
|
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "ilist">()), ctx);
|
|
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "ilist">()), ctx);
|
|
|
|
return TEST_PASS();
|
|
}), 2, int, char, const char *, TestObj);
|
|
|
|
return TEST_PASS();
|
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
|
|
|
("const_vector::assign(size_type count, const value_type& value)", []() 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 v1(get_test_param<ctx, "arr">());
|
|
cc::const_vector v2(get_test_param<ctx, "arr">());
|
|
|
|
auto count1 = v1.size();
|
|
auto count2 = v2.size() / 2;
|
|
|
|
v1.assign(count1, value);
|
|
v2.assign(count2, value);
|
|
|
|
ASSERT(v1.size() == count1, ctx);
|
|
ASSERT(v2.size() == count2, ctx);
|
|
ASSERT(std::ranges::all_of(v1, [value](auto&& e) { return e == value; }), ctx);
|
|
ASSERT(std::ranges::all_of(v1, [value](auto&& e) { return e == value; }), ctx);
|
|
|
|
ASSERT((value == get_test_param<ctx, "value">()), ctx);
|
|
|
|
return TEST_PASS();
|
|
}), 2, int, char, const char*, TestObj);
|
|
|
|
return TEST_PASS();
|
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
|
("const_vector::assign(InputIt first, InputIt last)", []() 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">())> v1;
|
|
cc::const_vector<T, get_test_param<ctx, "capacity">()> v2;
|
|
cc::const_vector<T, get_test_param<ctx, "ilist">().size()> v3;
|
|
cc::const_vector<T, c_arr_len(get_test_param<ctx, "arr">()) - 1> too_small;
|
|
|
|
std::vector container = get_test_param<ctx, "ilist">();
|
|
|
|
v1.assign(std::begin(get_test_param<ctx, "arr">()), std::end(get_test_param<ctx, "arr">()));
|
|
v2.assign(std::begin(get_test_param<ctx, "arr">()), std::end(get_test_param<ctx, "arr">()));
|
|
v3.assign(container.begin(), container.end());
|
|
|
|
ASSERT_THROWS(
|
|
(too_small.assign(std::begin(get_test_param<ctx, "arr">()),
|
|
std::end(get_test_param<ctx, "arr">()))), std::invalid_argument, ctx);
|
|
|
|
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "arr">()), ctx);
|
|
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "arr">()), ctx);
|
|
ASSERT(std::ranges::equal(v3, container), ctx);
|
|
ASSERT(std::ranges::equal(container, get_test_param<ctx, "ilist">()), ctx);
|
|
|
|
return TEST_PASS();
|
|
}), 2, int, char, const char *, TestObj);
|
|
|
|
return TEST_PASS();
|
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
|
("const_vector::assign(std::initializer_list<value_type> values)", []() constexpr {
|
|
|
|
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename ctx>() constexpr {
|
|
|
|
cc::const_vector<T, get_test_param<ctx, "ilist">().size()> v;
|
|
cc::const_vector<T, get_test_param<ctx, "ilist">().size() - 1> too_small;
|
|
|
|
v.assign(get_test_param<ctx, "ilist">());
|
|
|
|
ASSERT(std::ranges::equal(v, get_test_param<ctx, "ilist">()), ctx);
|
|
|
|
ASSERT_THROWS(too_small.assign(get_test_param<ctx, "ilist">()), std::invalid_argument, ctx);
|
|
|
|
return TEST_PASS();
|
|
}), 2, int, char, const char *, TestObj);
|
|
|
|
return TEST_PASS();
|
|
}, EvalFlag::RUNTIME_CONSTEVAL);
|
|
|
|
int main() {
|
|
return tests.run();
|
|
} |