Improve unit test coverage for plane and slicer geometry logic - #119
Improve unit test coverage for plane and slicer geometry logic#119Kavyashah067 wants to merge 3 commits into
Conversation
alessandrofelder
left a comment
There was a problem hiding this comment.
Thanks for your contribution @Kavyashah067
This looks largely good. I have some small questions and small suggestions for improvement.
|
|
||
| plane = Plane.from_norm(origin, normal) | ||
|
|
||
| assert np.allclose(np.abs(plane.normal), np.array([0, 0, 1])) |
There was a problem hiding this comment.
Do we need the np.abs here? If so, is this a bug in the main source code 🤔 (I would expect a .from_norm function of a plane to return a plane with (close to) the same normal.
There was a problem hiding this comment.
Thanks for pointing that out!
I’ve removed np.abs so the test now checks the direction of the normal directly.
| get_ax_idx("Frontal") | ||
|
|
||
|
|
||
| class DummyRoot: |
There was a problem hiding this comment.
Would it be possible to not use a dummy class here, and either use a mocking framework or a simple instance of the actual class instead?
There was a problem hiding this comment.
Thanks for the suggestion!
I’ve replaced the dummy class with MagicMock to better reflect real object behavior and keep the test more flexible.
|
|
||
| plane = Plane(origin, u, v) | ||
|
|
||
| points_3d = np.array([[1, 2, 0], [3, 4, 0]]) |
There was a problem hiding this comment.
Is it worth testing this with points_3d that are not already in the plane?
There was a problem hiding this comment.
That’s a good suggestion, thanks!
I’ve updated the test to use points that aren’t already in the plane so the projection logic is properly validated.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #119 +/- ##
===========================================
+ Coverage 69.63% 93.73% +24.10%
===========================================
Files 5 5
Lines 326 367 +41
===========================================
+ Hits 227 344 +117
+ Misses 99 23 -76 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
What is this PR
Unit Test Coverage for the plane and slicing components of brainglobe-heatmap.
Why is this PR needed?
The slicing pipeline depends on the geometric accuracy within the plane.py and slicer.py. Improving unit test coverage for mathematical core of the code to increase the reliability and secure foundation for future enhancements or feature implementation.
What does this PR do?
This PR adds unit tests covering:
(p3_to_p2)center_of_massget_ax_idxorientation handlingReferences
Brainglobe Heatmap Documentation
How has this PR been tested?
All tests were run locally using pytest and ensured existing implementation and unit test continue to pass.
Pre-commit checks passed.
Coverage was verified using.
pytest --cov=brainglobe_heatmap --cov-report=term-missingCoverage Impact:
-- plane.py: 70% → 88%
-- slicer.py: 58% → 66%
-- Overall coverage: 71% → 74%
Is this a breaking change?
No
Does this PR require an update to the documentation?
No
Checklist: