diff --git a/cpp/include/gar/graph.h b/cpp/include/gar/graph.h index 965d75f23..a7e043d91 100644 --- a/cpp/include/gar/graph.h +++ b/cpp/include/gar/graph.h @@ -66,16 +66,15 @@ class Vertex { */ template inline Result property(const std::string& property) noexcept { - T ret; if (properties_.find(property) == properties_.end()) { return Status::KeyError("The property is not exist."); } try { - ret = std::any_cast(properties_[property]); + T ret = std::any_cast(properties_[property]); + return ret; } catch (const std::bad_any_cast& e) { return Status::TypeError("The property type is not match."); } - return ret; } private: @@ -120,16 +119,15 @@ class Edge { */ template inline Result property(const std::string& property) noexcept { - T ret; if (properties_.find(property) == properties_.end()) { return Status::KeyError("The property is not exist."); } try { - ret = std::any_cast(properties_[property]); + T ret = std::any_cast(properties_[property]); + return ret; } catch (const std::bad_any_cast& e) { return Status::TypeError("The property type is not match."); } - return ret; } private: diff --git a/cpp/test/test_graph.cc b/cpp/test/test_graph.cc index 2bfa172e8..ee2353f2a 100644 --- a/cpp/test/test_graph.cc +++ b/cpp/test/test_graph.cc @@ -49,6 +49,12 @@ TEST_CASE("test_vertices_collection") { << ", id=" << vertex.property("id").value() << ", firstName=" << vertex.property("firstName").value() << std::endl; + // access data reference through vertex + REQUIRE(vertex.property("id").value() == + vertex.property("id").value()); + REQUIRE(vertex.property("firstName").value() == + vertex.property("firstName").value()); + REQUIRE(vertex.property("id").has_error()); count++; } auto it_last = vertices.begin() + (count - 1); @@ -88,11 +94,18 @@ TEST_CASE("test_edges_collection", "[Slow]") { size_t count = 0; for (auto it = edges.begin(); it != end; ++it) { // access data through iterator directly - std::cout << "src=" << it.source() << ", dst=" << it.destination() - << std::endl; + std::cout << "src=" << it.source() << ", dst=" << it.destination() << " "; + // access data through edge auto edge = *it; - std::cout << "src=" << edge.source() << ", dst=" << edge.destination() + REQUIRE(edge.source() == it.source()); + REQUIRE(edge.destination() == it.destination()); + std::cout << "creationDate=" + << edge.property("creationDate").value() << std::endl; + // access data reference through edge + REQUIRE(edge.property("creationDate").value() == + edge.property("creationDate").value()); + REQUIRE(edge.property("creationDate").has_error()); count++; } std::cout << "edge_count=" << count << std::endl; diff --git a/testing b/testing index d3ee868d8..ad3725825 160000 --- a/testing +++ b/testing @@ -1 +1 @@ -Subproject commit d3ee868d8d8da90adfd444e24ea8882606d33fff +Subproject commit ad3725825deceb6522be8a9b40b3e3c4706493e6