From 56aa63f42dac66e9c057904f00143d58d838a635 Mon Sep 17 00:00:00 2001 From: Arendelle Date: Sun, 14 Jun 2026 22:44:00 +0800 Subject: [PATCH 1/2] test(vector): add assertions and fix minor issues in test suite - Add includes and comprehensive assert() checks to all vector container tests, verifying size, capacity, element values, and state after operations (push_back, pop_back, erase, insert, assign, swap, clear, shrink_to_fit, etc.) - Fix typo in back.cc: "The first character" -> "The last character" - Fix missing trailing newlines in multiple files - Enable previously disabled append_range.cc test (remove #if 0) - Add state assertions to shared_ptr index tests for insert_index and erase_index operations --- tests/0026.container/0001.vector/append_range.cc | 4 +--- tests/0026.container/0001.vector/assign.cc | 8 +++++++- tests/0026.container/0001.vector/back.cc | 8 +++++--- tests/0026.container/0001.vector/begin.cc | 12 ++++++++---- tests/0026.container/0001.vector/capacity.cc | 9 +++++++-- tests/0026.container/0001.vector/clear.cc | 9 +++++++-- tests/0026.container/0001.vector/data.cc | 10 ++++++++-- tests/0026.container/0001.vector/emplace.cc | 7 ++++++- .../0026.container/0001.vector/emplace_index.cc | 11 ++++++++--- tests/0026.container/0001.vector/empty.cc | 7 +++++-- tests/0026.container/0001.vector/end.cc | 12 ++++++++---- tests/0026.container/0001.vector/erase.cc | 14 ++++++++++++-- tests/0026.container/0001.vector/erase_index.cc | 16 +++++++++++++--- tests/0026.container/0001.vector/front.cc | 6 ++++-- tests/0026.container/0001.vector/insert.cc | 10 ++++++++-- .../0001.vector/operator_assign.cc | 12 +++++++++++- tests/0026.container/0001.vector/operator_at.cc | 6 +++++- tests/0026.container/0001.vector/pop_back.cc | 11 +++++++++-- tests/0026.container/0001.vector/push_back.cc | 9 +++++++-- .../0001.vector/shared_ptr_index.cc | 13 ++++++++++++- .../0001.vector/shared_ptr_index_not_trivial.cc | 12 +++++++++++- .../0026.container/0001.vector/shrink_to_fit.cc | 13 +++++++++++-- tests/0026.container/0001.vector/size.cc | 6 ++++-- tests/0026.container/0001.vector/swap.cc | 12 ++++++++++-- tests/0026.container/0001.vector/vector.cc | 14 ++++++++++++-- .../0001.vector/vector_allocate_at_least.cc | 10 ++++++++-- .../0001.vector/vector_deduction.cc | 13 +++++++++++-- 27 files changed, 218 insertions(+), 56 deletions(-) diff --git a/tests/0026.container/0001.vector/append_range.cc b/tests/0026.container/0001.vector/append_range.cc index a71a49dca..3eecce8bc 100644 --- a/tests/0026.container/0001.vector/append_range.cc +++ b/tests/0026.container/0001.vector/append_range.cc @@ -8,10 +8,8 @@ using namespace fast_io::mnp; int main() { -#if 0 auto head = fast_io::vector{1, 2, 3, 4}; auto const tail = std::list{-5, -6, -7}; head.append_range(tail); assert(std::ranges::equal(head, fast_io::vector{1, 2, 3, 4, -5, -6, -7})); -#endif -} \ No newline at end of file +} diff --git a/tests/0026.container/0001.vector/assign.cc b/tests/0026.container/0001.vector/assign.cc index 8a182fa3e..c1626e79f 100644 --- a/tests/0026.container/0001.vector/assign.cc +++ b/tests/0026.container/0001.vector/assign.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include using namespace fast_io::io; @@ -18,6 +19,11 @@ int main() }; characters.assign(5, 'a'); + assert(characters.size() == 5); + for (char c : characters) + { + assert(c == 'a'); + } print_vector(); #if 0 diff --git a/tests/0026.container/0001.vector/back.cc b/tests/0026.container/0001.vector/back.cc index c000bc7a3..6765db8a2 100644 --- a/tests/0026.container/0001.vector/back.cc +++ b/tests/0026.container/0001.vector/back.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -9,6 +10,7 @@ int main() if (!letters.empty()) { - print("The first character is '", chvw(letters.back()), "'.\n"); + print("The last character is '", chvw(letters.back()), "'.\n"); } -} \ No newline at end of file + assert(letters.back() == 'f'); +} diff --git a/tests/0026.container/0001.vector/begin.cc b/tests/0026.container/0001.vector/begin.cc index 16bf1d280..d2057a862 100644 --- a/tests/0026.container/0001.vector/begin.cc +++ b/tests/0026.container/0001.vector/begin.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include #include @@ -17,17 +18,20 @@ int main() print("\n"); // Sums all integers in the vector nums (if any), printing only the result. - println("Sum of nums: ", - std::accumulate(nums.begin(), nums.end(), 0)); + auto const sum = std::accumulate(nums.begin(), nums.end(), 0); + println("Sum of nums: ", sum); + assert(sum == 31); // Prints the first fruit in the vector fruits, checking if there is any. if (!fruits.empty()) { println("First fruit: ", *fruits.begin()); + assert(*fruits.begin() == "orange"); } if (empty.begin() == empty.end()) { print("vector 'empty' is indeed empty.\n"); } -} \ No newline at end of file + assert(empty.begin() == empty.end()); +} diff --git a/tests/0026.container/0001.vector/capacity.cc b/tests/0026.container/0001.vector/capacity.cc index 969b289d5..1603e32d4 100644 --- a/tests/0026.container/0001.vector/capacity.cc +++ b/tests/0026.container/0001.vector/capacity.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -10,8 +11,10 @@ int main() auto cap = v.capacity(); println("Initial size: ", v.size(), ", capacity: ", cap); + assert(v.size() == 0); + assert(v.capacity() == 0); - print("\nDemonstrate the capacity's growth policy." + print("\nDemonstrate the capacity'\''s growth policy." "\nSize: Capacity: Ratio:\n"); while (sz-- > 0) { @@ -19,9 +22,11 @@ int main() if (cap != v.capacity()) { println(left(v.size(), 7), left(v.capacity(), 11), left(float(v.capacity()) / static_cast(cap), 10)); + assert(v.capacity() > cap); cap = v.capacity(); } } println("\nFinal size: ", v.size(), ", capacity: ", v.capacity()); + assert(v.size() == 100); } diff --git a/tests/0026.container/0001.vector/clear.cc b/tests/0026.container/0001.vector/clear.cc index 45d39ee25..63185d613 100644 --- a/tests/0026.container/0001.vector/clear.cc +++ b/tests/0026.container/0001.vector/clear.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include using namespace fast_io::io; @@ -13,6 +14,10 @@ int main() { fast_io::vector container{1, 2, 3}; print_info("Before clear: ", container); + assert(!container.empty()); + assert(container.size() == 3); container.clear(); print_info("After clear: ", container); -} \ No newline at end of file + assert(container.empty()); + assert(container.size() == 0); +} diff --git a/tests/0026.container/0001.vector/data.cc b/tests/0026.container/0001.vector/data.cc index 46458b465..b2bffdbf7 100644 --- a/tests/0026.container/0001.vector/data.cc +++ b/tests/0026.container/0001.vector/data.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include #include @@ -29,4 +30,9 @@ int main() // std::span (C++20) is a safer alternative to separated pointer/size. span_func({container.data(), container.size()}); -} \ No newline at end of file + + assert(container.data()[0] == 1); + assert(container.data()[1] == 2); + assert(container.data()[2] == 3); + assert(container.data()[3] == 4); +} diff --git a/tests/0026.container/0001.vector/emplace.cc b/tests/0026.container/0001.vector/emplace.cc index b0970a62a..25165a56f 100644 --- a/tests/0026.container/0001.vector/emplace.cc +++ b/tests/0026.container/0001.vector/emplace.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include #include @@ -62,4 +63,8 @@ int main() container.emplace(container.end(), std::move(three)); println("content:\n ", rgvw(container | std::views::transform([](auto const &a) { return a.s; }), " ")); + assert(container.size() == 3); + assert(container[0].s == "one"); + assert(container[1].s == "two"); + assert(container[2].s == "three"); } diff --git a/tests/0026.container/0001.vector/emplace_index.cc b/tests/0026.container/0001.vector/emplace_index.cc index 8ea5bfda3..d20f1dd20 100644 --- a/tests/0026.container/0001.vector/emplace_index.cc +++ b/tests/0026.container/0001.vector/emplace_index.cc @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include #include using namespace fast_io::io; @@ -13,6 +11,13 @@ int main() vec.emplace_index(0,6); vec.emplace_index(0,8); vec.erase_index(0); + // After push_back(4): [4] + // After emplace_index(0,6): [6,4] + // After emplace_index(0,8): [8,6,4] + // After erase_index(0): [6,4] + assert(vec.size() == 2); + assert(vec[0] == 6); + assert(vec[1] == 4); for(auto const & e : vec) { ::fast_io::io::println(e); diff --git a/tests/0026.container/0001.vector/empty.cc b/tests/0026.container/0001.vector/empty.cc index 73d4e2388..78ea733db 100644 --- a/tests/0026.container/0001.vector/empty.cc +++ b/tests/0026.container/0001.vector/empty.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -7,7 +8,9 @@ int main() { fast_io::vector numbers; println("Initially, numbers.empty(): ", boolalpha(numbers.empty())); + assert(numbers.empty()); numbers.push_back(42); println("After adding elements, numbers.empty(): ", boolalpha(numbers.empty())); -} \ No newline at end of file + assert(!numbers.empty()); +} diff --git a/tests/0026.container/0001.vector/end.cc b/tests/0026.container/0001.vector/end.cc index 16bf1d280..d2057a862 100644 --- a/tests/0026.container/0001.vector/end.cc +++ b/tests/0026.container/0001.vector/end.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include #include @@ -17,17 +18,20 @@ int main() print("\n"); // Sums all integers in the vector nums (if any), printing only the result. - println("Sum of nums: ", - std::accumulate(nums.begin(), nums.end(), 0)); + auto const sum = std::accumulate(nums.begin(), nums.end(), 0); + println("Sum of nums: ", sum); + assert(sum == 31); // Prints the first fruit in the vector fruits, checking if there is any. if (!fruits.empty()) { println("First fruit: ", *fruits.begin()); + assert(*fruits.begin() == "orange"); } if (empty.begin() == empty.end()) { print("vector 'empty' is indeed empty.\n"); } -} \ No newline at end of file + assert(empty.begin() == empty.end()); +} diff --git a/tests/0026.container/0001.vector/erase.cc b/tests/0026.container/0001.vector/erase.cc index ece6adf2a..835cc71aa 100644 --- a/tests/0026.container/0001.vector/erase.cc +++ b/tests/0026.container/0001.vector/erase.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -11,12 +12,18 @@ void print_container(fast_io::vector const &c) int main() { fast_io::vector c{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + assert(c.size() == 10); print_container(c); c.erase(c.begin()); + assert(c.size() == 9); + assert(c[0] == 1); print_container(c); c.erase(c.begin() + 2, c.begin() + 5); + // Before: [1,2,3,4,5,6,7,8,9]; erase indices 2-4 (values 3,4,5) + assert(c.size() == 6); + assert(c[0] == 1 && c[1] == 2 && c[2] == 6 && c[3] == 7 && c[4] == 8 && c[5] == 9); print_container(c); // Erase all even numbers @@ -31,5 +38,8 @@ int main() ++it; } } + // After erasing evens from [1,2,6,7,8,9]: [1,7,9] + assert(c.size() == 3); + assert(c[0] == 1 && c[1] == 7 && c[2] == 9); print_container(c); -} \ No newline at end of file +} diff --git a/tests/0026.container/0001.vector/erase_index.cc b/tests/0026.container/0001.vector/erase_index.cc index ef0b75878..d913428b5 100644 --- a/tests/0026.container/0001.vector/erase_index.cc +++ b/tests/0026.container/0001.vector/erase_index.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -11,12 +12,19 @@ inline void print_container(fast_io::vector const &c) int main() { fast_io::vector c{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + assert(c.size() == 10); print_container(c); c.erase_index(0); + assert(c.size() == 9); + assert(c[0] == 1); print_container(c); c.erase_index(2, 5); + // After erasing index 0: [1,2,3,4,5,6,7,8,9] + // erase_index(2,5): erase indices 2..4 (values 3,4,5) => [1,2,6,7,8,9] + assert(c.size() == 6); + assert(c[0] == 1 && c[1] == 2 && c[2] == 6 && c[3] == 7 && c[4] == 8 && c[5] == 9); print_container(c); // Erase all even numbers @@ -31,6 +39,8 @@ int main() ++i; } } - + // After erasing evens from [1,2,6,7,8,9]: [1,7,9] + assert(c.size() == 3); + assert(c[0] == 1 && c[1] == 7 && c[2] == 9); print_container(c); -} \ No newline at end of file +} diff --git a/tests/0026.container/0001.vector/front.cc b/tests/0026.container/0001.vector/front.cc index 788214682..b47ca738d 100644 --- a/tests/0026.container/0001.vector/front.cc +++ b/tests/0026.container/0001.vector/front.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -11,4 +12,5 @@ int main() { print("The first character is '", chvw(letters.front()), "'.\n"); } -} \ No newline at end of file + assert(letters.front() == 'a'); +} diff --git a/tests/0026.container/0001.vector/insert.cc b/tests/0026.container/0001.vector/insert.cc index c7b1864a1..62699205e 100644 --- a/tests/0026.container/0001.vector/insert.cc +++ b/tests/0026.container/0001.vector/insert.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include using namespace fast_io::io; @@ -13,9 +14,14 @@ int main() { fast_io::vector c1(3, 100); print_info(1, c1); + assert(c1.size() == 3); + assert(c1[0] == 100 && c1[1] == 100 && c1[2] == 100); auto it = c1.begin(); it = c1.insert(it, 200); + assert(*it == 200); + assert(c1.size() == 4); + assert(c1[0] == 200); print_info(2, c1); #if 0 c1.insert(it, 2, 300); @@ -35,4 +41,4 @@ int main() c1.insert(c1.end(), {601, 602, 603}); print_info(6, c1); #endif -} \ No newline at end of file +} diff --git a/tests/0026.container/0001.vector/operator_assign.cc b/tests/0026.container/0001.vector/operator_assign.cc index 1839fda72..9595c942d 100644 --- a/tests/0026.container/0001.vector/operator_assign.cc +++ b/tests/0026.container/0001.vector/operator_assign.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include #include @@ -11,14 +12,23 @@ int main() print("Initially:\n"); print("x = {", rgvw(x, ", "), "}\ny = {", rgvw(y, ", "), "}\nz = {", rgvw(z, ", "), "}\n"); + assert(x.size() == 3); + assert(y.empty()); + assert(z.empty()); print("Copy assignment copies data from x to y:\n"); y = x; print("x = {", rgvw(x, ", "), "}\ny = {", rgvw(y, ", "), "}\n"); + assert(y.size() == 3); + assert(y[0] == 1 && y[1] == 2 && y[2] == 3); print("Move assignment moves data from x to z, modifying both x and z:\n"); z = std::move(x); print("x = {", rgvw(x, ", "), "}\nz = {", rgvw(z, ", "), "}\n"); + assert(z.size() == 3); + assert(z[0] == 1 && z[1] == 2 && z[2] == 3); + // After move, source vector should be empty + assert(x.empty()); #if 0 auto const w = {4, 5, 6, 7}; diff --git a/tests/0026.container/0001.vector/operator_at.cc b/tests/0026.container/0001.vector/operator_at.cc index f1f1cb8fb..c82c411c2 100644 --- a/tests/0026.container/0001.vector/operator_at.cc +++ b/tests/0026.container/0001.vector/operator_at.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -8,10 +9,13 @@ int main() fast_io::vector numbers{2, 4, 6, 8}; print("Second element: ", numbers[1], "\n"); + assert(numbers[1] == 4); numbers[0] = 5; + assert(numbers[0] == 5); println("All numbers: ", rgvw(numbers, " ")); + assert(numbers[0] == 5 && numbers[1] == 4 && numbers[2] == 6 && numbers[3] == 8); } // Gets the sum of all primes in [0, N) using sieve of Eratosthenes diff --git a/tests/0026.container/0001.vector/pop_back.cc b/tests/0026.container/0001.vector/pop_back.cc index 1b69c9f01..5d1e3b265 100644 --- a/tests/0026.container/0001.vector/pop_back.cc +++ b/tests/0026.container/0001.vector/pop_back.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -18,10 +19,16 @@ int main() numbers.push_back(5); numbers.push_back(3); numbers.push_back(4); + assert(numbers.size() == 3); + assert(numbers[0] == 5); + assert(numbers[1] == 3); + assert(numbers[2] == 4); print_info(numbers); numbers.pop_back(); + assert(numbers.size() == 2); + assert(numbers.back() == 3); print_info(numbers); -} \ No newline at end of file +} diff --git a/tests/0026.container/0001.vector/push_back.cc b/tests/0026.container/0001.vector/push_back.cc index f59bda823..6963ce66d 100644 --- a/tests/0026.container/0001.vector/push_back.cc +++ b/tests/0026.container/0001.vector/push_back.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include using namespace fast_io::io; @@ -12,6 +13,10 @@ int main() std::string s{"def"}; letters.push_back(std::move(s)); + assert(letters.size() == 2); + assert(letters[0] == "abc"); + assert(letters[1] == "def"); + print("std::vector letters holds: "); for (auto &&e : letters) { @@ -19,4 +24,4 @@ int main() } print("\nMoved-from string s holds: \"", s, "\"\n"); -} \ No newline at end of file +} diff --git a/tests/0026.container/0001.vector/shared_ptr_index.cc b/tests/0026.container/0001.vector/shared_ptr_index.cc index 718ed417e..070765bbe 100644 --- a/tests/0026.container/0001.vector/shared_ptr_index.cc +++ b/tests/0026.container/0001.vector/shared_ptr_index.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include @@ -16,7 +17,14 @@ struct is_trivially_copyable_or_relocatable<::std::shared_ptr> int main() { ::fast_io::vector<::std::shared_ptr> vec{std::make_shared(1), std::make_shared(2), std::make_shared(3)}; + assert(vec.size() == 3); vec.insert_index(1, std::make_shared(4)); + assert(vec.size() == 4); + assert(*vec[0] == 1); + assert(*vec[1] == 4); + assert(*vec[2] == 2); + assert(*vec[3] == 3); + assert(vec[1].use_count() == 1); using namespace ::fast_io::io; print("After vec.insert_index(1)\n"); for (auto const &e : vec) @@ -24,6 +32,9 @@ int main() println(::fast_io::mnp::pointervw(e.get()), " use_count: ", e.use_count()); } vec.erase_index(0, 2); + assert(vec.size() == 2); + assert(*vec[0] == 2); + assert(*vec[1] == 3); print("After vec.erase_index(0,2)\n"); for (auto const &e : vec) { diff --git a/tests/0026.container/0001.vector/shared_ptr_index_not_trivial.cc b/tests/0026.container/0001.vector/shared_ptr_index_not_trivial.cc index ec16a890c..6cc34aa9a 100644 --- a/tests/0026.container/0001.vector/shared_ptr_index_not_trivial.cc +++ b/tests/0026.container/0001.vector/shared_ptr_index_not_trivial.cc @@ -1,11 +1,18 @@ -#include +#include +#include #include #include int main() { ::fast_io::vector<::std::shared_ptr> vec{std::make_shared(1), std::make_shared(2), std::make_shared(3)}; + assert(vec.size() == 3); vec.insert_index(1, std::make_shared(4)); + assert(vec.size() == 4); + assert(*vec[0] == 1); + assert(*vec[1] == 4); + assert(*vec[2] == 2); + assert(*vec[3] == 3); using namespace ::fast_io::io; print("After vec.insert_index(1)\n"); for (auto const &e : vec) @@ -13,6 +20,9 @@ int main() println(::fast_io::mnp::pointervw(e.get()), " use_count: ", e.use_count()); } vec.erase_index(0, 2); + assert(vec.size() == 2); + assert(*vec[0] == 2); + assert(*vec[1] == 3); print("After vec.erase_index(0,2)\n"); for (auto const &e : vec) { diff --git a/tests/0026.container/0001.vector/shrink_to_fit.cc b/tests/0026.container/0001.vector/shrink_to_fit.cc index 75cf3c8f4..15acfd107 100644 --- a/tests/0026.container/0001.vector/shrink_to_fit.cc +++ b/tests/0026.container/0001.vector/shrink_to_fit.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -7,12 +8,18 @@ int main() { fast_io::vector v; println("Default-constructed capacity is ", v.capacity()); + assert(v.capacity() == 0); v.resize(100); println("Capacity of a 100-element vector is ", v.capacity()); + assert(v.capacity() >= 100); + auto old_cap = v.capacity(); v.resize(50); println("Capacity after resize(50) is ", v.capacity()); + assert(v.capacity() == old_cap); v.shrink_to_fit(); println("Capacity after shrink_to_fit() is ", v.capacity()); + assert(v.size() == 50); + assert(v.capacity() >= 50); v.clear(); println("Capacity after clear() is ", v.capacity()); v.shrink_to_fit(); @@ -22,6 +29,8 @@ int main() v.push_back(i); } println("Capacity after adding 300 elements is ", v.capacity()); + assert(v.size() == 300); v.shrink_to_fit(); println("Capacity after shrink_to_fit() is ", v.capacity()); -} \ No newline at end of file + assert(v.capacity() >= 300); +} diff --git a/tests/0026.container/0001.vector/size.cc b/tests/0026.container/0001.vector/size.cc index b28d87578..a34efca6a 100644 --- a/tests/0026.container/0001.vector/size.cc +++ b/tests/0026.container/0001.vector/size.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -8,4 +9,5 @@ int main() fast_io::vector nums{1, 3, 5, 7}; print("nums contains ", nums.size(), " elements.\n"); -} \ No newline at end of file + assert(nums.size() == 4); +} diff --git a/tests/0026.container/0001.vector/swap.cc b/tests/0026.container/0001.vector/swap.cc index ed76031fc..fbb3ee5c1 100644 --- a/tests/0026.container/0001.vector/swap.cc +++ b/tests/0026.container/0001.vector/swap.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -6,6 +7,9 @@ using namespace fast_io::mnp; int main() { fast_io::vector a1{1, 2, 3}, a2{4, 5}; + assert(a1.size() == 3 && a2.size() == 2); + assert(a1[0] == 1 && a1[1] == 2 && a1[2] == 3); + assert(a2[0] == 4 && a2[1] == 5); auto it1 = std::next(a1.begin()); auto it2 = std::next(a2.begin()); @@ -17,7 +21,11 @@ int main() a1.swap(a2); perrln("{ ", rgvw(a1, " "), " } { ", rgvw(a2, " "), " } ", *it1, " ", *it2, " ", ref1, ' ', ref2); + assert(a1.size() == 2 && a2.size() == 3); + assert(a1[0] == 4 && a1[1] == 5); + assert(a2[0] == 1 && a2[1] == 2 && a2[2] == 3); + // Note that after swap the iterators and references stay associated with their // original elements, e.g. it1 that pointed to an element in 'a1' with value 2 // still points to the same element, though this element was moved into 'a2'. -} \ No newline at end of file +} diff --git a/tests/0026.container/0001.vector/vector.cc b/tests/0026.container/0001.vector/vector.cc index c2063d945..8618af9b2 100644 --- a/tests/0026.container/0001.vector/vector.cc +++ b/tests/0026.container/0001.vector/vector.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include #include using namespace fast_io::io; @@ -9,6 +10,12 @@ int main() // C++11 initializer list syntax: fast_io::vector words1{"the", "frogurt", "is", "also", "cursed"}; print("1: {", rgvw(words1, ", "), "}\n"); + assert(words1.size() == 5); + assert(words1[0] == "the"); + assert(words1[1] == "frogurt"); + assert(words1[2] == "is"); + assert(words1[3] == "also"); + assert(words1[4] == "cursed"); #if 0 // words2 == words1 fast_io::vector words2(::std::from_range, words1); @@ -17,13 +24,16 @@ int main() // words3 == words1 fast_io::vector words3(words1); print("3: {", rgvw(words3, ", "), "}\n"); + assert(words3 == words1); // words4 is {"Mo", "Mo", "Mo", "Mo", "Mo"} fast_io::vector words4(5, "Mo"); print("4: {", rgvw(words4, ", "), "}\n"); + assert(words4.size() == 5); + for (auto const &w : words4) assert(w == "Mo"); #if 0 auto const rg = {"cat", "cow", "crow"}; fast_io::vector words5(::std::from_range, rg); // overload (11) print("5: {", rgvw(words5, ", "), "}\n"); #endif -} \ No newline at end of file +} diff --git a/tests/0026.container/0001.vector/vector_allocate_at_least.cc b/tests/0026.container/0001.vector/vector_allocate_at_least.cc index be73a1944..906438ac7 100644 --- a/tests/0026.container/0001.vector/vector_allocate_at_least.cc +++ b/tests/0026.container/0001.vector/vector_allocate_at_least.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -7,7 +8,12 @@ int main() { fast_io::vector<::std::size_t> vec; println("Before vec.push_back(50): vec.size()=",vec.size()," vec.capacity()=",vec.capacity()); + assert(vec.size() == 0); + assert(vec.capacity() == 0); vec.push_back(50); vec.push_back(50); println("After vec.push_back(50): vec.size()=",vec.size()," vec.capacity()=",vec.capacity()); -} \ No newline at end of file + assert(vec.size() == 2); + assert(vec[0] == 50); + assert(vec[1] == 50); +} diff --git a/tests/0026.container/0001.vector/vector_deduction.cc b/tests/0026.container/0001.vector/vector_deduction.cc index e3b412543..01ea0de84 100644 --- a/tests/0026.container/0001.vector/vector_deduction.cc +++ b/tests/0026.container/0001.vector/vector_deduction.cc @@ -1,4 +1,5 @@ -#include +#include +#include #include using namespace fast_io::io; using namespace fast_io::mnp; @@ -7,7 +8,15 @@ int main() { fast_io::vector vec{static_cast<::std::uint_least32_t>(1), 6, 10, 20}; println("Before vec.push_back(50): vec.size()=", vec.size(), " vec.capacity()=", vec.capacity()); + assert(vec.size() == 4); + assert(vec[0] == 1); + assert(vec[1] == 6); + assert(vec[2] == 10); + assert(vec[3] == 20); vec.push_back(50); vec.push_back(50); println("After vec.push_back(50): vec.size()=", vec.size(), " vec.capacity()=", vec.capacity()); -} \ No newline at end of file + assert(vec.size() == 6); + assert(vec[4] == 50); + assert(vec[5] == 50); +} From 431d4ce2486cb118681d5321dc59f860ff1521eb Mon Sep 17 00:00:00 2001 From: Arendelle Date: Sun, 14 Jun 2026 23:07:22 +0800 Subject: [PATCH 2/2] Replace assert to fast_terminate --- .../0001.vector/append_range.cc | 3 +-- tests/0026.container/0001.vector/assign.cc | 5 ++--- .../0001.vector/assign_range.cc | 5 ++--- tests/0026.container/0001.vector/back.cc | 3 +-- tests/0026.container/0001.vector/begin.cc | 7 +++---- tests/0026.container/0001.vector/capacity.cc | 9 ++++---- tests/0026.container/0001.vector/clear.cc | 9 ++++---- tests/0026.container/0001.vector/data.cc | 9 ++++---- tests/0026.container/0001.vector/emplace.cc | 9 ++++---- .../0001.vector/emplace_index.cc | 7 +++---- tests/0026.container/0001.vector/empty.cc | 5 ++--- tests/0026.container/0001.vector/end.cc | 7 +++---- tests/0026.container/0001.vector/erase.cc | 15 +++++++------ .../0026.container/0001.vector/erase_index.cc | 15 +++++++------ tests/0026.container/0001.vector/front.cc | 3 +-- tests/0026.container/0001.vector/insert.cc | 11 +++++----- .../0001.vector/insert_range.cc | 5 ++--- .../0001.vector/operator_assign.cc | 17 +++++++-------- .../0026.container/0001.vector/operator_at.cc | 7 +++---- .../0001.vector/operator_cmp.cc | 5 ++--- tests/0026.container/0001.vector/pop_back.cc | 13 ++++++------ tests/0026.container/0001.vector/push_back.cc | 7 +++---- .../0001.vector/shared_ptr_index.cc | 21 +++++++++---------- .../shared_ptr_index_not_trivial.cc | 19 ++++++++--------- .../0001.vector/shrink_to_fit.cc | 15 +++++++------ tests/0026.container/0001.vector/size.cc | 3 +-- tests/0026.container/0001.vector/swap.cc | 13 ++++++------ tests/0026.container/0001.vector/vector.cc | 19 ++++++++--------- .../0001.vector/vector_allocate_at_least.cc | 11 +++++----- .../0001.vector/vector_deduction.cc | 17 +++++++-------- 30 files changed, 132 insertions(+), 162 deletions(-) diff --git a/tests/0026.container/0001.vector/append_range.cc b/tests/0026.container/0001.vector/append_range.cc index 3eecce8bc..b0f5397f0 100644 --- a/tests/0026.container/0001.vector/append_range.cc +++ b/tests/0026.container/0001.vector/append_range.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -11,5 +10,5 @@ int main() auto head = fast_io::vector{1, 2, 3, 4}; auto const tail = std::list{-5, -6, -7}; head.append_range(tail); - assert(std::ranges::equal(head, fast_io::vector{1, 2, 3, 4, -5, -6, -7})); + if (!(std::ranges::equal(head, fast_io::vector{1, 2, 3, 4, -5, -6, -7}))) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/assign.cc b/tests/0026.container/0001.vector/assign.cc index c1626e79f..fcb50d690 100644 --- a/tests/0026.container/0001.vector/assign.cc +++ b/tests/0026.container/0001.vector/assign.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -19,10 +18,10 @@ int main() }; characters.assign(5, 'a'); - assert(characters.size() == 5); + if (!(characters.size() == 5)) ::fast_io::fast_terminate(); for (char c : characters) { - assert(c == 'a'); + if (!(c == 'a')) ::fast_io::fast_terminate(); } print_vector(); diff --git a/tests/0026.container/0001.vector/assign_range.cc b/tests/0026.container/0001.vector/assign_range.cc index 7366eb689..82041d45a 100644 --- a/tests/0026.container/0001.vector/assign_range.cc +++ b/tests/0026.container/0001.vector/assign_range.cc @@ -1,5 +1,4 @@ -#include -#include +#include #include #include #include @@ -10,6 +9,6 @@ int main() auto const source = std::list{2, 7, 1}; auto destination = fast_io::vector{3, 1, 4}; destination.assign_range(source); - assert(std::ranges::equal(source, destination)); + if (!(std::ranges::equal(source, destination))) ::fast_io::fast_terminate(); #endif } \ No newline at end of file diff --git a/tests/0026.container/0001.vector/back.cc b/tests/0026.container/0001.vector/back.cc index 6765db8a2..d87625218 100644 --- a/tests/0026.container/0001.vector/back.cc +++ b/tests/0026.container/0001.vector/back.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -12,5 +11,5 @@ int main() { print("The last character is '", chvw(letters.back()), "'.\n"); } - assert(letters.back() == 'f'); + if (!(letters.back() == 'f')) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/begin.cc b/tests/0026.container/0001.vector/begin.cc index d2057a862..7c41e2e63 100644 --- a/tests/0026.container/0001.vector/begin.cc +++ b/tests/0026.container/0001.vector/begin.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -20,18 +19,18 @@ int main() // Sums all integers in the vector nums (if any), printing only the result. auto const sum = std::accumulate(nums.begin(), nums.end(), 0); println("Sum of nums: ", sum); - assert(sum == 31); + if (!(sum == 31)) ::fast_io::fast_terminate(); // Prints the first fruit in the vector fruits, checking if there is any. if (!fruits.empty()) { println("First fruit: ", *fruits.begin()); - assert(*fruits.begin() == "orange"); + if (!(*fruits.begin() == "orange")) ::fast_io::fast_terminate(); } if (empty.begin() == empty.end()) { print("vector 'empty' is indeed empty.\n"); } - assert(empty.begin() == empty.end()); + if (!(empty.begin() == empty.end())) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/capacity.cc b/tests/0026.container/0001.vector/capacity.cc index 1603e32d4..2b15df8e5 100644 --- a/tests/0026.container/0001.vector/capacity.cc +++ b/tests/0026.container/0001.vector/capacity.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -11,8 +10,8 @@ int main() auto cap = v.capacity(); println("Initial size: ", v.size(), ", capacity: ", cap); - assert(v.size() == 0); - assert(v.capacity() == 0); + if (!(v.size() == 0)) ::fast_io::fast_terminate(); + if (!(v.capacity() == 0)) ::fast_io::fast_terminate(); print("\nDemonstrate the capacity'\''s growth policy." "\nSize: Capacity: Ratio:\n"); @@ -22,11 +21,11 @@ int main() if (cap != v.capacity()) { println(left(v.size(), 7), left(v.capacity(), 11), left(float(v.capacity()) / static_cast(cap), 10)); - assert(v.capacity() > cap); + if (!(v.capacity() > cap)) ::fast_io::fast_terminate(); cap = v.capacity(); } } println("\nFinal size: ", v.size(), ", capacity: ", v.capacity()); - assert(v.size() == 100); + if (!(v.size() == 100)) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/clear.cc b/tests/0026.container/0001.vector/clear.cc index 63185d613..1f6ad45a7 100644 --- a/tests/0026.container/0001.vector/clear.cc +++ b/tests/0026.container/0001.vector/clear.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -14,10 +13,10 @@ int main() { fast_io::vector container{1, 2, 3}; print_info("Before clear: ", container); - assert(!container.empty()); - assert(container.size() == 3); + if (!(!container.empty())) ::fast_io::fast_terminate(); + if (!(container.size() == 3)) ::fast_io::fast_terminate(); container.clear(); print_info("After clear: ", container); - assert(container.empty()); - assert(container.size() == 0); + if (!(container.empty())) ::fast_io::fast_terminate(); + if (!(container.size() == 0)) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/data.cc b/tests/0026.container/0001.vector/data.cc index b2bffdbf7..bf6638d15 100644 --- a/tests/0026.container/0001.vector/data.cc +++ b/tests/0026.container/0001.vector/data.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -31,8 +30,8 @@ int main() // std::span (C++20) is a safer alternative to separated pointer/size. span_func({container.data(), container.size()}); - assert(container.data()[0] == 1); - assert(container.data()[1] == 2); - assert(container.data()[2] == 3); - assert(container.data()[3] == 4); + if (!(container.data()[0] == 1)) ::fast_io::fast_terminate(); + if (!(container.data()[1] == 2)) ::fast_io::fast_terminate(); + if (!(container.data()[2] == 3)) ::fast_io::fast_terminate(); + if (!(container.data()[3] == 4)) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/emplace.cc b/tests/0026.container/0001.vector/emplace.cc index 25165a56f..5af7a56af 100644 --- a/tests/0026.container/0001.vector/emplace.cc +++ b/tests/0026.container/0001.vector/emplace.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -63,8 +62,8 @@ int main() container.emplace(container.end(), std::move(three)); println("content:\n ", rgvw(container | std::views::transform([](auto const &a) { return a.s; }), " ")); - assert(container.size() == 3); - assert(container[0].s == "one"); - assert(container[1].s == "two"); - assert(container[2].s == "three"); + if (!(container.size() == 3)) ::fast_io::fast_terminate(); + if (!(container[0].s == "one")) ::fast_io::fast_terminate(); + if (!(container[1].s == "two")) ::fast_io::fast_terminate(); + if (!(container[2].s == "three")) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/emplace_index.cc b/tests/0026.container/0001.vector/emplace_index.cc index d20f1dd20..0ed045cd2 100644 --- a/tests/0026.container/0001.vector/emplace_index.cc +++ b/tests/0026.container/0001.vector/emplace_index.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -15,9 +14,9 @@ int main() // After emplace_index(0,6): [6,4] // After emplace_index(0,8): [8,6,4] // After erase_index(0): [6,4] - assert(vec.size() == 2); - assert(vec[0] == 6); - assert(vec[1] == 4); + if (!(vec.size() == 2)) ::fast_io::fast_terminate(); + if (!(vec[0] == 6)) ::fast_io::fast_terminate(); + if (!(vec[1] == 4)) ::fast_io::fast_terminate(); for(auto const & e : vec) { ::fast_io::io::println(e); diff --git a/tests/0026.container/0001.vector/empty.cc b/tests/0026.container/0001.vector/empty.cc index 78ea733db..679db01a7 100644 --- a/tests/0026.container/0001.vector/empty.cc +++ b/tests/0026.container/0001.vector/empty.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -8,9 +7,9 @@ int main() { fast_io::vector numbers; println("Initially, numbers.empty(): ", boolalpha(numbers.empty())); - assert(numbers.empty()); + if (!(numbers.empty())) ::fast_io::fast_terminate(); numbers.push_back(42); println("After adding elements, numbers.empty(): ", boolalpha(numbers.empty())); - assert(!numbers.empty()); + if (!(!numbers.empty())) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/end.cc b/tests/0026.container/0001.vector/end.cc index d2057a862..7c41e2e63 100644 --- a/tests/0026.container/0001.vector/end.cc +++ b/tests/0026.container/0001.vector/end.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -20,18 +19,18 @@ int main() // Sums all integers in the vector nums (if any), printing only the result. auto const sum = std::accumulate(nums.begin(), nums.end(), 0); println("Sum of nums: ", sum); - assert(sum == 31); + if (!(sum == 31)) ::fast_io::fast_terminate(); // Prints the first fruit in the vector fruits, checking if there is any. if (!fruits.empty()) { println("First fruit: ", *fruits.begin()); - assert(*fruits.begin() == "orange"); + if (!(*fruits.begin() == "orange")) ::fast_io::fast_terminate(); } if (empty.begin() == empty.end()) { print("vector 'empty' is indeed empty.\n"); } - assert(empty.begin() == empty.end()); + if (!(empty.begin() == empty.end())) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/erase.cc b/tests/0026.container/0001.vector/erase.cc index 835cc71aa..ed1d900ee 100644 --- a/tests/0026.container/0001.vector/erase.cc +++ b/tests/0026.container/0001.vector/erase.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -12,18 +11,18 @@ void print_container(fast_io::vector const &c) int main() { fast_io::vector c{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - assert(c.size() == 10); + if (!(c.size() == 10)) ::fast_io::fast_terminate(); print_container(c); c.erase(c.begin()); - assert(c.size() == 9); - assert(c[0] == 1); + if (!(c.size() == 9)) ::fast_io::fast_terminate(); + if (!(c[0] == 1)) ::fast_io::fast_terminate(); print_container(c); c.erase(c.begin() + 2, c.begin() + 5); // Before: [1,2,3,4,5,6,7,8,9]; erase indices 2-4 (values 3,4,5) - assert(c.size() == 6); - assert(c[0] == 1 && c[1] == 2 && c[2] == 6 && c[3] == 7 && c[4] == 8 && c[5] == 9); + if (!(c.size() == 6)) ::fast_io::fast_terminate(); + if (!(c[0] == 1 && c[1] == 2 && c[2] == 6 && c[3] == 7 && c[4] == 8 && c[5] == 9)) ::fast_io::fast_terminate(); print_container(c); // Erase all even numbers @@ -39,7 +38,7 @@ int main() } } // After erasing evens from [1,2,6,7,8,9]: [1,7,9] - assert(c.size() == 3); - assert(c[0] == 1 && c[1] == 7 && c[2] == 9); + if (!(c.size() == 3)) ::fast_io::fast_terminate(); + if (!(c[0] == 1 && c[1] == 7 && c[2] == 9)) ::fast_io::fast_terminate(); print_container(c); } diff --git a/tests/0026.container/0001.vector/erase_index.cc b/tests/0026.container/0001.vector/erase_index.cc index d913428b5..7677355c4 100644 --- a/tests/0026.container/0001.vector/erase_index.cc +++ b/tests/0026.container/0001.vector/erase_index.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -12,19 +11,19 @@ inline void print_container(fast_io::vector const &c) int main() { fast_io::vector c{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - assert(c.size() == 10); + if (!(c.size() == 10)) ::fast_io::fast_terminate(); print_container(c); c.erase_index(0); - assert(c.size() == 9); - assert(c[0] == 1); + if (!(c.size() == 9)) ::fast_io::fast_terminate(); + if (!(c[0] == 1)) ::fast_io::fast_terminate(); print_container(c); c.erase_index(2, 5); // After erasing index 0: [1,2,3,4,5,6,7,8,9] // erase_index(2,5): erase indices 2..4 (values 3,4,5) => [1,2,6,7,8,9] - assert(c.size() == 6); - assert(c[0] == 1 && c[1] == 2 && c[2] == 6 && c[3] == 7 && c[4] == 8 && c[5] == 9); + if (!(c.size() == 6)) ::fast_io::fast_terminate(); + if (!(c[0] == 1 && c[1] == 2 && c[2] == 6 && c[3] == 7 && c[4] == 8 && c[5] == 9)) ::fast_io::fast_terminate(); print_container(c); // Erase all even numbers @@ -40,7 +39,7 @@ int main() } } // After erasing evens from [1,2,6,7,8,9]: [1,7,9] - assert(c.size() == 3); - assert(c[0] == 1 && c[1] == 7 && c[2] == 9); + if (!(c.size() == 3)) ::fast_io::fast_terminate(); + if (!(c[0] == 1 && c[1] == 7 && c[2] == 9)) ::fast_io::fast_terminate(); print_container(c); } diff --git a/tests/0026.container/0001.vector/front.cc b/tests/0026.container/0001.vector/front.cc index b47ca738d..2a6cd353f 100644 --- a/tests/0026.container/0001.vector/front.cc +++ b/tests/0026.container/0001.vector/front.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -12,5 +11,5 @@ int main() { print("The first character is '", chvw(letters.front()), "'.\n"); } - assert(letters.front() == 'a'); + if (!(letters.front() == 'a')) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/insert.cc b/tests/0026.container/0001.vector/insert.cc index 62699205e..24be1fa28 100644 --- a/tests/0026.container/0001.vector/insert.cc +++ b/tests/0026.container/0001.vector/insert.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -14,14 +13,14 @@ int main() { fast_io::vector c1(3, 100); print_info(1, c1); - assert(c1.size() == 3); - assert(c1[0] == 100 && c1[1] == 100 && c1[2] == 100); + if (!(c1.size() == 3)) ::fast_io::fast_terminate(); + if (!(c1[0] == 100 && c1[1] == 100 && c1[2] == 100)) ::fast_io::fast_terminate(); auto it = c1.begin(); it = c1.insert(it, 200); - assert(*it == 200); - assert(c1.size() == 4); - assert(c1[0] == 200); + if (!(*it == 200)) ::fast_io::fast_terminate(); + if (!(c1.size() == 4)) ::fast_io::fast_terminate(); + if (!(c1[0] == 200)) ::fast_io::fast_terminate(); print_info(2, c1); #if 0 c1.insert(it, 2, 300); diff --git a/tests/0026.container/0001.vector/insert_range.cc b/tests/0026.container/0001.vector/insert_range.cc index 105c87811..1cadb6669 100644 --- a/tests/0026.container/0001.vector/insert_range.cc +++ b/tests/0026.container/0001.vector/insert_range.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -12,10 +11,10 @@ int main() #if 0 auto container = fast_io::vector{1, 2, 3, 4}; auto pos = std::next(container.begin(), 2); - assert(*pos == 3); + if (!(*pos == 3)) ::fast_io::fast_terminate(); auto const rg = std::list{-1, -2, -3}; container.insert_range(pos, rg); - assert(std::ranges::equal(container, fast_io::vector{1, 2, -1, -2, -3, 3, 4})); + if (!(std::ranges::equal(container, fast_io::vector{1, 2, -1, -2, -3, 3, 4}))) ::fast_io::fast_terminate(); #endif } \ No newline at end of file diff --git a/tests/0026.container/0001.vector/operator_assign.cc b/tests/0026.container/0001.vector/operator_assign.cc index 9595c942d..817bd6097 100644 --- a/tests/0026.container/0001.vector/operator_assign.cc +++ b/tests/0026.container/0001.vector/operator_assign.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -12,23 +11,23 @@ int main() print("Initially:\n"); print("x = {", rgvw(x, ", "), "}\ny = {", rgvw(y, ", "), "}\nz = {", rgvw(z, ", "), "}\n"); - assert(x.size() == 3); - assert(y.empty()); - assert(z.empty()); + if (!(x.size() == 3)) ::fast_io::fast_terminate(); + if (!(y.empty())) ::fast_io::fast_terminate(); + if (!(z.empty())) ::fast_io::fast_terminate(); print("Copy assignment copies data from x to y:\n"); y = x; print("x = {", rgvw(x, ", "), "}\ny = {", rgvw(y, ", "), "}\n"); - assert(y.size() == 3); - assert(y[0] == 1 && y[1] == 2 && y[2] == 3); + if (!(y.size() == 3)) ::fast_io::fast_terminate(); + if (!(y[0] == 1 && y[1] == 2 && y[2] == 3)) ::fast_io::fast_terminate(); print("Move assignment moves data from x to z, modifying both x and z:\n"); z = std::move(x); print("x = {", rgvw(x, ", "), "}\nz = {", rgvw(z, ", "), "}\n"); - assert(z.size() == 3); - assert(z[0] == 1 && z[1] == 2 && z[2] == 3); + if (!(z.size() == 3)) ::fast_io::fast_terminate(); + if (!(z[0] == 1 && z[1] == 2 && z[2] == 3)) ::fast_io::fast_terminate(); // After move, source vector should be empty - assert(x.empty()); + if (!(x.empty())) ::fast_io::fast_terminate(); #if 0 auto const w = {4, 5, 6, 7}; diff --git a/tests/0026.container/0001.vector/operator_at.cc b/tests/0026.container/0001.vector/operator_at.cc index c82c411c2..2f0d64ca4 100644 --- a/tests/0026.container/0001.vector/operator_at.cc +++ b/tests/0026.container/0001.vector/operator_at.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -9,13 +8,13 @@ int main() fast_io::vector numbers{2, 4, 6, 8}; print("Second element: ", numbers[1], "\n"); - assert(numbers[1] == 4); + if (!(numbers[1] == 4)) ::fast_io::fast_terminate(); numbers[0] = 5; - assert(numbers[0] == 5); + if (!(numbers[0] == 5)) ::fast_io::fast_terminate(); println("All numbers: ", rgvw(numbers, " ")); - assert(numbers[0] == 5 && numbers[1] == 4 && numbers[2] == 6 && numbers[3] == 8); + if (!(numbers[0] == 5 && numbers[1] == 4 && numbers[2] == 6 && numbers[3] == 8)) ::fast_io::fast_terminate(); } // Gets the sum of all primes in [0, N) using sieve of Eratosthenes diff --git a/tests/0026.container/0001.vector/operator_cmp.cc b/tests/0026.container/0001.vector/operator_cmp.cc index 8f7ebca21..b6509e3c6 100644 --- a/tests/0026.container/0001.vector/operator_cmp.cc +++ b/tests/0026.container/0001.vector/operator_cmp.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -12,7 +11,7 @@ int main() b{1, 2, 3}, c{7, 8, 9, 10}; - assert("" + if (!("" "Compare equal containers:" && (a != b) == false && (a == b) == true && @@ -40,5 +39,5 @@ int main() (a <=> c) < 0 && (a <=> c) != 0 && (a <=> c) <= 0 && - ""); + "")) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/pop_back.cc b/tests/0026.container/0001.vector/pop_back.cc index 5d1e3b265..28e5691a1 100644 --- a/tests/0026.container/0001.vector/pop_back.cc +++ b/tests/0026.container/0001.vector/pop_back.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -19,16 +18,16 @@ int main() numbers.push_back(5); numbers.push_back(3); numbers.push_back(4); - assert(numbers.size() == 3); - assert(numbers[0] == 5); - assert(numbers[1] == 3); - assert(numbers[2] == 4); + if (!(numbers.size() == 3)) ::fast_io::fast_terminate(); + if (!(numbers[0] == 5)) ::fast_io::fast_terminate(); + if (!(numbers[1] == 3)) ::fast_io::fast_terminate(); + if (!(numbers[2] == 4)) ::fast_io::fast_terminate(); print_info(numbers); numbers.pop_back(); - assert(numbers.size() == 2); - assert(numbers.back() == 3); + if (!(numbers.size() == 2)) ::fast_io::fast_terminate(); + if (!(numbers.back() == 3)) ::fast_io::fast_terminate(); print_info(numbers); } diff --git a/tests/0026.container/0001.vector/push_back.cc b/tests/0026.container/0001.vector/push_back.cc index 6963ce66d..474d01c95 100644 --- a/tests/0026.container/0001.vector/push_back.cc +++ b/tests/0026.container/0001.vector/push_back.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -13,9 +12,9 @@ int main() std::string s{"def"}; letters.push_back(std::move(s)); - assert(letters.size() == 2); - assert(letters[0] == "abc"); - assert(letters[1] == "def"); + if (!(letters.size() == 2)) ::fast_io::fast_terminate(); + if (!(letters[0] == "abc")) ::fast_io::fast_terminate(); + if (!(letters[1] == "def")) ::fast_io::fast_terminate(); print("std::vector letters holds: "); for (auto &&e : letters) diff --git a/tests/0026.container/0001.vector/shared_ptr_index.cc b/tests/0026.container/0001.vector/shared_ptr_index.cc index 070765bbe..eaf1d9b95 100644 --- a/tests/0026.container/0001.vector/shared_ptr_index.cc +++ b/tests/0026.container/0001.vector/shared_ptr_index.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -17,14 +16,14 @@ struct is_trivially_copyable_or_relocatable<::std::shared_ptr> int main() { ::fast_io::vector<::std::shared_ptr> vec{std::make_shared(1), std::make_shared(2), std::make_shared(3)}; - assert(vec.size() == 3); + if (!(vec.size() == 3)) ::fast_io::fast_terminate(); vec.insert_index(1, std::make_shared(4)); - assert(vec.size() == 4); - assert(*vec[0] == 1); - assert(*vec[1] == 4); - assert(*vec[2] == 2); - assert(*vec[3] == 3); - assert(vec[1].use_count() == 1); + if (!(vec.size() == 4)) ::fast_io::fast_terminate(); + if (!(*vec[0] == 1)) ::fast_io::fast_terminate(); + if (!(*vec[1] == 4)) ::fast_io::fast_terminate(); + if (!(*vec[2] == 2)) ::fast_io::fast_terminate(); + if (!(*vec[3] == 3)) ::fast_io::fast_terminate(); + if (!(vec[1].use_count() == 1)) ::fast_io::fast_terminate(); using namespace ::fast_io::io; print("After vec.insert_index(1)\n"); for (auto const &e : vec) @@ -32,9 +31,9 @@ int main() println(::fast_io::mnp::pointervw(e.get()), " use_count: ", e.use_count()); } vec.erase_index(0, 2); - assert(vec.size() == 2); - assert(*vec[0] == 2); - assert(*vec[1] == 3); + if (!(vec.size() == 2)) ::fast_io::fast_terminate(); + if (!(*vec[0] == 2)) ::fast_io::fast_terminate(); + if (!(*vec[1] == 3)) ::fast_io::fast_terminate(); print("After vec.erase_index(0,2)\n"); for (auto const &e : vec) { diff --git a/tests/0026.container/0001.vector/shared_ptr_index_not_trivial.cc b/tests/0026.container/0001.vector/shared_ptr_index_not_trivial.cc index 6cc34aa9a..b78a17328 100644 --- a/tests/0026.container/0001.vector/shared_ptr_index_not_trivial.cc +++ b/tests/0026.container/0001.vector/shared_ptr_index_not_trivial.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -6,13 +5,13 @@ int main() { ::fast_io::vector<::std::shared_ptr> vec{std::make_shared(1), std::make_shared(2), std::make_shared(3)}; - assert(vec.size() == 3); + if (!(vec.size() == 3)) ::fast_io::fast_terminate(); vec.insert_index(1, std::make_shared(4)); - assert(vec.size() == 4); - assert(*vec[0] == 1); - assert(*vec[1] == 4); - assert(*vec[2] == 2); - assert(*vec[3] == 3); + if (!(vec.size() == 4)) ::fast_io::fast_terminate(); + if (!(*vec[0] == 1)) ::fast_io::fast_terminate(); + if (!(*vec[1] == 4)) ::fast_io::fast_terminate(); + if (!(*vec[2] == 2)) ::fast_io::fast_terminate(); + if (!(*vec[3] == 3)) ::fast_io::fast_terminate(); using namespace ::fast_io::io; print("After vec.insert_index(1)\n"); for (auto const &e : vec) @@ -20,9 +19,9 @@ int main() println(::fast_io::mnp::pointervw(e.get()), " use_count: ", e.use_count()); } vec.erase_index(0, 2); - assert(vec.size() == 2); - assert(*vec[0] == 2); - assert(*vec[1] == 3); + if (!(vec.size() == 2)) ::fast_io::fast_terminate(); + if (!(*vec[0] == 2)) ::fast_io::fast_terminate(); + if (!(*vec[1] == 3)) ::fast_io::fast_terminate(); print("After vec.erase_index(0,2)\n"); for (auto const &e : vec) { diff --git a/tests/0026.container/0001.vector/shrink_to_fit.cc b/tests/0026.container/0001.vector/shrink_to_fit.cc index 15acfd107..b2df41b55 100644 --- a/tests/0026.container/0001.vector/shrink_to_fit.cc +++ b/tests/0026.container/0001.vector/shrink_to_fit.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -8,18 +7,18 @@ int main() { fast_io::vector v; println("Default-constructed capacity is ", v.capacity()); - assert(v.capacity() == 0); + if (!(v.capacity() == 0)) ::fast_io::fast_terminate(); v.resize(100); println("Capacity of a 100-element vector is ", v.capacity()); - assert(v.capacity() >= 100); + if (!(v.capacity() >= 100)) ::fast_io::fast_terminate(); auto old_cap = v.capacity(); v.resize(50); println("Capacity after resize(50) is ", v.capacity()); - assert(v.capacity() == old_cap); + if (!(v.capacity() == old_cap)) ::fast_io::fast_terminate(); v.shrink_to_fit(); println("Capacity after shrink_to_fit() is ", v.capacity()); - assert(v.size() == 50); - assert(v.capacity() >= 50); + if (!(v.size() == 50)) ::fast_io::fast_terminate(); + if (!(v.capacity() >= 50)) ::fast_io::fast_terminate(); v.clear(); println("Capacity after clear() is ", v.capacity()); v.shrink_to_fit(); @@ -29,8 +28,8 @@ int main() v.push_back(i); } println("Capacity after adding 300 elements is ", v.capacity()); - assert(v.size() == 300); + if (!(v.size() == 300)) ::fast_io::fast_terminate(); v.shrink_to_fit(); println("Capacity after shrink_to_fit() is ", v.capacity()); - assert(v.capacity() >= 300); + if (!(v.capacity() >= 300)) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/size.cc b/tests/0026.container/0001.vector/size.cc index a34efca6a..7f9457519 100644 --- a/tests/0026.container/0001.vector/size.cc +++ b/tests/0026.container/0001.vector/size.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -9,5 +8,5 @@ int main() fast_io::vector nums{1, 3, 5, 7}; print("nums contains ", nums.size(), " elements.\n"); - assert(nums.size() == 4); + if (!(nums.size() == 4)) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/swap.cc b/tests/0026.container/0001.vector/swap.cc index fbb3ee5c1..8fa9b209b 100644 --- a/tests/0026.container/0001.vector/swap.cc +++ b/tests/0026.container/0001.vector/swap.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -7,9 +6,9 @@ using namespace fast_io::mnp; int main() { fast_io::vector a1{1, 2, 3}, a2{4, 5}; - assert(a1.size() == 3 && a2.size() == 2); - assert(a1[0] == 1 && a1[1] == 2 && a1[2] == 3); - assert(a2[0] == 4 && a2[1] == 5); + if (!(a1.size() == 3 && a2.size() == 2)) ::fast_io::fast_terminate(); + if (!(a1[0] == 1 && a1[1] == 2 && a1[2] == 3)) ::fast_io::fast_terminate(); + if (!(a2[0] == 4 && a2[1] == 5)) ::fast_io::fast_terminate(); auto it1 = std::next(a1.begin()); auto it2 = std::next(a2.begin()); @@ -21,9 +20,9 @@ int main() a1.swap(a2); perrln("{ ", rgvw(a1, " "), " } { ", rgvw(a2, " "), " } ", *it1, " ", *it2, " ", ref1, ' ', ref2); - assert(a1.size() == 2 && a2.size() == 3); - assert(a1[0] == 4 && a1[1] == 5); - assert(a2[0] == 1 && a2[1] == 2 && a2[2] == 3); + if (!(a1.size() == 2 && a2.size() == 3)) ::fast_io::fast_terminate(); + if (!(a1[0] == 4 && a1[1] == 5)) ::fast_io::fast_terminate(); + if (!(a2[0] == 1 && a2[1] == 2 && a2[2] == 3)) ::fast_io::fast_terminate(); // Note that after swap the iterators and references stay associated with their // original elements, e.g. it1 that pointed to an element in 'a1' with value 2 diff --git a/tests/0026.container/0001.vector/vector.cc b/tests/0026.container/0001.vector/vector.cc index 8618af9b2..16603060d 100644 --- a/tests/0026.container/0001.vector/vector.cc +++ b/tests/0026.container/0001.vector/vector.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -10,12 +9,12 @@ int main() // C++11 initializer list syntax: fast_io::vector words1{"the", "frogurt", "is", "also", "cursed"}; print("1: {", rgvw(words1, ", "), "}\n"); - assert(words1.size() == 5); - assert(words1[0] == "the"); - assert(words1[1] == "frogurt"); - assert(words1[2] == "is"); - assert(words1[3] == "also"); - assert(words1[4] == "cursed"); + if (!(words1.size() == 5)) ::fast_io::fast_terminate(); + if (!(words1[0] == "the")) ::fast_io::fast_terminate(); + if (!(words1[1] == "frogurt")) ::fast_io::fast_terminate(); + if (!(words1[2] == "is")) ::fast_io::fast_terminate(); + if (!(words1[3] == "also")) ::fast_io::fast_terminate(); + if (!(words1[4] == "cursed")) ::fast_io::fast_terminate(); #if 0 // words2 == words1 fast_io::vector words2(::std::from_range, words1); @@ -24,13 +23,13 @@ int main() // words3 == words1 fast_io::vector words3(words1); print("3: {", rgvw(words3, ", "), "}\n"); - assert(words3 == words1); + if (!(words3 == words1)) ::fast_io::fast_terminate(); // words4 is {"Mo", "Mo", "Mo", "Mo", "Mo"} fast_io::vector words4(5, "Mo"); print("4: {", rgvw(words4, ", "), "}\n"); - assert(words4.size() == 5); - for (auto const &w : words4) assert(w == "Mo"); + if (!(words4.size() == 5)) ::fast_io::fast_terminate(); + for (auto const &w : words4) if (!(w == "Mo")) ::fast_io::fast_terminate(); #if 0 auto const rg = {"cat", "cow", "crow"}; fast_io::vector words5(::std::from_range, rg); // overload (11) diff --git a/tests/0026.container/0001.vector/vector_allocate_at_least.cc b/tests/0026.container/0001.vector/vector_allocate_at_least.cc index 906438ac7..3216c5080 100644 --- a/tests/0026.container/0001.vector/vector_allocate_at_least.cc +++ b/tests/0026.container/0001.vector/vector_allocate_at_least.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -8,12 +7,12 @@ int main() { fast_io::vector<::std::size_t> vec; println("Before vec.push_back(50): vec.size()=",vec.size()," vec.capacity()=",vec.capacity()); - assert(vec.size() == 0); - assert(vec.capacity() == 0); + if (!(vec.size() == 0)) ::fast_io::fast_terminate(); + if (!(vec.capacity() == 0)) ::fast_io::fast_terminate(); vec.push_back(50); vec.push_back(50); println("After vec.push_back(50): vec.size()=",vec.size()," vec.capacity()=",vec.capacity()); - assert(vec.size() == 2); - assert(vec[0] == 50); - assert(vec[1] == 50); + if (!(vec.size() == 2)) ::fast_io::fast_terminate(); + if (!(vec[0] == 50)) ::fast_io::fast_terminate(); + if (!(vec[1] == 50)) ::fast_io::fast_terminate(); } diff --git a/tests/0026.container/0001.vector/vector_deduction.cc b/tests/0026.container/0001.vector/vector_deduction.cc index 01ea0de84..8c26e765c 100644 --- a/tests/0026.container/0001.vector/vector_deduction.cc +++ b/tests/0026.container/0001.vector/vector_deduction.cc @@ -1,4 +1,3 @@ -#include #include #include using namespace fast_io::io; @@ -8,15 +7,15 @@ int main() { fast_io::vector vec{static_cast<::std::uint_least32_t>(1), 6, 10, 20}; println("Before vec.push_back(50): vec.size()=", vec.size(), " vec.capacity()=", vec.capacity()); - assert(vec.size() == 4); - assert(vec[0] == 1); - assert(vec[1] == 6); - assert(vec[2] == 10); - assert(vec[3] == 20); + if (!(vec.size() == 4)) ::fast_io::fast_terminate(); + if (!(vec[0] == 1)) ::fast_io::fast_terminate(); + if (!(vec[1] == 6)) ::fast_io::fast_terminate(); + if (!(vec[2] == 10)) ::fast_io::fast_terminate(); + if (!(vec[3] == 20)) ::fast_io::fast_terminate(); vec.push_back(50); vec.push_back(50); println("After vec.push_back(50): vec.size()=", vec.size(), " vec.capacity()=", vec.capacity()); - assert(vec.size() == 6); - assert(vec[4] == 50); - assert(vec[5] == 50); + if (!(vec.size() == 6)) ::fast_io::fast_terminate(); + if (!(vec[4] == 50)) ::fast_io::fast_terminate(); + if (!(vec[5] == 50)) ::fast_io::fast_terminate(); }