-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Add spiral-matrix #942
Conversation
printf("expected[%d][%d] = %d\n", i, j, expected_matrix[i][j]); | ||
printf("actual[%d][%d] = %d\n", i, j, actual->matrix[i][j]); |
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.
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.
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.
How does this look when the tests run and have their standard output?
Would it interfere with how the web IDE detects pass/fail ?
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.
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.
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.
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.
615d01b
to
fc54fbc
Compare
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.
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++) { |
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.
size_t i
maybe?
printf("expected[%d][%d] = %d\n", i, j, expected_matrix[i][j]); | ||
printf("actual[%d][%d] = %d\n", i, j, actual->matrix[i][j]); |
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.
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)); |
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.
Small nit:
Consider refactoring type and variable names from spiral_matrix
to spiral
so that we then have a nice spiral->matrix
during use?
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.
Sure, good idea
No worries, thanks for the review! |
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.
LGTM 👍
Related to #940