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

View File

@@ -145,6 +145,13 @@ TEST(NavigationMeshTests, VertexWithNoNeighborsRoundTrip)
// Vertex events // 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) TEST(NavigationMeshTests, EventNotSetByDefault)
{ {
NavigationMesh nav; NavigationMesh nav;