mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Fixed circular_q size impl and added tests
This commit is contained in:
parent
371bc8ebe2
commit
bffceb90b0
@ -82,7 +82,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
return max_items_ - 1 - (head_ - tail_);
|
||||
return max_items_ - (head_ - tail_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,9 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
test_custom_callbacks.cpp
|
||||
test_cfg.cpp
|
||||
test_time_point.cpp
|
||||
test_stopwatch.cpp)
|
||||
test_stopwatch.cpp
|
||||
test_circular_q.cpp
|
||||
)
|
||||
|
||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||
|
48
tests/test_circular_q.cpp
Normal file
48
tests/test_circular_q.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "includes.h"
|
||||
#include "spdlog/details/circular_q.h"
|
||||
|
||||
using q_type = spdlog::details::circular_q<int>;
|
||||
TEST_CASE("test_size", "[circular_q]")
|
||||
{
|
||||
size_t q_size = 4;
|
||||
q_type q(q_size);
|
||||
REQUIRE(q.size() == 0);
|
||||
REQUIRE(q.empty() == true);
|
||||
for (int i = 0; i < q_size; i++)
|
||||
{
|
||||
q.push_back(std::move(i));
|
||||
}
|
||||
REQUIRE(q.size() == q_size);
|
||||
q.push_back(999);
|
||||
REQUIRE(q.size() == q_size);
|
||||
}
|
||||
|
||||
TEST_CASE("test_rolling", "[circular_q]")
|
||||
{
|
||||
const size_t q_size = 4;
|
||||
q_type q(q_size);
|
||||
|
||||
for (size_t i = 0; i < q_size + 2; i++)
|
||||
{
|
||||
q.push_back(i);
|
||||
}
|
||||
|
||||
REQUIRE(q.size() == q_size);
|
||||
|
||||
REQUIRE(q.front() == 2);
|
||||
q.pop_front();
|
||||
|
||||
REQUIRE(q.front() == 3);
|
||||
q.pop_front();
|
||||
|
||||
REQUIRE(q.front() == 4);
|
||||
q.pop_front();
|
||||
|
||||
REQUIRE(q.front() == 5);
|
||||
q.pop_front();
|
||||
|
||||
REQUIRE(q.empty());
|
||||
|
||||
q.push_back(6);
|
||||
REQUIRE(q.front() == 6);
|
||||
}
|
Loading…
Reference in New Issue
Block a user