Skip to content

test: add comprehensive test suite for intervals.py#116

Merged
schewskone merged 20 commits intosensorium-competition:mainfrom
VaibhavGarg2003:test-intervals-math
Mar 13, 2026
Merged

test: add comprehensive test suite for intervals.py#116
schewskone merged 20 commits intosensorium-competition:mainfrom
VaibhavGarg2003:test-intervals-math

Conversation

@VaibhavGarg2003
Copy link
Copy Markdown
Contributor

@VaibhavGarg2003 VaibhavGarg2003 commented Mar 5, 2026

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

Copilot AI review requested due to automatic review settings March 5, 2026 19:14
@gitnotebooks
Copy link
Copy Markdown

gitnotebooks bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

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

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.

Copy link
Copy Markdown
Contributor

@pollytur pollytur left a comment

Choose a reason for hiding this comment

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

I noticed that the experanto.intervals module didn't have any test coverage.

This is not true. TimeInterval are partially tested here and here

Please look at this files first and remove duplicated testing / integrate your tests in them

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@VaibhavGarg2003
Copy link
Copy Markdown
Contributor Author

@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.

@VaibhavGarg2003 VaibhavGarg2003 requested a review from pollytur March 6, 2026 14:39
Copy link
Copy Markdown
Contributor

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

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.

Copy link
Copy Markdown
Contributor

@pollytur pollytur left a comment

Choose a reason for hiding this comment

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

Thanks for iterating, @VaibhavGarg2003 !

Here is some feedback:
Required changes:

  1. Please integrate the tests in the corresponding existing file instead of creating a new one
  2. Please use @pytest.mark.parametrize instead 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

@VaibhavGarg2003
Copy link
Copy Markdown
Contributor Author

Thanks for the detailed feedback, @pollytur , I've made all the requested changes:

  1. Integrated all tests into test_time_intervals_interpolator.py and deleted the separate test_intervals.py file.
  2. Refactored all structurally identical test functions to use @pytest.mark.parametrize.
  3. Removed test_stats_returns_string and test_time_interval_repr as they were testing output format, not Experanto logic.

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)
Intersection is contained in both parent intervals
uniquefy is idempotent (running it twice = running it once)
uniquefy preserves coverage (no covered points are lost)
Complement + original intervals cover the full range

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).

@pollytur
Copy link
Copy Markdown
Contributor

pollytur commented Mar 9, 2026

@VaibhavGarg2003 thanks for the fast update
please add hypothesis to the dev section of the .toml file - otherwise the CI/CD tests fails since they are missing a requirement

Copy link
Copy Markdown
Contributor

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

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.

@pollytur
Copy link
Copy Markdown
Contributor

pollytur commented Mar 9, 2026

@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

Copy link
Copy Markdown
Contributor

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

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.

@VaibhavGarg2003
Copy link
Copy Markdown
Contributor Author

@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.

Copy link
Copy Markdown
Contributor

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

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.

@VaibhavGarg2003
Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

@pollytur pollytur left a comment

Choose a reason for hiding this comment

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

Thanks
this looks good for me :)

Copy link
Copy Markdown
Collaborator

@schewskone schewskone left a comment

Choose a reason for hiding this comment

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

@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 :)

@VaibhavGarg2003
Copy link
Copy Markdown
Contributor Author

@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.

@schewskone schewskone merged commit c4b57d1 into sensorium-competition:main Mar 13, 2026
5 checks passed
@VaibhavGarg2003 VaibhavGarg2003 deleted the test-intervals-math branch March 13, 2026 12:01
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.

4 participants