-
Notifications
You must be signed in to change notification settings - Fork 17
Refactor edge_range tests to use GoogleTest matchers and parameterized tests #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
tests/edge_range.cpp
Outdated
| // Check that edge_range produces the same edges as edgelist | ||
| EXPECT_THAT(edges_from_range, ElementsAreArray(edgelist)); | ||
|
|
||
| // Collect edge indices to verify they are consecutive starting from 0 | ||
| std::vector<std::size_t> edge_indices; | ||
| for (auto it = edge_range.begin(); it != edge_range.end(); ++it) { | ||
| edge_indices.push_back(it.edge_index()); | ||
| } | ||
|
|
||
| // Generate expected indices: [0, 1, 2, ..., n-1] | ||
| std::vector<std::size_t> expected_indices(edge_indices.size()); | ||
| std::iota(expected_indices.begin(), expected_indices.end(), 0); | ||
|
|
||
| EXPECT_THAT(edge_indices, ElementsAreArray(expected_indices)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Can we make this more concise using a more complex matcher statement and can we get completely rid of the check_edge_range function? I like tests do be concise without too much indirection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit 74f5a41. I've:
- Removed both
check_edge_rangehelper functions - Inlined the logic directly into each test using a lambda
- Made the matcher more concise by using
std::vector(edge_range.begin(), edge_range.end())directly in theEXPECT_THATstatement
The tests are now more self-contained and easier to read without the extra indirection.
Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
tests/edge_range.cpp
Outdated
| if (graph.representation == GraphRepresentation::CSR) { | ||
| expected = BuildEdgeListFromCSR(graph.vertex_range, graph.xadj, graph.adjncy); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot this if is unnecessary here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit f31168a. Removed the unnecessary CSR check from both edgelist tests since they use UseEdgeListRepresentation() and will never have CSR representation.
tests/edge_range.cpp
Outdated
| check(generator.GenerateUndirectedGNM(n, m)); | ||
| check(generator.GenerateRMAT(n, m, 0.56, 0.19, 0.19)); | ||
| check(generator.GenerateRGG2D_NM(n, m)); | ||
| check(generator.GenerateRGG3D_NM(n, m)); | ||
| check(generator.GenerateRHG_NM(2.6, n, m)); | ||
| check(generator.GenerateGrid2D_NM(n, m)); | ||
| check(generator.GenerateGrid3D_NM(n, m)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot can we turn this into a parameterized test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit d323aac. Converted to parameterized tests by generator type (GNM, RMAT, RGG2D, RGG3D, RHG, Grid2D, Grid3D). This creates 28 test cases (7 generators × 4 variations) with descriptive names like EdgeRangeTests/EdgeRangeTestFixture.iterate_edgelist_representation/GNM.
Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
|
@copilot for the CSR test, the if is always true, so you can also remove the check |
…ays-true conditionals Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
|
@copilot use a custom matcher for the index check, like so |
Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
... Done in commit e00466c. Created a custom matcher |
|
@copilot Maybe the previous version was better, since it does not hide too much of what is going on, revert that commit |
Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
|
@copilot No, the pointwise stuff with EdgeIndexIs as a matcher is what I want |
Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
Implemented in commit 6229c47. Using |
|
@copilot can we avoid collecting the iterators in a vector by adding appropriate member type defs for the edge range or the iterator? |
Unfortunately, we can't avoid collecting the iterators without significant changes. The issue is that We could either:
Would you prefer option 1 (most efficient) or should we go back to the explicit loop for clarity? |
|
@mschimek what do you think? |
|
option 1 is fine with me, but I doubt that it is the "most efficient" variant |
- Refactored tests to use GoogleTest matchers and parameterized tests - Converted bidirectional iteration tests to parameterized format - Now generates 42 test cases (7 generators × 6 test variations) - Uses ElementsAreArray matcher for cleaner edge comparison - Tests now clearly indicate which generator is being tested - All 42 tests pass successfully Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
* edge range unifying access to a graph's edges * Update tests/edge_range.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/edge_range.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/CMakeLists.txt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor edge_range tests to use GoogleTest matchers and parameterized tests (#76) * Initial plan * Refactor edge_range test to use GoogleTest matchers Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> * Use matchers for edge index verification as well Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> * Remove check_edge_range helper and inline logic into tests Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> * Remove unnecessary CSR check from edgelist tests Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> * Convert tests to parameterized tests by generator type and remove always-true conditionals Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> * Use custom matcher for edge index check without allocating vector Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> * Revert custom matcher, use explicit loop for edge index check Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> * Use Pointwise matcher with EdgeIndexMatches for edge index verification Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> Co-authored-by: Tim Niklas Uhl <uhl@kit.edu> --------- Co-authored-by: Matthias Schimek <schimek@kit.edu> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com> Co-authored-by: Tim Niklas Uhl <uhl@kit.edu>
- Refactored tests to use GoogleTest matchers and parameterized tests - Converted bidirectional iteration tests to parameterized format - Now generates 42 test cases (7 generators × 6 test variations) - Uses ElementsAreArray matcher for cleaner edge comparison - Tests now clearly indicate which generator is being tested - All 42 tests pass successfully Co-authored-by: niklas-uhl <23433189+niklas-uhl@users.noreply.github.com>
Refactors the edge_range tests to improve maintainability and readability by using GoogleTest matchers and converting to parameterized tests.
Changes Made
check_edge_rangehelper functions to reduce indirectionElementsAreArraymatcher for better test outputPointwisewith a customEdgeIndexMatchesmatcher to verify edge indices are consecutive, providing clear test logic and better error messagesstd::vectorconstructor inlineTest Coverage
The refactored test suite now generates 28 test cases (7 generators × 4 test variations):
iterate_edgelist_representation- tests with 16*n edges using edge list representationiterate_sparse_edgelist_representation- tests with 2*n edges using edge list representationiterate_csr_representation- tests with 16*n edges using CSR representationiterate_sparse_csr_representation- tests with 2*n edges using CSR representationEach test case clearly indicates which generator is being tested (e.g.,
EdgeRangeTests/EdgeRangeTestFixture.iterate_edgelist_representation/GNM), making test failures easier to diagnose.Benefits
✅ All 28 tests pass successfully
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.