Updated details::circular_q and added some tests for it

This commit is contained in:
gabime 2023-09-01 12:49:07 +03:00
parent 202260719f
commit 820baa886c

View File

@ -2,12 +2,14 @@
#include "spdlog/details/circular_q.h" #include "spdlog/details/circular_q.h"
using q_type = spdlog::details::circular_q<size_t>; using q_type = spdlog::details::circular_q<size_t>;
TEST_CASE("test_size", "[circular_q]") TEST_CASE("test_size", "[circular_q]")
{ {
const size_t q_size = 4; const size_t q_size = 4;
q_type q(q_size); q_type q(q_size);
REQUIRE(q.size() == 0); REQUIRE(q.size() == 0);
REQUIRE(q.empty() == true); REQUIRE(q.empty() == true);
REQUIRE(q.full() == false);
for (size_t i = 0; i < q_size; i++) for (size_t i = 0; i < q_size; i++)
{ {
q.push_back(std::move(i)); q.push_back(std::move(i));
@ -49,7 +51,75 @@ TEST_CASE("test_rolling", "[circular_q]")
TEST_CASE("test_empty", "[circular_q]") TEST_CASE("test_empty", "[circular_q]")
{ {
q_type q(0); q_type q1(0);
q.push_back(1); REQUIRE(q1.empty());
REQUIRE(q.empty()); q1.push_back(1);
REQUIRE(q1.empty());
q_type q2(1);
REQUIRE(q2.empty());
q2.push_back(1);
REQUIRE(!q2.empty());
q2.pop_front();
REQUIRE(q2.empty());
} }
TEST_CASE("test_full", "[circular_q]")
{
q_type q1(0);
REQUIRE(q1.full());
q_type q2(2);
REQUIRE(!q2.full());
q2.push_back(1);
REQUIRE(!q2.full());
q2.push_back(2);
REQUIRE(q2.full());
}
TEST_CASE("test_operator[]", "[circular_q]")
{
q_type q(2);
q.push_back(100);
q.push_back(200);
REQUIRE(q[0] == 100);
REQUIRE(q[1] == 200);
}
TEST_CASE("test_operator=", "[circular_q]")
{
q_type q1(2);
q1.push_back(100);
q1.push_back(200);
q_type q2 = q1;
REQUIRE(q2.size() == 2);
REQUIRE(q2[0] == 100);
REQUIRE(q2[1] == 200);
}
TEST_CASE("test_front", "[circular_q]")
{
q_type q(2);
q.push_back(100);
q.push_back(200);
REQUIRE(q.front() == 100);
}
TEST_CASE("test_overrun_counter", "[circular_q]")
{
q_type q(2);
REQUIRE(q.overrun_counter() == 0);
for(size_t i=0; i<10; i++)
{
q.push_back(100);
}
REQUIRE(q.overrun_counter() == 8);
}