You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.0 KiB
83 lines
2.0 KiB
#include <catch2/catch_test_macros.hpp>
|
|
#include <fmt/core.h>
|
|
#include <nlohmann/json.hpp>
|
|
#include <fstream>
|
|
#include "map.hpp"
|
|
#include "worldbuilder.hpp"
|
|
|
|
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("camera control", "[map]") {
|
|
Map map(20, 20);
|
|
WorldBuilder builder(map);
|
|
builder.generate_map();
|
|
|
|
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("map placement test", "[map:placement]") {
|
|
for(int i = 0; i < 50; i++) {
|
|
size_t width = Random::uniform<size_t>(9, 21);
|
|
size_t height = Random::uniform<size_t>(13, 25);
|
|
Map map(width, height);
|
|
WorldBuilder builder(map);
|
|
builder.generate_rooms();
|
|
map.invert_space();
|
|
|
|
for(size_t rnum = 0; rnum < map.room_count(); rnum++) {
|
|
Room &room = map.room(rnum);
|
|
Point pos;
|
|
|
|
REQUIRE(map.place_entity(rnum, pos));
|
|
// matrix::dump("ROOM PLACEMENT TEST", map.walls(), pos.x, pos.y);
|
|
|
|
REQUIRE(!map.iswall(pos.x, pos.y));
|
|
REQUIRE(pos.x >= room.x);
|
|
REQUIRE(pos.y >= room.y);
|
|
REQUIRE(pos.x <= room.x + room.width);
|
|
REQUIRE(pos.y <= room.y + room.height);
|
|
}
|
|
}
|
|
}
|
|
|
|
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.$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);
|
|
}
|
|
}
|
|
|