test: add comprehensive test suite for intervals.py#116
test: add comprehensive test suite for intervals.py#116schewskone merged 20 commits intosensorium-competition:mainfrom
Conversation
|
Review these changes at https://app.gitnotebooks.com/sensorium-competition/experanto/pull/116 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…003/experanto into test-intervals-math
|
@pollytur , you were right about the partial coverage in the interpolator tests, I've removed the duplicated logic. I kept the standalone math tests in test_intervals.py to keep the unit tests isolated from the interpolator logic. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pollytur
left a comment
There was a problem hiding this comment.
Thanks for iterating, @VaibhavGarg2003 !
Here is some feedback:
Required changes:
- Please integrate the tests in the corresponding existing file instead of creating a new one
- Please use
@pytest.mark.parametrizeinstead of many separate more or less same functions.
e.g. few separate functions (test_complement_of_empty,test_complement_gap_in_middle, etc.) are structurally identical. This should be sth like
@pytest.mark.parametrize("intervals,start,end,expected", [
([], 0.0, 10.0, [TimeInterval(0.0, 10.0)]), # empty → full range
([TimeInterval(0.0, 10.0)], 0.0, 10.0, []), # full coverage → empty
([TimeInterval(3.0, 10.0)], 0.0, 10.0, [TimeInterval(0.0, 3.0)]), # gap at start
([TimeInterval(0.0, 7.0)], 0.0, 10.0, [TimeInterval(7.0, 10.0)]), # gap at end
([TimeInterval(0.0, 3.0), TimeInterval(7.0, 10.0)], 0.0, 10.0, [TimeInterval(3.0, 7.0)]), # middle gap
([TimeInterval(1.0, 3.0), TimeInterval(5.0, 7.0)], 0.0, 10.0,
[TimeInterval(0.0, 1.0), TimeInterval(3.0, 5.0), TimeInterval(7.0, 10.0)]), # multiple gaps
([TimeInterval(1.0, 5.0), TimeInterval(3.0, 7.0)], 0.0, 10.0,
[TimeInterval(0.0, 1.0), TimeInterval(7.0, 10.0)]), # overlapping input
])
def test_complement(intervals, start, end, expected):
assert find_complement_of_interval_array(start, end, intervals) == expected
this makes it infinitely shorter and more readable and easier to comprehend
3) Why do you return strings? (e.g. test_stats_returns_string?) please remove this strings and test the experanto logic. The test_stats_returns_string should go completely. Same for test_time_interval_repr
I probably have missed sth but lets start from here and iterate
Optional:
Ideally also write some tests against against invariants, not specific examples. (this is something we have not done much in experanto yet but ideally we should)
take a look at the hypothesis library, specifically at the following
from hypothesis import given, assume, settings
from hypothesis import strategies as st
from hypothesis.strategies import composite
and how to use it
…003/experanto into test-intervals-math
|
Thanks for the detailed feedback, @pollytur , I've made all the requested changes:
I also took your optional suggestion and added 5 property-based tests using hypothesis that verify mathematical invariants: Intersection is commutative (a ∩ b == b ∩ a) Quick question: hypothesis is not currently in the project's test dependencies. Should I add it to pyproject.toml, or would you prefer I use pytest.importorskip("hypothesis") so these tests are skipped gracefully when it's not installed? All 71 tests pass locally (5 expected warnings from inverted interval tests). |
|
@VaibhavGarg2003 thanks for the fast update |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@VaibhavGarg2003 please merge main into your current branch. There are no requirements.txt anymore and when you would merge main - the CI/CD should install from .toml file |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@pollytur I've just merged main into my branch, it should be fully synced and ready to use the .toml file for CI. Thanks for the heads up. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Yes @pollytur , it is completely redundant now that the property-based test is handling it. I've just deleted the old hardcoded test_two_interval_intersection_commutative function to keep the test suite clean and pushed the update. Also updated hypothesis version, tell me if everything is good. |
pollytur
left a comment
There was a problem hiding this comment.
Thanks
this looks good for me :)
schewskone
left a comment
There was a problem hiding this comment.
@VaibhavGarg2003 Thanks a lot for the PR. Only found 2 test cases that might be missing, please add them or let me know why they don't make sense. Also please merge the most recent main branch, there should be no conflicts.
Happy to merge after :)
Co-authored-by: Schewski <109431200+schewskone@users.noreply.github.com>
…anto into test-intervals-math
|
@schewskone ,Added the overlapping/unsorted test via your suggestion, and added the boundary touching test to match the logic in 548. Also merged the latest main. Should be good to go. |
While digging into the filtering pipeline to research my GSoC proposal (specifically Issue #92 and PR #85), I noticed that the experanto.intervals module didn't have any test coverage. Since the entire filtering system relies on this core math to work correctly, I wanted to build a solid safety net for it before proposing any new features that rely on it.
What this PR does:-
I added 50+ pytest cases into the existing tests/test_time_intervals_interpolator.py. This tests all the core utility functions and brings the coverage for that module to nearly 100%.
I made sure to test the standard scenarios along with the tricky edge cases, such as:
Completely empty arrays
Zero length (touching) intervals
Unsorted inputs being passed in
Overlapping and adjacent interval merges