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

Fix implementation of isEmpty and overlaps in Interval.hs #3042

Merged
merged 2 commits into from
May 4, 2021

Conversation

norman-thomas
Copy link
Contributor

@norman-thomas norman-thomas commented Apr 20, 2021

A fellow Plutus Pioneer Program student (BC Chuah) noticed an odd behavior of the overlaps function.

Upon further investigation, I noticed that both overlaps and isEmpty needed a change to work as expected.

Pre-submit checklist:

  • Branch
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Relevant tickets are mentioned in commit messages
    • Formatting, materialized Nix files, PNG optimization, etc. are updated
  • PR
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

Pre-merge checklist:

  • Someone approved it
  • Commits have useful messages
  • Review clarifications made it into the code
  • History is moderately tidy; or going to squash-merge

Copy link
Contributor

@j-mueller j-mueller left a comment

Choose a reason for hiding this comment

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

The implementation looks ok now, thank you.

You could add some property tests for this to plutus-ledger/test/Spec.hs as well. For example, every non-empty interval overlaps with itself. There are some examples already.

@@ -225,7 +225,7 @@ member a i = i `contains` singleton a
-- | Check whether two intervals overlap, that is, whether there is a value that
-- is a member of both intervals.
overlaps :: Ord a => Interval a -> Interval a -> Bool
overlaps l r = isEmpty (l `intersection` r)
overlaps l r = not $ isEmpty (l `intersection` r)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops!

@norman-thomas
Copy link
Contributor Author

norman-thomas commented Apr 21, 2021

Sure, I already started implementing basic test cases, e.g.
norman-thomas@ff495db

Am currently familiarizing myself more with Haskell and (property based) testing in Haskell before daring to submit those.
I will follow up shortly with the tests.

Thanks for the example and pointing me in the direction!

@norman-thomas norman-thomas force-pushed the master branch 3 times, most recently from fd446cb to 398dab9 Compare April 25, 2021 19:41
@norman-thomas norman-thomas marked this pull request as draft April 25, 2021 19:59
@norman-thomas norman-thomas marked this pull request as ready for review April 26, 2021 07:06
@norman-thomas
Copy link
Contributor Author

@j-mueller

I added a couple of test cases covering isEmpty, overlaps and intersection.

Sadly, the Hydra CI check fails, but it seems to be failing in master as well.

@michaelpj
Copy link
Contributor

Flaky VM test, restarted.

@norman-thomas norman-thomas requested a review from j-mueller May 1, 2021 18:24
Copy link
Contributor

@j-mueller j-mueller left a comment

Choose a reason for hiding this comment

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

Great, thanks for adding the tests.

@michaelpj michaelpj merged commit 58bf9ed into IntersectMBO:master May 4, 2021
@ghost ghost mentioned this pull request May 4, 2021
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.

3 participants