From 807f2da166fd5d0a13e76418b4b91838a4ac5ef8 Mon Sep 17 00:00:00 2001 From: lixueclaire Date: Sat, 6 May 2023 20:22:43 +0800 Subject: [PATCH] Implement the add-assign operator for VertexIter (#151) --- cpp/include/gar/graph.h | 6 ++++++ cpp/test/test_graph.cc | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/cpp/include/gar/graph.h b/cpp/include/gar/graph.h index ac3760192..965d75f23 100644 --- a/cpp/include/gar/graph.h +++ b/cpp/include/gar/graph.h @@ -213,6 +213,12 @@ class VertexIter { return ret; } + /** The add-assign operator. */ + VertexIter& operator+=(IdType offset) { + cur_offset_ += offset; + return *this; + } + /** The equality operator. */ bool operator==(const VertexIter& rhs) const noexcept { return cur_offset_ == rhs.cur_offset_; diff --git a/cpp/test/test_graph.cc b/cpp/test/test_graph.cc index 55832c810..2bfa172e8 100644 --- a/cpp/test/test_graph.cc +++ b/cpp/test/test_graph.cc @@ -56,6 +56,17 @@ TEST_CASE("test_vertices_collection") { << ", id=" << it_last.property("id").value() << ", firstName=" << it_last.property("firstName").value() << std::endl; + auto it_begin = it_last + (1 - count); + + auto it = vertices.begin(); + it += (count - 1); + REQUIRE(it.id() == it_last.id()); + REQUIRE(it.property("id").value() == + it_last.property("id").value()); + it += (1 - count); + REQUIRE(it.id() == it_begin.id()); + REQUIRE(it.property("id").value() == + it_begin.property("id").value()); } TEST_CASE("test_edges_collection", "[Slow]") {