Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions tests/0026.container/0001.vector/append_range.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <cassert>
#include <algorithm>
#include <list>
#include <fast_io.h>
Expand All @@ -8,10 +7,8 @@ using namespace fast_io::mnp;

int main()
{
#if 0
auto head = fast_io::vector<int>{1, 2, 3, 4};
auto const tail = std::list{-5, -6, -7};
head.append_range(tail);
assert(std::ranges::equal(head, fast_io::vector<int>{1, 2, 3, 4, -5, -6, -7}));
#endif
}
if (!(std::ranges::equal(head, fast_io::vector<int>{1, 2, 3, 4, -5, -6, -7}))) ::fast_io::fast_terminate();
}
7 changes: 6 additions & 1 deletion tests/0026.container/0001.vector/assign.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <string>
#include <string>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
Expand All @@ -18,6 +18,11 @@ int main()
};

characters.assign(5, 'a');
if (!(characters.size() == 5)) ::fast_io::fast_terminate();
for (char c : characters)
{
if (!(c == 'a')) ::fast_io::fast_terminate();
}
print_vector();

#if 0
Expand Down
5 changes: 2 additions & 3 deletions tests/0026.container/0001.vector/assign_range.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <algorithm>
#include <cassert>
#include <algorithm>
#include <list>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
Expand All @@ -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
}
7 changes: 4 additions & 3 deletions tests/0026.container/0001.vector/back.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <fast_io.h>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
using namespace fast_io::mnp;
Expand All @@ -9,6 +9,7 @@ int main()

if (!letters.empty())
{
print("The first character is '", chvw(letters.back()), "'.\n");
print("The last character is '", chvw(letters.back()), "'.\n");
}
}
if (!(letters.back() == 'f')) ::fast_io::fast_terminate();
}
11 changes: 7 additions & 4 deletions tests/0026.container/0001.vector/begin.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <algorithm>
#include <algorithm>
#include <numeric>
#include <string>
#include <fast_io.h>
Expand All @@ -17,17 +17,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);
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());
if (!(*fruits.begin() == "orange")) ::fast_io::fast_terminate();
}

if (empty.begin() == empty.end())
{
print("vector 'empty' is indeed empty.\n");
}
}
if (!(empty.begin() == empty.end())) ::fast_io::fast_terminate();
}
8 changes: 6 additions & 2 deletions tests/0026.container/0001.vector/capacity.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <fast_io.h>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
using namespace fast_io::mnp;
Expand All @@ -10,18 +10,22 @@ int main()

auto cap = v.capacity();
println("Initial size: ", v.size(), ", capacity: ", cap);
if (!(v.size() == 0)) ::fast_io::fast_terminate();
if (!(v.capacity() == 0)) ::fast_io::fast_terminate();

print("\nDemonstrate the capacity's growth policy."
print("\nDemonstrate the capacity'\''s growth policy."
"\nSize: Capacity: Ratio:\n");
while (sz-- > 0)
{
v.push_back(sz);
if (cap != v.capacity())
{
println(left(v.size(), 7), left(v.capacity(), 11), left(float(v.capacity()) / static_cast<float>(cap), 10));
if (!(v.capacity() > cap)) ::fast_io::fast_terminate();
cap = v.capacity();
}
}

println("\nFinal size: ", v.size(), ", capacity: ", v.capacity());
if (!(v.size() == 100)) ::fast_io::fast_terminate();
}
8 changes: 6 additions & 2 deletions tests/0026.container/0001.vector/clear.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <string_view>
#include <string_view>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
Expand All @@ -13,6 +13,10 @@ int main()
{
fast_io::vector<int> container{1, 2, 3};
print_info("Before clear: ", container);
if (!(!container.empty())) ::fast_io::fast_terminate();
if (!(container.size() == 3)) ::fast_io::fast_terminate();
container.clear();
print_info("After clear: ", container);
}
if (!(container.empty())) ::fast_io::fast_terminate();
if (!(container.size() == 0)) ::fast_io::fast_terminate();
}
9 changes: 7 additions & 2 deletions tests/0026.container/0001.vector/data.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <cstddef>
#include <cstddef>
#include <span>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
Expand Down Expand Up @@ -29,4 +29,9 @@ int main()

// std::span (C++20) is a safer alternative to separated pointer/size.
span_func({container.data(), container.size()});
}

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();
}
6 changes: 5 additions & 1 deletion tests/0026.container/0001.vector/emplace.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <algorithm>
#include <algorithm>
#include <ranges>
#include <string>
#include <fast_io.h>
Expand Down Expand Up @@ -62,4 +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; }), " "));
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();
}
10 changes: 7 additions & 3 deletions tests/0026.container/0001.vector/emplace_index.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
#include <ranges>
#include <string>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
Expand All @@ -13,6 +10,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]
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);
Expand Down
6 changes: 4 additions & 2 deletions tests/0026.container/0001.vector/empty.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <fast_io.h>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
using namespace fast_io::mnp;
Expand All @@ -7,7 +7,9 @@ int main()
{
fast_io::vector<int> numbers;
println("Initially, numbers.empty(): ", boolalpha(numbers.empty()));
if (!(numbers.empty())) ::fast_io::fast_terminate();

numbers.push_back(42);
println("After adding elements, numbers.empty(): ", boolalpha(numbers.empty()));
}
if (!(!numbers.empty())) ::fast_io::fast_terminate();
}
11 changes: 7 additions & 4 deletions tests/0026.container/0001.vector/end.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <algorithm>
#include <algorithm>
#include <numeric>
#include <string>
#include <fast_io.h>
Expand All @@ -17,17 +17,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);
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());
if (!(*fruits.begin() == "orange")) ::fast_io::fast_terminate();
}

if (empty.begin() == empty.end())
{
print("vector 'empty' is indeed empty.\n");
}
}
if (!(empty.begin() == empty.end())) ::fast_io::fast_terminate();
}
13 changes: 11 additions & 2 deletions tests/0026.container/0001.vector/erase.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <fast_io.h>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
using namespace fast_io::mnp;
Expand All @@ -11,12 +11,18 @@ void print_container(fast_io::vector<int> const &c)
int main()
{
fast_io::vector<int> c{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
if (!(c.size() == 10)) ::fast_io::fast_terminate();
print_container(c);

c.erase(c.begin());
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)
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
Expand All @@ -31,5 +37,8 @@ int main()
++it;
}
}
// After erasing evens from [1,2,6,7,8,9]: [1,7,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);
}
}
15 changes: 12 additions & 3 deletions tests/0026.container/0001.vector/erase_index.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <fast_io.h>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
using namespace fast_io::mnp;
Expand All @@ -11,12 +11,19 @@ inline void print_container(fast_io::vector<int> const &c)
int main()
{
fast_io::vector<int> c{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
if (!(c.size() == 10)) ::fast_io::fast_terminate();
print_container(c);

c.erase_index(0);
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]
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
Expand All @@ -31,6 +38,8 @@ int main()
++i;
}
}

// After erasing evens from [1,2,6,7,8,9]: [1,7,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);
}
}
5 changes: 3 additions & 2 deletions tests/0026.container/0001.vector/front.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <fast_io.h>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
using namespace fast_io::mnp;
Expand All @@ -11,4 +11,5 @@ int main()
{
print("The first character is '", chvw(letters.front()), "'.\n");
}
}
if (!(letters.front() == 'a')) ::fast_io::fast_terminate();
}
9 changes: 7 additions & 2 deletions tests/0026.container/0001.vector/insert.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <iterator>
#include <iterator>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
Expand All @@ -13,9 +13,14 @@ int main()
{
fast_io::vector<int> c1(3, 100);
print_info(1, c1);
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);
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);
Expand All @@ -35,4 +40,4 @@ int main()
c1.insert(c1.end(), {601, 602, 603});
print_info(6, c1);
#endif
}
}
5 changes: 2 additions & 3 deletions tests/0026.container/0001.vector/insert_range.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <cassert>
#include <iterator>
#include <algorithm>
#include <list>
Expand All @@ -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
}
Loading
Loading