Source File: ex61.cpp
#include <fmt/core.h>
#include <chrono>
#include <thread>
#include <string>
#include <cassert>
#include <functional>
#include <fuc2/testing.hpp>
#include <fuc2/run.hpp>
#include "ex61_dlist.hpp"
using namespace fuc2;
void test_push_pop_back() {
DList<int> ages;
for(int i = 0; i < 5; i++) {
ages.push_back(i * 34);
}
CHECK(ages.count() == 5, "wrong count");
for(int i = 0; i < 5; i++) {
auto res = ages.pop_back();
fmt::println("pop_back: {}, count: {}", res, ages.count());
}
EQUAL(ages.count(), 0, "wrong count");
NOT_EQUAL(ages.count(), 5, "wrong count");
}
void test_push_pop_front() {
DList<float> ages;
for(int i = 0; i < 5; i++) {
ages.push_front(i * 34);
}
CHECK(ages.count() == 5, "should have 5");
for(int i = 0; i < 5; i++) {
auto res = ages.pop_front();
fmt::println("pop_front: {}, count: {}", res, ages.count());
}
EQUAL(ages.count(), 0, "should be empty");
}
void test_push_blows_up() {
DList<float> ages;
auto runner = [&]() {
ages.pop_front();
};
BLOWS_UP(runner, "pop_front empty should crash");
}
int main(int argc, char* argv[]) {
return run({
.name="DList basic operations",
.options={ .fail_fast=false },
.tests={
TEST(test_push_pop_back),
TEST(test_push_pop_front),
TEST(test_push_blows_up),
}
}, {}, false);
}