/* Copyright 2016-2021 Michele Santullo
* This file is part of "duckhandy".
*
* "duckhandy" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "duckhandy" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "duckhandy". If not, see .
*/
#include "catch2/catch.hpp"
#include "duckhandy/resource_pool.hpp"
#include
TEST_CASE ("Make operations on the ResourcePool", "[ResourcePool]") {
using dhandy::ResourcePool;
int callback_count = 0;
ResourcePool> vec_pool([&callback_count](int count) {
++callback_count;
std::vector nums(count);
for (int z = 0; z < count; ++z) {
nums[z] = z;
}
return nums;
});
{
auto vec_10 = vec_pool.make(10);
REQUIRE(vec_10->size() == 10);
for (int z = 0; z < 10; ++z) {
CHECK((*vec_10)[z] == z);
}
}
CHECK(1 == callback_count);
CHECK(vec_pool.size() == 1);
{
auto vec_10 = vec_pool.make(10);
REQUIRE(vec_10->size() == 10);
for (int z = 0; z < 10; ++z) {
CHECK((*vec_10)[z] == z);
}
}
CHECK(1 == callback_count);
CHECK(vec_pool.size() == 1);
{
auto vec_9 = vec_pool.make(9);
REQUIRE(vec_9->size() == 9);
for (int z = 0; z < 9; ++z) {
CHECK((*vec_9)[z] == z);
}
}
CHECK(2 == callback_count);
CHECK(vec_pool.size() == 2);
{
auto vec_10 = vec_pool.make(10);
REQUIRE(vec_10->size() == 10);
for (int z = 0; z < 10; ++z) {
CHECK((*vec_10)[z] == z);
}
}
CHECK(2 == callback_count);
CHECK(vec_pool.size() == 2);
{
auto vec_5 = vec_pool.make(5);
REQUIRE(vec_5->size() == 5);
for (int z = 0; z < 5; ++z) {
CHECK((*vec_5)[z] == z);
}
}
CHECK(3 == callback_count);
CHECK(vec_pool.size() == 3);
}