#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"]; Map map(test["input"], test["walls"], test["limit"]); map.make_paths(); Matrix &paths = map.paths(); if(paths != expected) { println("ERROR! ------"); dump_map("EXPECTED", expected); dump_map("RESULT", paths); } 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("lighting test", "[map]") { Map map(20,20); map.generate(); Point light1 = map.place_entity(0); Point light2 = map.place_entity(1); LightSource source1{7,1}; LightSource source2{3,2}; map.reset_light(); map.set_light_target(light1); map.set_light_target(light2); map.path_light(); map.render_light(source1, light1); map.render_light(source2, light2); map.clear_light_target(light1); map.clear_light_target(light2); const auto &lighting = map.lighting(); // confirm light is set at least at and around the two points REQUIRE(lighting[light1.y][light1.x] == lighting::LEVELS[source1.strength]); REQUIRE(lighting[light2.y][light2.x] == lighting::LEVELS[source2.strength]); } 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); }