summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/app.hpp5
-rw-r--r--test/path-search.cpp29
-rw-r--r--test/serializer.cpp8
3 files changed, 37 insertions, 5 deletions
diff --git a/test/app.hpp b/test/app.hpp
index 04ed55b7..f3e57da2 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -17,6 +17,7 @@
namespace floormat {
struct chunk_coords;
+struct chunk_coords_;
struct chunk;
struct world;
@@ -25,7 +26,11 @@ struct test_app final : private FM_APPLICATION
using Application = FM_APPLICATION;
explicit test_app(const Arguments& arguments);
~test_app();
+
+ static chunk& make_test_chunk(world& w, chunk_coords_ ch);
+
int exec() override;
+
static void test_json();
static void test_tile_iter();
static void test_const_math();
diff --git a/test/path-search.cpp b/test/path-search.cpp
index 7bbd04c0..faa16a06 100644
--- a/test/path-search.cpp
+++ b/test/path-search.cpp
@@ -1,6 +1,10 @@
#include "app.hpp"
-#include "src/path-search.hpp"
#include "compat/assert.hpp"
+#include "loader/loader.hpp"
+#include "src/world.hpp"
+#include "src/scenery.hpp"
+
+#include "src/path-search.hpp"
namespace floormat {
@@ -8,7 +12,30 @@ namespace {
void test_bbox()
{
+ auto metal2 = loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked);
+ auto table = loader.scenery("table1");
+ {
+ auto w = world();
+ auto& c12 = w[chunk_coords_{1, 2, 0}];
+ [[maybe_unused]] auto& c11 = w[chunk_coords_{1, 1, 0}];
+ c12[{0, 0}].wall_north() = {metal2, 0};
+
+ constexpr auto sample = [](chunk& c, search::bbox bb) {
+ return search::sample_rtree_1(c, bb.min, bb.max, (object_id)-1);
+ };
+
+ constexpr auto bbox = [](Vector2i coord, rotation r) {
+ return search::make_neighbor_tile_bbox(coord, {}, r);
+ };
+
+ using enum rotation;
+ fm_assert( !sample(c12, bbox({0, 0}, N)) );
+ fm_assert( sample(c12, bbox({0, 0}, E)) );
+ fm_assert( sample(c12, bbox({0, 0}, S)) );
+ fm_assert( sample(c12, bbox({0, 0}, W)) );
+ }
+ // todo use test chunk
}
} // namespace
diff --git a/test/serializer.cpp b/test/serializer.cpp
index 9387f827..dd2d090d 100644
--- a/test/serializer.cpp
+++ b/test/serializer.cpp
@@ -13,9 +13,7 @@ namespace floormat {
namespace Path = Corrade::Utility::Path;
-namespace {
-
-chunk& make_test_chunk(world& w, chunk_coords_ ch)
+chunk& test_app::make_test_chunk(world& w, chunk_coords_ ch)
{
chunk& c = w[ch];
c.mark_modified();
@@ -47,6 +45,8 @@ chunk& make_test_chunk(world& w, chunk_coords_ ch)
return c;
}
+namespace {
+
void assert_chunks_equal(const chunk& a, const chunk& b)
{
fm_assert(a.objects().size() == b.objects().size());
@@ -103,7 +103,7 @@ void test_serializer(StringView input, StringView tmp)
{
coord = {1, 1, 0};
w = world();
- make_test_chunk(w, coord);
+ test_app::make_test_chunk(w, coord);
}
w.serialize(tmp);
auto w2 = world::deserialize(tmp);