uncomment folly tests

This commit is contained in:
Bechir 2024-03-28 15:25:10 +01:00
parent 04cbe9924e
commit d87855004f
2 changed files with 138 additions and 138 deletions

View File

@ -1,116 +1,116 @@
// #include <catch2/catch_all.hpp> #include <catch2/catch_all.hpp>
// #include "aare/CircularFifo.hpp" #include "aare/CircularFifo.hpp"
// using aare::CircularFifo; using aare::CircularFifo;
// // Only for testing. To make sure we can avoid copy constructor // Only for testing. To make sure we can avoid copy constructor
// // and copy assignment // and copy assignment
// struct MoveOnlyInt { struct MoveOnlyInt {
// int value{}; int value{};
// MoveOnlyInt() = default; MoveOnlyInt() = default;
// MoveOnlyInt(int i) : value(i){}; MoveOnlyInt(int i) : value(i){};
// MoveOnlyInt(const MoveOnlyInt &) = delete; MoveOnlyInt(const MoveOnlyInt &) = delete;
// MoveOnlyInt &operator=(const MoveOnlyInt &) = delete; MoveOnlyInt &operator=(const MoveOnlyInt &) = delete;
// MoveOnlyInt(MoveOnlyInt &&other) { std::swap(value, other.value); } MoveOnlyInt(MoveOnlyInt &&other) { std::swap(value, other.value); }
// MoveOnlyInt &operator=(MoveOnlyInt &&other) { MoveOnlyInt &operator=(MoveOnlyInt &&other) {
// std::swap(value, other.value); std::swap(value, other.value);
// return *this; return *this;
// } }
// bool operator==(int other) const { return value == other; } bool operator==(int other) const { return value == other; }
// }; };
// TEST_CASE("CircularFifo can be default constructed") { CircularFifo<MoveOnlyInt> f; } TEST_CASE("CircularFifo can be default constructed") { CircularFifo<MoveOnlyInt> f; }
// TEST_CASE("Newly constructed fifo has the right size") { TEST_CASE("Newly constructed fifo has the right size") {
// size_t size = 17; size_t size = 17;
// CircularFifo<MoveOnlyInt> f(size); CircularFifo<MoveOnlyInt> f(size);
// CHECK(f.numFreeSlots() == size); CHECK(f.numFreeSlots() == size);
// CHECK(f.numFilledSlots() == 0); CHECK(f.numFilledSlots() == 0);
// } }
// TEST_CASE("Can fit size number of objects") { TEST_CASE("Can fit size number of objects") {
// size_t size = 8; size_t size = 8;
// size_t numPushedItems = 0; size_t numPushedItems = 0;
// CircularFifo<MoveOnlyInt> f(size); CircularFifo<MoveOnlyInt> f(size);
// for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
// MoveOnlyInt a; MoveOnlyInt a;
// bool popped = f.try_pop_free(a); bool popped = f.try_pop_free(a);
// CHECK(popped); CHECK(popped);
// if (popped) { if (popped) {
// a.value = i; a.value = i;
// bool pushed = f.try_push_value(std::move(a)); bool pushed = f.try_push_value(std::move(a));
// CHECK(pushed); CHECK(pushed);
// if (pushed) if (pushed)
// numPushedItems++; numPushedItems++;
// } }
// } }
// CHECK(f.numFreeSlots() == 0); CHECK(f.numFreeSlots() == 0);
// CHECK(f.numFilledSlots() == size); CHECK(f.numFilledSlots() == size);
// CHECK(numPushedItems == size); CHECK(numPushedItems == size);
// } }
// TEST_CASE("Push move only type") { TEST_CASE("Push move only type") {
// CircularFifo<MoveOnlyInt> f; CircularFifo<MoveOnlyInt> f;
// f.push_value(5); f.push_value(5);
// } }
// TEST_CASE("Push pop") { TEST_CASE("Push pop") {
// CircularFifo<MoveOnlyInt> f; CircularFifo<MoveOnlyInt> f;
// f.push_value(MoveOnlyInt(1)); f.push_value(MoveOnlyInt(1));
// auto a = f.pop_value(); auto a = f.pop_value();
// CHECK(a == 1); CHECK(a == 1);
// } }
// TEST_CASE("Pop free and then push") { TEST_CASE("Pop free and then push") {
// CircularFifo<MoveOnlyInt> f; CircularFifo<MoveOnlyInt> f;
// auto a = f.pop_free(); auto a = f.pop_free();
// a.value = 5; a.value = 5;
// f.push_value(std::move(a)); // Explicit move since we can't copy f.push_value(std::move(a)); // Explicit move since we can't copy
// auto b = f.pop_value(); auto b = f.pop_value();
// CHECK(a == 0); // Moved from value CHECK(a == 0); // Moved from value
// CHECK(b == 5); // Original value CHECK(b == 5); // Original value
// } }
// TEST_CASE("Skip the first value") { TEST_CASE("Skip the first value") {
// CircularFifo<MoveOnlyInt> f; CircularFifo<MoveOnlyInt> f;
// for (int i = 0; i != 10; ++i) { for (int i = 0; i != 10; ++i) {
// auto a = f.pop_free(); auto a = f.pop_free();
// a.value = i + 1; a.value = i + 1;
// f.push_value(std::move(a)); // Explicit move since we can't copy f.push_value(std::move(a)); // Explicit move since we can't copy
// } }
// auto b = f.pop_value(); auto b = f.pop_value();
// CHECK(b == 1); CHECK(b == 1);
// f.next(); f.next();
// auto c = f.pop_value(); auto c = f.pop_value();
// CHECK(c == 3); CHECK(c == 3);
// } }
// TEST_CASE("Use in place and move to free") { TEST_CASE("Use in place and move to free") {
// size_t size = 18; size_t size = 18;
// CircularFifo<MoveOnlyInt> f(size); CircularFifo<MoveOnlyInt> f(size);
// //Push 10 values to the fifo //Push 10 values to the fifo
// for (int i = 0; i != 10; ++i) { for (int i = 0; i != 10; ++i) {
// auto a = f.pop_free(); auto a = f.pop_free();
// a.value = i + 1; a.value = i + 1;
// f.push_value(std::move(a)); // Explicit move since we can't copy f.push_value(std::move(a)); // Explicit move since we can't copy
// } }
// auto b = f.frontPtr(); auto b = f.frontPtr();
// CHECK(*b == 1); CHECK(*b == 1);
// CHECK(f.numFilledSlots() == 10); CHECK(f.numFilledSlots() == 10);
// CHECK(f.numFreeSlots() == size-10); CHECK(f.numFreeSlots() == size-10);
// f.next(); f.next();
// auto c = f.frontPtr(); auto c = f.frontPtr();
// CHECK(*c == 2); CHECK(*c == 2);
// CHECK(f.numFilledSlots() == 9); CHECK(f.numFilledSlots() == 9);
// CHECK(f.numFreeSlots() == size-9); CHECK(f.numFreeSlots() == size-9);
// } }

View File

@ -1,49 +1,49 @@
// #include <catch2/catch_all.hpp> #include <catch2/catch_all.hpp>
// #include "aare/ProducerConsumerQueue.hpp" #include "aare/ProducerConsumerQueue.hpp"
// // using arve::SimpleQueue; // using arve::SimpleQueue;
// TEST_CASE("push pop"){ TEST_CASE("push pop"){
// folly::ProducerConsumerQueue<int> q(5); folly::ProducerConsumerQueue<int> q(5);
// int a = 3; int a = 3;
// int b = 8; int b = 8;
// CHECK(q.sizeGuess() == 0); CHECK(q.sizeGuess() == 0);
// CHECK(q.write(a)); CHECK(q.write(a));
// CHECK(q.sizeGuess() == 1); CHECK(q.sizeGuess() == 1);
// CHECK(q.write(b)); CHECK(q.write(b));
// CHECK(q.sizeGuess() == 2); CHECK(q.sizeGuess() == 2);
// int c = 0; int c = 0;
// CHECK(q.read(c)); CHECK(q.read(c));
// CHECK(c == 3); CHECK(c == 3);
// CHECK(q.sizeGuess() == 1); CHECK(q.sizeGuess() == 1);
// CHECK(q.read(c)); CHECK(q.read(c));
// CHECK(c == 8); CHECK(c == 8);
// CHECK(q.sizeGuess() == 0); CHECK(q.sizeGuess() == 0);
// } }
// TEST_CASE("Cannot push to a full queue"){ TEST_CASE("Cannot push to a full queue"){
// folly::ProducerConsumerQueue<int> q(3); folly::ProducerConsumerQueue<int> q(3);
// int a = 3; int a = 3;
// int b = 4; int b = 4;
// int c = 0; int c = 0;
// CHECK(q.write(a)); CHECK(q.write(a));
// CHECK(q.write(b)); CHECK(q.write(b));
// CHECK_FALSE(q.write(a)); CHECK_FALSE(q.write(a));
// //values are still ok //values are still ok
// CHECK(q.read(c)); CHECK(q.read(c));
// CHECK(c == 3); CHECK(c == 3);
// CHECK(q.read(c)); CHECK(q.read(c));
// CHECK(c == 4); CHECK(c == 4);
// } }
// TEST_CASE("Cannot pop from an empty queue"){ TEST_CASE("Cannot pop from an empty queue"){
// folly::ProducerConsumerQueue<int> q(2); folly::ProducerConsumerQueue<int> q(2);
// int a=0; int a=0;
// CHECK_FALSE(q.read(a)); CHECK_FALSE(q.read(a));
// } }
// // TEST_CASE("fail"){ // TEST_CASE("fail"){
// // CHECK(false); // CHECK(false);
// // } // }