#include #include "map.hpp" #include #include #include using namespace fmt; using namespace nlohmann; using std::string; json load_test_data(const string &fname) { std::ifstream infile(fname); return json::parse(infile); } TEST_CASE("dijkstra algo test", "[map]") { 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.$limit = test["limit"]; map.$paths.$input = input; REQUIRE(map.INVARIANT()); map.make_paths(); Matrix &paths = map.paths(); if(paths != expected) { println("ERROR! ------"); dump_map("EXPECTED", expected); dump_map("RESULT", paths); } REQUIRE(map.INVARIANT()); // FIX ME: REQUIRE(paths == expected); } } TEST_CASE("bsp algo test", "[map]") { Map map(20, 20); map.generate(); } TEST_CASE("dumping and debugging", "[map]") { Map map(20, 20); map.generate(); dump_map("GENERATED", map.paths()); map.dump(); } TEST_CASE("camera control", "[map]") { Map map(20,20); map.generate(); Point center = map.center_camera({10,10}, 5, 5); REQUIRE(center.x == 8); REQUIRE(center.y == 8); Point translation = map.map_to_camera({10,10}, center); REQUIRE(translation.x == 2); REQUIRE(translation.y == 2); } TEST_CASE("pathing", "[map]") { Map map(20,20); map.generate(); REQUIRE(map.can_move({0,0}) == false); REQUIRE(map.iswall(0,0) == true); }