From dd00820933be56fbe3ef2b296a5b59b7f78316ca Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 9 Oct 2023 10:06:54 +0200 Subject: a --- test/app.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/app.hpp | 2 +- test/bench.hpp | 27 ++++++++++++++++++++++++++ test/coords.cpp | 23 ++++++++++++---------- test/dijkstra.cpp | 36 ++++++++++------------------------ test/main.cpp | 58 ------------------------------------------------------- 6 files changed, 109 insertions(+), 95 deletions(-) create mode 100644 test/app.cpp create mode 100644 test/bench.hpp delete mode 100644 test/main.cpp (limited to 'test') diff --git a/test/app.cpp b/test/app.cpp new file mode 100644 index 00000000..3e1f7f82 --- /dev/null +++ b/test/app.cpp @@ -0,0 +1,58 @@ +#include "app.hpp" +#include "compat/assert.hpp" +#include "loader/loader.hpp" +#include +#include + +namespace floormat { + +test_app::test_app(const Arguments& arguments): + Application { + arguments, + Configuration{} + } +{ +} + +test_app::~test_app() +{ + loader_::destroy(); +} + +int test_app::exec() +{ + test_coords(); + test_json(); + test_tile_iter(); + test_magnum_math(); + test_entity(); + test_loader(); + test_bitmask(); + test_serializer_1(); + test_serializer_2(); + test_path_search(); + test_math(); + test_hash(); + test_path_search_node_pool(); + + test_dijkstra(); + + zzz_test_misc(); + + return 0; +} + +} // namespace floormat + +int main(int argc, char** argv) +{ +#ifdef _WIN32 + // NOLINTNEXTLINE(concurrency-mt-unsafe) + if (const auto* s = std::getenv("MAGNUM_LOG"); !s || !*s) + _putenv("MAGNUM_LOG=quiet"); +#else + setenv("MAGNUM_LOG", "quiet", 0); +#endif + floormat::test_app application{{argc, argv}}; + return application.exec(); +} diff --git a/test/app.hpp b/test/app.hpp index 3544ed1b..0822e68f 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -31,6 +31,7 @@ struct test_app final : private FM_APPLICATION int exec() override; + static void test_coords(); static void test_json(); static void test_tile_iter(); static void test_magnum_math(); @@ -44,7 +45,6 @@ struct test_app final : private FM_APPLICATION static void test_hash(); static void test_path_search_node_pool(); static void test_dijkstra(); - static void test_coords(); static void zzz_test_misc(); }; } // namespace floormat diff --git a/test/bench.hpp b/test/bench.hpp new file mode 100644 index 00000000..7101e49f --- /dev/null +++ b/test/bench.hpp @@ -0,0 +1,27 @@ +#pragma once +#include +#include + +namespace floormat { + +template +requires requires (F& fun) { fun(); } +void bench_run(StringView name, F&& fun) +{ + using namespace std::chrono; + using clock = high_resolution_clock; +#if 0 + for (int i = 0; i < 20; i++) + fun(); + const auto t0 = clock::now(); + for (int i = 0; i < 1000; i++) + fun(); +#else + const auto t0 = clock::now(); + fun(); +#endif + const auto tm = clock::now() - t0; + Debug{} << "test" << name << "took" << duration_cast(tm).count() << "ms."; +} + +} // namespace floormat diff --git a/test/coords.cpp b/test/coords.cpp index 363d6f8a..7fbf8c34 100644 --- a/test/coords.cpp +++ b/test/coords.cpp @@ -1,10 +1,16 @@ #include "app.hpp" #include "src/object.hpp" +#include "bench.hpp" namespace floormat { namespace { +point norm(const point& pt, Vector2i delta) +{ + return object::normalize_coords(pt, delta); +}; + void test_normalize_point() { point a = { {{ 0, 0, 0}, { 0, 0}}, { 0, 0} }, @@ -12,16 +18,13 @@ void test_normalize_point() c = { {{ -1, 1, 1}, { 7, 9}}, { 1, 31} }, d = { {{16384,-16384,2}, {15, 0}}, { 1, 2} }; - { constexpr auto norm = [](const point& pt, Vector2i delta) { return object::normalize_coords(pt, delta); }; - - fm_assert_equal(norm(a, {}), point{{{ 0, 0, 0}, { 0, 0}}, { 0, 0} }); - fm_assert_equal(norm(b, {}), point{{{ -1, 1, 2}, { 0, 15}}, { 0, 0} }); - fm_assert_equal(norm(b, { 1, -1} ), point{{{ -1, 1 , 2}, { 0, 15}}, { 1, -1} }); - fm_assert_equal(norm(b, { -65, 65 }), point{{{ -2, 2, 2}, {15, 0}}, { -1, 1} }); - fm_assert_equal(norm(c, { 30, -62 }), point{{{ -1, 1, 1}, { 7, 9}}, { 31, -31} }); - fm_assert_equal(norm(c, {1024, 1024}), point{{{ 0, 2, 1}, { 7, 9}}, { 1, 31} }); - fm_assert_equal(norm(d, {2048, 1087}), point{{{16386,-16383,2}, {15, 1}}, { 1, 1} }); - } + fm_assert_equal(norm(a, {}), point{{{ 0, 0, 0}, { 0, 0}}, { 0, 0} }); + fm_assert_equal(norm(b, {}), point{{{ -1, 1, 2}, { 0, 15}}, { 0, 0} }); + fm_assert_equal(norm(b, { 1, -1} ), point{{{ -1, 1 , 2}, { 0, 15}}, { 1, -1} }); + fm_assert_equal(norm(b, { -65, 65 }), point{{{ -2, 2, 2}, {15, 0}}, { -1, 1} }); + fm_assert_equal(norm(c, { 30, -62 }), point{{{ -1, 1, 1}, { 7, 9}}, { 31, -31} }); + fm_assert_equal(norm(c, {1024, 1024}), point{{{ 0, 2, 1}, { 7, 9}}, { 1, 31} }); + fm_assert_equal(norm(d, {2048, 1087}), point{{{16386,-16383,2}, {15, 1}}, { 1, 1} }); } } // namespace diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp index 8b56e505..8c35648d 100644 --- a/test/dijkstra.cpp +++ b/test/dijkstra.cpp @@ -1,36 +1,11 @@ #include "app.hpp" +#include "bench.hpp" #include "src/path-search.hpp" #include "loader/loader.hpp" #include -#include -#include namespace floormat { -namespace { - -template -requires requires (F& fun) { fun(); } -void bench_run(StringView name, F&& fun) -{ - using namespace std::chrono; - using clock = high_resolution_clock; -#if 0 - for (int i = 0; i < 20; i++) - fun(); - const auto t0 = clock::now(); - for (int i = 0; i < 1000; i++) - fun(); -#else - const auto t0 = clock::now(); - fun(); -#endif - const auto tm = clock::now() - t0; - Debug{} << "test" << name << "took" << duration_cast(tm).count() << "ms."; -} - -} // namespace - void test_app::test_dijkstra() { auto w = world(); @@ -58,6 +33,15 @@ void test_app::test_dijkstra() fm_assert(ch.is_passability_modified()); + auto do_bench = [&](int debug) { + a.Dijkstra(w, + {{0,0,0}, {11,9}}, // from + {wpos, {wox, woy}}, // to + 0, max_dist, {32,32}, // size + debug); + }; + + //do_bench(0); bench_run("Dijkstra", [&] { a.Dijkstra(w, {{0,0,0}, {11,9}}, // from diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index af64dfec..00000000 --- a/test/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "app.hpp" -#include "compat/assert.hpp" -#include "loader/loader.hpp" -#include -#include - -namespace floormat { - -test_app::test_app(const Arguments& arguments): - Application { - arguments, - Configuration{} - } -{ -} - -test_app::~test_app() -{ - loader_::destroy(); -} - -int test_app::exec() -{ - test_json(); - test_tile_iter(); - test_magnum_math(); - test_entity(); - test_loader(); - test_bitmask(); - test_serializer_1(); - test_serializer_2(); - test_path_search(); - test_math(); - test_hash(); - test_path_search_node_pool(); - test_coords(); - - test_dijkstra(); - - zzz_test_misc(); - - return 0; -} - -} // namespace floormat - -int main(int argc, char** argv) -{ -#ifdef _WIN32 - // NOLINTNEXTLINE(concurrency-mt-unsafe) - if (const auto* s = std::getenv("MAGNUM_LOG"); !s || !*s) - _putenv("MAGNUM_LOG=quiet"); -#else - setenv("MAGNUM_LOG", "quiet", 0); -#endif - floormat::test_app application{{argc, argv}}; - return application.exec(); -} -- cgit v1.2.3