blob: c2837e4f627415c62683c08ac73b9bd0726bc75c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include "app.hpp"
#include "compat/assert.hpp"
#include "compat/vector-wrapper.hpp"
#include "src/search-result.hpp"
#include "src/search-node.hpp"
namespace floormat {
namespace { struct Test_PathPool {}; }
using psrpa = path_search_result_pool_access<Test_PathPool>;
using node = path_search_result::node;
template<>
struct path_search_result_pool_access<Test_PathPool> final
{
static const Pointer<node>& get_node(const path_search_result& p) { return p._node; }
static const auto& get_pool() { return path_search_result::_pool; }
static size_t pool_size();
};
size_t path_search_result_pool_access<Test_PathPool>::pool_size()
{
size_t ret = 0;
for (const auto* pool = get_pool().get(); pool; pool = pool->_next.get())
ret++;
return ret;
}
void Test::test_astar_pool()
{
const auto& pool = psrpa::get_pool();
fm_assert(psrpa::pool_size() == 0);
auto a = path_search_result{};
fm_assert(psrpa::pool_size() == 0);
fm_assert(!psrpa::get_node(a));
a = {};
fm_assert(!psrpa::get_node(a));
fm_assert(psrpa::pool_size() == 0);
a = path_search_result{};
(void)a.raw_path();
fm_assert(psrpa::get_node(a));
fm_assert(psrpa::pool_size() == 0);
const void* const first = psrpa::get_node(a).get();
fm_assert(first);
a = {};
fm_assert(!psrpa::get_node(a));
fm_assert(psrpa::pool_size() == 1);
fm_assert(pool.get() == first);
a = path_search_result{};
(void)a.raw_path();
fm_assert(psrpa::get_node(a));
fm_assert(psrpa::get_node(a).get() == first);
fm_assert(psrpa::pool_size() == 0);
auto b = path_search_result{};
(void)b.raw_path();
fm_assert(psrpa::get_node(a));
fm_assert(psrpa::get_node(b));
fm_assert(psrpa::pool_size() == 0);
b = {};
a = {};
fm_assert(!psrpa::get_node(a));
fm_assert(!psrpa::get_node(b));
fm_assert(psrpa::pool_size() == 2);
fm_assert(pool.get() == first);
}
} // namespace floormat
|