Skip to content

Commit

Permalink
Fix % 0 bug in MG_SELECT_RANDOM_VERTICES test (#4034)
Browse files Browse the repository at this point in the history
`% 0` throws an exception (`mg_graph_view.local_vertex_partition_range_size()` & `num_of_elements_in_given_set` can be 0). This PR fixes the bug.

Authors:
  - Seunghwa Kang (https://github.com/seunghwak)

Approvers:
  - Chuck Hastings (https://github.com/ChuckHastings)

URL: #4034
  • Loading branch information
seunghwak authored Dec 2, 2023
1 parent c6aa981 commit 90fec71
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cpp/tests/structure/mg_select_random_vertices_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Tests_MGSelectRandomVertices
std::iota(
h_given_set.begin(), h_given_set.end(), mg_graph_view.local_vertex_partition_range_first());
std::shuffle(h_given_set.begin(), h_given_set.end(), std::mt19937{std::random_device{}()});
h_given_set.resize(std::rand() % mg_graph_view.local_vertex_partition_range_size() + 1);
h_given_set.resize(std::rand() % (mg_graph_view.local_vertex_partition_range_size() + 1));

// Compute size of the distributed vertex set
int num_of_elements_in_given_set = static_cast<int>(h_given_set.size());
Expand All @@ -105,7 +105,7 @@ class Tests_MGSelectRandomVertices
size_t select_count =
num_of_elements_in_given_set > select_random_vertices_usecase.select_count
? select_random_vertices_usecase.select_count
: std::rand() % num_of_elements_in_given_set + 1;
: std::rand() % (num_of_elements_in_given_set + 1);

for (int idx = 0; idx < with_replacement_flags.size(); idx++) {
bool with_replacement = with_replacement_flags[idx];
Expand Down

0 comments on commit 90fec71

Please sign in to comment.