From 738d9a64d381e28d748cd8a05141c7c494a8e252 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 20 Mar 2026 12:02:52 -0400 Subject: [PATCH] Make the tests go faster. --- src/gui/mini_map.cpp | 33 ------------------------ src/gui/mini_map.hpp | 17 ------------- src/meson.build | 1 - tests/dijkstra.json | 60 -------------------------------------------- tests/map.cpp | 32 +++-------------------- tests/matrix.cpp | 59 +------------------------------------------ tests/pathing.cpp | 26 +------------------ 7 files changed, 6 insertions(+), 222 deletions(-) delete mode 100644 src/gui/mini_map.cpp delete mode 100644 src/gui/mini_map.hpp delete mode 100644 tests/dijkstra.json diff --git a/src/gui/mini_map.cpp b/src/gui/mini_map.cpp deleted file mode 100644 index 2a1663f..0000000 --- a/src/gui/mini_map.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "mini_map.hpp" -#include -#include -#include "dbc.hpp" -#include "game/components.hpp" -#include "algos/rand.hpp" -#include "game/systems.hpp" -#include "algos/rand.hpp" -#include -#include -#include - -namespace gui { - using namespace components; - - MiniMapUI::MiniMapUI() : - $map_grid{L"...", 45, {200, 200, 200, 100}, 10} - { - $font = std::make_shared(FONT_FILE_NAME); - } - - void MiniMapUI::init(guecs::UI& overlay) { - auto top_right = overlay.entity("top_right"); - auto cell = overlay.cell_for(top_right); - $map_grid.init(cell, $font); - } - - void MiniMapUI::render(sf::RenderWindow &window, int compass_dir) { - (void)compass_dir; - $map_grid.update(L"I'M BROKEN"); - window.draw(*$map_grid.text); - } -} diff --git a/src/gui/mini_map.hpp b/src/gui/mini_map.hpp deleted file mode 100644 index 4a74911..0000000 --- a/src/gui/mini_map.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "graphics/textures.hpp" -#include -#include - -namespace gui { - class MiniMapUI { - public: - guecs::Text $map_grid; - guecs::UI $gui; - std::shared_ptr $font = nullptr; - - MiniMapUI(); - void init(guecs::UI& overlay); - void render(sf::RenderWindow &window, int compass_dir); - }; -} diff --git a/src/meson.build b/src/meson.build index 0afa78f..9609930 100644 --- a/src/meson.build +++ b/src/meson.build @@ -24,7 +24,6 @@ sources = files( 'gui/loot_ui.cpp', 'gui/main_ui.cpp', 'gui/map_view.cpp', - 'gui/mini_map.cpp', 'gui/overlay_ui.cpp', 'gui/ritual_ui.cpp', 'gui/status_ui.cpp', diff --git a/tests/dijkstra.json b/tests/dijkstra.json deleted file mode 100644 index 1ee6990..0000000 --- a/tests/dijkstra.json +++ /dev/null @@ -1,60 +0,0 @@ -[{ - "input": [ - [1, 1, 1, 0], - [1, 0, 1, 1], - [1, 0, 1, 1], - [1, 1, 1, 1] - ], - "walls": [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 1, 0], - [0, 0, 1, 0] - ], - "expected": [ - [1, 1, 1, 0], - [1, 0, 1, 1], - [1, 0, 1000, 2], - [1, 1, 1000, 3] - ] -},{ - "input": [ - [1, 1, 1, 0], - [1, 0, 1, 1], - [1, 0, 1, 1], - [1, 1, 1, 1] - ], - "walls": [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 1, 0], - [0, 0, 1, 0] - ], - "expected": [ - [1, 1, 1, 0], - [1, 0, 1, 1], - [1, 0, 1000, 2], - [1, 1, 1000, 3] - ] -}, -{ - "input": [ - [1, 1, 1, 0], - [1, 1, 1, 1], - [1, 0, 1, 1], - [1, 1, 1, 1] - ], - "walls": [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 1, 0], - [0, 0, 1, 0] - ], - "expected": [ - [2, 2, 1, 0], - [1, 1, 1, 1], - [1, 0, 1000, 2], - [1, 1, 1000, 3] - ] -} -] diff --git a/tests/map.cpp b/tests/map.cpp index f401ad1..cf9ef69 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -7,6 +7,7 @@ #include "game/systems.hpp" #include #include "graphics/textures.hpp" +#include "algos/rand.hpp" using namespace fmt; using namespace nlohmann; @@ -52,34 +53,6 @@ TEST_CASE("map placement test", "[map-fail]") { } } -TEST_CASE("dijkstra algo test", "[map]") { - textures::init(); - json data = load_test_data("./tests/dijkstra.json"); - - for(auto &test : data) { - Matrix expected = test["expected"]; - Matrix input = test["input"]; - Matrix walls = test["walls"]; - Map map(input.size(), input[0].size()); - map.$walls = walls; - map.$paths.$input = input; - - REQUIRE(map.INVARIANT()); - - map.make_paths(); - Matrix &paths = map.paths(); - - if(paths != expected) { - println("ERROR! ------"); - matrix::dump("EXPECTED", expected); - matrix::dump("RESULT", paths); - } - - REQUIRE(map.INVARIANT()); - // FIX ME: REQUIRE(paths == expected); - } -} - TEST_CASE("map image test", "[map]") { GameDB::init(); @@ -99,6 +72,9 @@ TEST_CASE("map image test", "[map]") { System::draw_map(map_tiles, entity_map); System::render_map(map_tiles, entity_map, *render, 2, player_display); + // randomly test about 80% of them + if(Random::uniform(0, 100) < 20) break; + #ifdef TEST_RENDER // confirm we get two different maps auto out_img = render->getTexture().copyToImage(); diff --git a/tests/matrix.cpp b/tests/matrix.cpp index 3fee78e..993f52b 100644 --- a/tests/matrix.cpp +++ b/tests/matrix.cpp @@ -21,64 +21,7 @@ std::shared_ptr make_map() { return GameDB::current_level().map; } -TEST_CASE("basic matrix iterator", "[matrix]") { - std::ifstream infile("./tests/dijkstra.json"); - json data = json::parse(infile); - auto test = data[0]; - - Matrix walls = test["walls"]; - - // tests going through straight cells but also - // using two iterators on one matrix (or two) - matrix::each_cell cells{walls}; - cells.next(); // kick it off - size_t row_count = 0; - - for(matrix::each_row it{walls}; - it.next(); cells.next()) - { - REQUIRE(walls[cells.y][cells.x] == walls[it.y][it.x]); - row_count += it.row; - } - - REQUIRE(row_count == walls.size()); - - { - // test getting the correct height in the middle - row_count = 0; - matrix::box box{walls, 2,2, 1}; - - while(box.next()) { - row_count += box.x == box.left; - walls[box.y][box.x] = 3; - } - //matrix::dump("2,2 WALLS", walls, 2, 2); - - REQUIRE(row_count == 3); - } - - { - // matrix::dump("1:1 POINT", walls, 1,1); - // confirm boxes have the right number of rows - // when x goes to 0 on first next call - row_count = 0; - matrix::box box{walls, 1, 1, 1}; - - while(box.next()) { - row_count += box.x == box.left; - } - REQUIRE(row_count == 3); - } - - { - matrix::compass star{walls, 1, 1}; - while(star.next()) { - println("START IS {},{}=={}", star.x, star.y, walls[star.y][star.x]); - walls[star.y][star.x] = 11; - } - // matrix::dump("STAR POINT", walls, 1,1); - } -} +// BUG: create a test that randomizes a map then does matrix ops on it inline void random_matrix(Matrix &out) { for(size_t y = 0; y < out.size(); y++) { diff --git a/tests/pathing.cpp b/tests/pathing.cpp index 53d29e0..1265dc1 100644 --- a/tests/pathing.cpp +++ b/tests/pathing.cpp @@ -38,7 +38,7 @@ TEST_CASE("multiple targets can path", "[pathing]") { while(found == PathingResult::CONTINUE) { // fmt::println("\033[2J\033[1;1H"); // matrix::dump(diag ? "diag" : "simple", paths.$paths, pos.x, pos.y); - std::this_thread::sleep_for(200ms); + // std::this_thread::sleep_for(200ms); found = paths.find_path(pos, PATHING_TOWARD, diag); } @@ -51,27 +51,3 @@ TEST_CASE("multiple targets can path", "[pathing]") { REQUIRE(found != PathingResult::FAIL); } } - -TEST_CASE("dijkstra algo test", "[pathing-old]") { - json data = load_test_pathing("./tests/dijkstra.json"); - - for(auto &test : data) { - Matrix expected = test["expected"]; - Matrix walls = test["walls"]; - - Pathing pathing(walls[0].size(), walls.size()); - - pathing.$input = test["input"]; - - REQUIRE(pathing.INVARIANT()); - int longest = pathing.compute_paths(walls); - REQUIRE(longest > 0); - REQUIRE(longest < WALL_PATH_LIMIT); - - REQUIRE(pathing.INVARIANT()); - - matrix::dump("PATHING RESULT", pathing.$paths); - matrix::dump("PATHING EXPECTED", expected); - REQUIRE(pathing.$paths == expected); - } -}