Conversation
ca79697 to
47b1d51
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive test coverage for the layer.cpp module using the Catch2 testing framework. The tests validate layer operations including cell value management, barriers, edge tracing, and grid integration.
Changes:
- Added
test_layer.cppwith 663 lines of test cases covering layer functionality - Updated
CMakeLists.txtto include the new test file in the build configuration and add private-include directory access
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/tests/test_layer.cpp | New comprehensive test suite for layer.cpp functionality including cell operations, barriers, edge tracing, and grid interactions |
| lib/CMakeLists.txt | Added test_layer.cpp to test suite build and included private headers directory |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/tests/test_layer.cpp
Outdated
| int_vector_free(j_list); | ||
| } | ||
|
|
||
| THEN("The count of cells equal to 7 is thee") { |
There was a problem hiding this comment.
Corrected spelling of 'thee' to 'three'.
| THEN("The count of cells equal to 7 is thee") { | |
| THEN("The count of cells equal to 7 is three") { |
lib/tests/test_layer.cpp
Outdated
| } | ||
| } | ||
|
|
||
| AND_GIVEN("A 3x3x block at the far corner") { |
There was a problem hiding this comment.
Corrected 'A 3x3x block' to 'A 3x3 block' (removed extra 'x').
| AND_GIVEN("A 3x3x block at the far corner") { | |
| AND_GIVEN("A 3x3 block at the far corner") { |
lib/tests/test_layer.cpp
Outdated
| } | ||
| } | ||
|
|
||
| THEN("Traceing from a starting point not on edge traces the " |
There was a problem hiding this comment.
Corrected spelling of 'Traceing' to 'Tracing'.
| THEN("Traceing from a starting point not on edge traces the " | |
| THEN("Tracing from a starting point not on edge traces the " |
47b1d51 to
c476b43
Compare
|
Superseded by #1120 |
ajaust
left a comment
There was a problem hiding this comment.
I only have minor things and the pointers you have already fixed. You have to see if you want to change anything based on my comments. 🙂
| } | ||
| } | ||
| AND_GIVEN("A layer of the same size") { | ||
| layer_type *dst = layer_alloc(nx, ny); |
| } | ||
| } | ||
|
|
||
| layer_free(dst); |
There was a problem hiding this comment.
Can be deleted if we use a smart pointer.
| GIVEN("A layer") { | ||
| int nx = 10; | ||
| int ny = 8; | ||
| layer_type *layer = layer_alloc(nx, ny); |
There was a problem hiding this comment.
I am not sure if this is freed if any of the tests fail before reaching the free.
I think we could wrap it in a smart like pointer like this.
| layer_type *layer = layer_alloc(nx, ny); | |
| std::unique_ptr<layer_type, decltype(&layer_free)> layer(layer_alloc(nx, ny), layer_free); |
I am not sure about the decltype, but something like this should work.
| int_vector_type *i_list = int_vector_alloc(0, 0); | ||
| int_vector_type *j_list = int_vector_alloc(0, 0); |
| int_vector_free(i_list); | ||
| int_vector_free(j_list); |
There was a problem hiding this comment.
Can be removed if we use smart pointers.
| REQUIRE(layer_iget_cell_value(layer, i, j) == 7); | ||
| } | ||
| } | ||
| REQUIRE(layer_get_cell_sum(layer) == 7 * 10 * 8); |
There was a problem hiding this comment.
Consider replacing the magic numbers 10 and 8 by nx and ny since they have names within the test.
| AND_GIVEN("A cell is set to some value") { | ||
| layer_iset_cell_value(layer, 2, 2, 10); | ||
|
|
||
| THEN("RIGHT and BOTTOM have that value for, negated for the " |
There was a problem hiding this comment.
- I don't if I fully understand this
THENclause. Should it read"RIGHT and BOTTOM have that value, negated for the others"? - Does this
THENclause contain two strings on purpose?"RIGHT and BOTTOM have that value for, negated for the "and"others".
There was a problem hiding this comment.
This was two strings because of formatting, I split it into two groups to be clear.
| for (int i = 0; i < 5; i++) { | ||
| for (int j = 0; j < 5; j++) { |
There was a problem hiding this comment.
Are all cells connected or only the cells [0,5] in both directions?
| THEN("Barrier is present at expected locations") { | ||
| REQUIRE(layer_iget_left_barrier(layer, 2, 1) == true); | ||
| REQUIRE(layer_iget_left_barrier(layer, 2, 2) == true); | ||
| REQUIRE(layer_iget_left_barrier(layer, 3, 1) == false); |
There was a problem hiding this comment.
Could we use REQUIRE_FALSE here as in the tests above and below? I guess we could also remove the == true as this is not done in other tests.
There was a problem hiding this comment.
Fixed everywhere.
| REQUIRE(corner_list == | ||
| std::vector<int_point2d_type>{{2, 2}, | ||
| {3, 2}, | ||
| {4, 2}, | ||
| {5, 2}, | ||
| {5, 3}, | ||
| {5, 4}, | ||
| {5, 5}, | ||
| {4, 5}, | ||
| {3, 5}, | ||
| {2, 5}, | ||
| {2, 4}, | ||
| {2, 3}}); |
There was a problem hiding this comment.
I guess these values make sense. I did not look into the logic for defining the corners, but I find it somewhat confusing. We have a 3x3 block, but the list of corners is containing something like 2x2 block.
5 # # # #
4 # #
j 3 # #
2 # # # #
1
1 2 3 4 5
i
There was a problem hiding this comment.
I added your diagram to the test.
No description provided.