Fixed the bug that made walls not receive the algorithm.

This commit is contained in:
Zed A. Shaw 2024-09-26 16:55:42 -04:00
parent 4d748d1f48
commit ebb5360c5c
3 changed files with 30 additions and 30 deletions

View file

@ -1,35 +1,34 @@
#include <catch2/catch_test_macros.hpp>
#include "map.hpp"
#include <fmt/core.h>
#include <nlohmann/json.hpp>
#include <fstream>
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]") {
Matrix in_map = {
{1, 1, 1, 0},
{1, 0, 1, 1},
{1, 0, 1, 1},
{1, 1, 1, 1},
};
Matrix walls = {
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 1, 0},
{0, 0, 1, 0},
};
Matrix expected = {
{1, 1, 1, 0},
{1, 0, 1, 1},
{1, 0, 0, 2},
{1, 1, 0, 3},
};
json data = load_test_data("./tests/dijkstra.json");
Matrix res = dijkstra_map(in_map, walls);
for(auto &test : data) {
Matrix in_map = test["input"];
Matrix walls = test["walls"];
Matrix expected = test["expected"];
int limit = test["limit"];
Matrix res = dijkstra_map(in_map, walls, limit);
println("--- EXPECTED:");
dump_map(expected);
println("--- RESULT:");
dump_map(res);
if(res != expected) {
println("ERROR! ------");
dump_map("EXPECTED", expected);
dump_map("RESULT", res);
}
REQUIRE(res == expected);
REQUIRE(res == expected);
}
}