From 6081a9c426a51b93d3420786a78cf40523a3dc9e Mon Sep 17 00:00:00 2001 From: orange Date: Wed, 11 Mar 2026 14:30:01 +0300 Subject: [PATCH] added throw test --- source/pathfinding/navigation_mesh.cpp | 9 +++++---- tests/general/unit_test_navigation_mesh.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source/pathfinding/navigation_mesh.cpp b/source/pathfinding/navigation_mesh.cpp index 0376425..380f83e 100644 --- a/source/pathfinding/navigation_mesh.cpp +++ b/source/pathfinding/navigation_mesh.cpp @@ -32,8 +32,10 @@ namespace omath::pathfinding void NavigationMesh::set_event(const Vector3& vertex, std::string event_id) { - if (m_vertex_map.contains(vertex)) - m_vertex_events[vertex] = std::move(event_id); + if (!m_vertex_map.contains(vertex)) + throw std::invalid_argument(std::format("Vertex '{}' not found", vertex)); + + m_vertex_events[vertex] = std::move(event_id); } void NavigationMesh::clear_event(const Vector3& vertex) @@ -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'; diff --git a/tests/general/unit_test_navigation_mesh.cpp b/tests/general/unit_test_navigation_mesh.cpp index 266bf62..37cec31 100644 --- a/tests/general/unit_test_navigation_mesh.cpp +++ b/tests/general/unit_test_navigation_mesh.cpp @@ -145,6 +145,13 @@ TEST(NavigationMeshTests, VertexWithNoNeighborsRoundTrip) // Vertex events // --------------------------------------------------------------------------- +TEST(NavigationMeshTests, SetEventOnNonExistentVertexThrows) +{ + NavigationMesh nav; + const Vector3 v{99.f, 99.f, 99.f}; + EXPECT_THROW(nav.set_event(v, "jump"), std::invalid_argument); +} + TEST(NavigationMeshTests, EventNotSetByDefault) { NavigationMesh nav;