added throw test

This commit is contained in:
2026-03-11 14:30:01 +03:00
parent 8bbd504356
commit 6081a9c426
2 changed files with 12 additions and 4 deletions

View File

@@ -32,7 +32,9 @@ namespace omath::pathfinding
void NavigationMesh::set_event(const Vector3<float>& vertex, std::string event_id)
{
if (m_vertex_map.contains(vertex))
if (!m_vertex_map.contains(vertex))
throw std::invalid_argument(std::format("Vertex '{}' not found", vertex));
m_vertex_events[vertex] = std::move(event_id);
}
@@ -62,8 +64,7 @@ namespace omath::pathfinding
const auto event_it = m_vertex_events.find(vertex);
const std::string& event = (event_it != m_vertex_events.end()) ? event_it->second : "-";
oss << vertex.x << ' ' << vertex.y << ' ' << vertex.z
<< ' ' << neighbors.size() << ' ' << event << '\n';
oss << vertex.x << ' ' << vertex.y << ' ' << vertex.z << ' ' << neighbors.size() << ' ' << event << '\n';
for (const auto& n : neighbors)
oss << n.x << ' ' << n.y << ' ' << n.z << '\n';

View File

@@ -145,6 +145,13 @@ TEST(NavigationMeshTests, VertexWithNoNeighborsRoundTrip)
// Vertex events
// ---------------------------------------------------------------------------
TEST(NavigationMeshTests, SetEventOnNonExistentVertexThrows)
{
NavigationMesh nav;
const Vector3<float> v{99.f, 99.f, 99.f};
EXPECT_THROW(nav.set_event(v, "jump"), std::invalid_argument);
}
TEST(NavigationMeshTests, EventNotSetByDefault)
{
NavigationMesh nav;