Skip to content
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

Add spiral-matrix #942

Merged
merged 10 commits into from
Feb 24, 2024
Merged

Add spiral-matrix #942

merged 10 commits into from
Feb 24, 2024

Conversation

ryanplusplus
Copy link
Member

Related to #940

Comment on lines 25 to 26
printf("expected[%d][%d] = %d\n", i, j, expected_matrix[i][j]);
printf("actual[%d][%d] = %d\n", i, j, actual->matrix[i][j]);
Copy link
Member Author

Choose a reason for hiding this comment

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

Because the check is pretty opaque (it tells you whether it matches, but that's it), I added in these prints to show where the first difference is when there's a failure.

Copy link
Contributor

Choose a reason for hiding this comment

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

How does this look when the tests run and have their standard output?
Would it interfere with how the web IDE detects pass/fail ?

Copy link
Member Author

@ryanplusplus ryanplusplus Feb 24, 2024

Choose a reason for hiding this comment

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

With this, the output for a failure is:

expected[0][0] = 1
actual[0][0] = 0
./test_spiral_matrix.c:52:test_trivial_spiral:FAIL: Expected TRUE Was FALSE

Without it, the output is:

./test_spiral_matrix.c:52:test_trivial_spiral:FAIL: Expected TRUE Was FALSE

Would it interfere with how the web IDE detects pass/fail ?

I don't think it will since the failure is still present, but I'm not sure whether it will show the console output in addition to the failure text.

Looking through the Unity docs I think I should be able to compare each row in the array. This should give enough context to understand where the failure is because each cell has a unique value.

Copy link
Member Author

Choose a reason for hiding this comment

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

With Unity's array matcher, the output is:

./test_spiral_matrix.c:22:test_spiral_of_size_5:FAIL: Element 2 Expected 25 Was 0

I think that's sufficient to work out where the error is even without knowing the row number.

@ryanplusplus ryanplusplus mentioned this pull request Jan 27, 2024
12 tasks
Copy link
Contributor

@wolf99 wolf99 left a comment

Choose a reason for hiding this comment

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

Sorry that it took me so long to review this!
Just a few small nits


void spiral_matrix_destroy(spiral_matrix_t *spiral_matrix)
{
for (int i = 0; i < spiral_matrix->size; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

size_t i maybe?

Comment on lines 25 to 26
printf("expected[%d][%d] = %d\n", i, j, expected_matrix[i][j]);
printf("actual[%d][%d] = %d\n", i, j, actual->matrix[i][j]);
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this look when the tests run and have their standard output?
Would it interfere with how the web IDE detects pass/fail ?


spiral_matrix_t *spiral_matrix_create(int size)
{
spiral_matrix_t *spiral_matrix = calloc(1, sizeof(spiral_matrix_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nit:
Consider refactoring type and variable names from spiral_matrix to spiral so that we then have a nice spiral->matrix during use?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, good idea

@ryanplusplus
Copy link
Member Author

Sorry that it took me so long to review this! Just a few small nits

No worries, thanks for the review!

Copy link
Contributor

@wolf99 wolf99 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ryanplusplus ryanplusplus merged commit eb38a73 into main Feb 24, 2024
4 checks passed
@ryanplusplus ryanplusplus deleted the spiral-matrix branch February 24, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants