94 lines
3.2 KiB
C++
94 lines
3.2 KiB
C++
// Loader tests: missing keys keep defaults and are reported; bad ranges are clamped and reported.
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <cstdio>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
#include "voronoi_route/params_io.h"
|
|
|
|
namespace {
|
|
|
|
std::string writeTemp(const std::string& body)
|
|
{
|
|
const std::string path = "/tmp/voronoi_route_params_test_" + std::to_string(::getpid()) + ".yaml";
|
|
std::ofstream f(path);
|
|
f << body;
|
|
return path;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(ParamsIo, PackagedDefaultsLoadCleanly)
|
|
{
|
|
voronoi_route::RouteParams p;
|
|
std::string err;
|
|
std::vector<std::string> notes;
|
|
ASSERT_TRUE(voronoi_route::loadRouteParams(VORONOI_ROUTE_PACKAGED_PARAMS, &p, &err, ¬es)) << err;
|
|
EXPECT_TRUE(notes.empty()) << notes.front();
|
|
EXPECT_DOUBLE_EQ(p.min_clearance_m, 0.3);
|
|
EXPECT_FALSE(p.unknown_is_obstacle);
|
|
const auto c = p.toConfig(0.05);
|
|
EXPECT_DOUBLE_EQ(c.min_edge_length_cells, 6.0);
|
|
EXPECT_DOUBLE_EQ(c.min_clearance_cells, 6.0);
|
|
EXPECT_EQ(c.attach_max_radius_cells, 200);
|
|
const auto cp = p.toCorridor(0.05);
|
|
EXPECT_DOUBLE_EQ(cp.half_width_min_cells, 30.0);
|
|
}
|
|
|
|
TEST(ParamsIo, MissingAndBadKeysAreReportedNotFatal)
|
|
{
|
|
const std::string path = writeTemp(
|
|
"voronoi_route:\n"
|
|
" graph:\n"
|
|
" min_edge_length_m: -5\n" // out of range -> clamped to default
|
|
" spur_clearance_ratio: 1.0\n"
|
|
" corridor:\n"
|
|
" half_width_min_m: 3.0\n"
|
|
" half_width_max_m: 1.0\n" // max < min -> raised
|
|
" obstacle:\n"
|
|
" unknown: obstacle\n");
|
|
voronoi_route::RouteParams p;
|
|
std::string err;
|
|
std::vector<std::string> notes;
|
|
ASSERT_TRUE(voronoi_route::loadRouteParams(path, &p, &err, ¬es)) << err;
|
|
std::remove(path.c_str());
|
|
EXPECT_DOUBLE_EQ(p.spur_clearance_ratio, 1.0);
|
|
EXPECT_DOUBLE_EQ(p.min_edge_length_m, 0.3); // clamped
|
|
EXPECT_DOUBLE_EQ(p.half_width_max_m, 3.0); // raised to min
|
|
EXPECT_TRUE(p.unknown_is_obstacle);
|
|
EXPECT_DOUBLE_EQ(p.min_clearance_m, 0.3); // missing -> default
|
|
bool saw_missing = false, saw_clamp = false;
|
|
for (const auto& n : notes)
|
|
{
|
|
if (n.find("min_clearance_m: missing") != std::string::npos) saw_missing = true;
|
|
if (n.find("min_edge_length_m out of range") != std::string::npos) saw_clamp = true;
|
|
}
|
|
EXPECT_TRUE(saw_missing);
|
|
EXPECT_TRUE(saw_clamp);
|
|
}
|
|
|
|
TEST(ParamsIo, NoRootKeyFails)
|
|
{
|
|
const std::string path = writeTemp("something_else: 1\n");
|
|
voronoi_route::RouteParams p;
|
|
std::string err;
|
|
EXPECT_FALSE(voronoi_route::loadRouteParams(path, &p, &err, nullptr));
|
|
std::remove(path.c_str());
|
|
EXPECT_NE(err.find("voronoi_route"), std::string::npos);
|
|
}
|
|
|
|
TEST(ParamsIo, ObstacleRuleIsSelfContainedInOwnParams)
|
|
{
|
|
// No config-dir scan, no formula from another package's flags: `unknown_is_obstacle` decides
|
|
// the policy directly, everything else in the rule is this package's own default.
|
|
voronoi_route::RouteParams p;
|
|
const auto r = p.toObstacleRule(0.05);
|
|
EXPECT_EQ(r.layer.lethal_cost_threshold, 100);
|
|
EXPECT_TRUE(r.layer.track_unknown_space);
|
|
EXPECT_EQ(r.unknown, voronoi_route::UnknownPolicy::kTraversable);
|
|
|
|
p.unknown_is_obstacle = true;
|
|
EXPECT_EQ(p.toObstacleRule(0.05).unknown, voronoi_route::UnknownPolicy::kObstacle);
|
|
}
|