Skip to content

Commit

Permalink
Add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lixueclaire committed Apr 13, 2023
1 parent 64179d7 commit b5a4f4a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cpp/include/gar/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,7 @@ class EdgeIter {
}

/** Check if the current position is the end. */
bool is_end() const {
return global_chunk_index_ == chunk_end_ && cur_offset_ == 0;
}
bool is_end() const { return global_chunk_index_ >= chunk_end_; }

/** Point to the next edge with the same source, return false if not found. */
bool next_src() {
Expand Down Expand Up @@ -1237,6 +1235,9 @@ static inline Result<Edges> ConstructEdgesCollection(
EdgeInfo edge_info;
GAR_ASSIGN_OR_RAISE(edge_info,
graph_info.GetEdgeInfo(src_label, edge_label, dst_label));
if (!edge_info.ContainAdjList(adj_list_type)) {
return Status::Invalid("Invalid adj list type");
}
switch (adj_list_type) {
case AdjListType::ordered_by_source:
return EdgesCollection<AdjListType::ordered_by_source>(
Expand Down
22 changes: 22 additions & 0 deletions cpp/test/test_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,26 @@ TEST_CASE("test_edges_collection", "[Slow]") {
}
std::cout << "edge_count=" << count2 << std::endl;
REQUIRE(edges2.size() == count2);

// empty collection
auto expect3 = GAR_NAMESPACE::ConstructEdgesCollection(
graph_info, src_label, edge_label, dst_label,
GAR_NAMESPACE::AdjListType::unordered_by_source, 5, 5);
REQUIRE(!expect2.has_error());
auto& edges3 = std::get<GAR_NAMESPACE::EdgesCollection<
GAR_NAMESPACE::AdjListType::unordered_by_source>>(expect3.value());
auto end3 = edges3.end();
GAR_NAMESPACE::IdType count3 = 0;
for (auto it = edges3.begin(); it != end3; ++it) {
count3++;
}
std::cout << "edge_count=" << count3 << std::endl;
REQUIRE(count3 == 0);
REQUIRE(edges3.size() == 0);

// invalid adjlist type
auto expect4 = GAR_NAMESPACE::ConstructEdgesCollection(
graph_info, src_label, edge_label, dst_label,
GAR_NAMESPACE::AdjListType::unordered_by_dest);
REQUIRE(expect4.status().IsInvalid());
}

0 comments on commit b5a4f4a

Please sign in to comment.