You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.3 KiB
67 lines
1.3 KiB
|
12 hours ago
|
#include <fmt/core.h>
|
||
|
|
#include <deque>
|
||
|
|
#include <string>
|
||
|
|
#include <fuc2.hpp>
|
||
|
|
|
||
|
|
using namespace fuc2;
|
||
|
|
|
||
|
|
void test_push_pop_back() {
|
||
|
|
std::deque<int> ages;
|
||
|
|
|
||
|
|
for(int i = 0; i < 5; i++) {
|
||
|
|
ages.push_back(i * 34);
|
||
|
|
}
|
||
|
|
|
||
|
|
CHECK(ages.size() == 5, "wrong count");
|
||
|
|
|
||
|
|
for(int i = 0; i < 5; i++) {
|
||
|
|
ages.pop_back();
|
||
|
|
fmt::println("count: {}", ages.size());
|
||
|
|
}
|
||
|
|
|
||
|
|
EQUAL(ages.size(), size_t(0), "wrong count");
|
||
|
|
NOT_EQUAL(ages.size(), size_t(5), "wrong count");
|
||
|
|
}
|
||
|
|
|
||
|
|
void test_push_pop_front() {
|
||
|
|
std::deque<float> ages;
|
||
|
|
|
||
|
|
for(int i = 0; i < 5; i++) {
|
||
|
|
ages.push_front(i * 34);
|
||
|
|
}
|
||
|
|
|
||
|
|
CHECK(ages.size() == 5, "wrong count");
|
||
|
|
|
||
|
|
for(int i = 0; i < 5; i++) {
|
||
|
|
ages.pop_front();
|
||
|
|
fmt::println("count: {}", ages.size());
|
||
|
|
}
|
||
|
|
|
||
|
|
NOT_EQUAL(ages.size(), size_t(0), "wrong count");
|
||
|
|
}
|
||
|
|
|
||
|
|
void test_push_blows_up() {
|
||
|
|
std::deque<float> ages;
|
||
|
|
|
||
|
|
auto runner = [&]() {
|
||
|
|
// uncomment this to see how the C++ stdlib sabotages you
|
||
|
|
// ages.pop_front();
|
||
|
|
|
||
|
|
ages.at(10);
|
||
|
|
};
|
||
|
|
|
||
|
|
BLOWS_UP(runner, "pop_front empty should crash");
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char* argv[]) {
|
||
|
|
return run({
|
||
|
|
.name="std::deque basic operations",
|
||
|
|
.options={ .fail_fast=false },
|
||
|
|
.tests={
|
||
|
|
{"push_pop_back", test_push_pop_back},
|
||
|
|
{"push_pop_front", test_push_pop_front},
|
||
|
|
{"push_blows_up", test_push_blows_up},
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|