-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_partition.cpp
More file actions
47 lines (42 loc) · 1.45 KB
/
test_partition.cpp
File metadata and controls
47 lines (42 loc) · 1.45 KB
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
#define TCODPATH_ValueType int16_t
#define TCODPATH_VALUE_MAX INT16_MAX
#define TCODPATH_VALUE_MIN INT16_MIN
#define TCODPATH_IndexType int16_t
#include <libtcod-path/graph_types.h>
#include <libtcod-path/partition.h>
#include <array>
#include <catch2/catch_all.hpp>
#include <limits>
#include <stdexcept>
#include "common.h"
TEST_CASE("TCODPATH_partition", "") {
static const auto TEST_DATA = std::vector<std::string>{
"111#22#",
"111#2#3",
"111##33",
};
static const auto shape = std::array{
static_cast<TCODPATH_IndexType>(TEST_DATA.size()), static_cast<TCODPATH_IndexType>(TEST_DATA.at(0).size())};
auto costs = Map2D(shape);
for (int y = 0; y < TEST_DATA.size(); ++y) {
for (int x = 0; x < TEST_DATA.at(y).size(); ++x) {
costs[{y, x}] = TEST_DATA.at(y).at(x) != '#' ? 1 : 0;
}
};
auto graph = as_2d_graph(costs, 1, 0);
auto partition = Map2D(shape, -1);
TCODPATH_partition_from_graph(&graph, partition.c_data());
for (int y = 0; y < TEST_DATA.size(); ++y) {
auto line = std::string();
for (int x = 0; x < TEST_DATA.at(y).size(); ++x) {
line.push_back((partition[{y, x}] == 0) ? '#' : '0' + (char)partition[{y, x}]);
}
CHECK(TEST_DATA.at(y) == line);
};
}
TEST_CASE("TCODPATH_partition large", "[.slow]") {
auto costs = Map2D({2048, 2048}, 1);
auto graph = as_2d_graph(costs, 1, 0);
auto partition = Map2D(costs.get_shape(), 0);
TCODPATH_partition_from_graph(&graph, partition.c_data());
}