Skip to content

Add tests for layer.cpp#1119

Closed
eivindjahren wants to merge 1 commit intomainfrom
fix_layer
Closed

Add tests for layer.cpp#1119
eivindjahren wants to merge 1 commit intomainfrom
fix_layer

Conversation

@eivindjahren
Copy link
Collaborator

No description provided.

@eivindjahren eivindjahren self-assigned this Feb 12, 2026
@eivindjahren eivindjahren moved this to Ready for Review in SCOUT Feb 12, 2026
@eivindjahren eivindjahren requested a review from Copilot February 12, 2026 14:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.cpp with 663 lines of test cases covering layer functionality
  • Updated CMakeLists.txt to 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.

int_vector_free(j_list);
}

THEN("The count of cells equal to 7 is thee") {
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'thee' to 'three'.

Suggested change
THEN("The count of cells equal to 7 is thee") {
THEN("The count of cells equal to 7 is three") {

Copilot uses AI. Check for mistakes.
}
}

AND_GIVEN("A 3x3x block at the far corner") {
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected 'A 3x3x block' to 'A 3x3 block' (removed extra 'x').

Suggested change
AND_GIVEN("A 3x3x block at the far corner") {
AND_GIVEN("A 3x3 block at the far corner") {

Copilot uses AI. Check for mistakes.
}
}

THEN("Traceing from a starting point not on edge traces the "
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'Traceing' to 'Tracing'.

Suggested change
THEN("Traceing from a starting point not on edge traces the "
THEN("Tracing from a starting point not on edge traces the "

Copilot uses AI. Check for mistakes.
@eivindjahren
Copy link
Collaborator Author

Superseded by #1120

@github-project-automation github-project-automation bot moved this from Ready for Review to Done in SCOUT Feb 13, 2026
Copy link

@ajaust ajaust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Candidate for unique_ptr.

}
}

layer_free(dst);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Comment on lines +283 to +284
int_vector_type *i_list = int_vector_alloc(0, 0);
int_vector_type *j_list = int_vector_alloc(0, 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential candidates for unique_ptr.

Comment on lines +292 to +293
int_vector_free(i_list);
int_vector_free(j_list);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing the magic numbers 10 and 8 by nx and ny since they have names within the test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this, should be in PR #1120

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 "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I don't if I fully understand this THEN clause. Should it read "RIGHT and BOTTOM have that value, negated for the others"?
  • Does this THEN clause contain two strings on purpose? "RIGHT and BOTTOM have that value for, negated for the " and "others".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was two strings because of formatting, I split it into two groups to be clear.

Comment on lines +176 to +177
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed everywhere.

Comment on lines +359 to +371
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}});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added your diagram to the test.

@github-project-automation github-project-automation bot moved this from Done to Reviewed in SCOUT Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants