Skip to content

Add function to invert constraints and ranges #91 - #92

Merged
TG1999 merged 6 commits into
aboutcode-org:mainfrom
TG1999:inverse
Nov 23, 2022
Merged

Add function to invert constraints and ranges #91#92
TG1999 merged 6 commits into
aboutcode-org:mainfrom
TG1999:inverse

Conversation

@TG1999

@TG1999 TG1999 commented Nov 9, 2022

Copy link
Copy Markdown
Contributor

Signed-off-by: Tushar Goel tushar.goel.dav@gmail.com

We have invert of every operator:

>= : <
<= : >
!= : =
< : >=
> : <=
= : !=

But we don't have any inversion for star operator currently, what should we do for that ?

Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
@TG1999
TG1999 requested a review from pombredanne November 9, 2022 17:13
@TG1999

TG1999 commented Nov 9, 2022

Copy link
Copy Markdown
Contributor Author

@pombredanne I made inversion of each comparator here:

INVERTED_COMPARATORS = {
    ">=": "<",
    "<=": ">",
    "!=": "=",
    "<": ">=",
    ">": "<=",
    "=": "!=",
    "*": "^",
    "^": "*",
}

would like to get your opinion on this

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks... see some comments for your review

Comment thread src/univers/version_constraint.py Outdated
Comment thread src/univers/version_constraint.py Outdated
Comment thread src/univers/version_constraint.py Outdated
Comment thread src/univers/version_range.py Outdated
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!
see my review inline for your consideration.
IMHO the inversion should be first a method on a constraint and then second a range method that use the constraints method.
We would need a few unit tests rather than only data driven tests, and we could get fewer tests by removing duplicated tests.

Comment thread src/univers/version_range.py Outdated
Comment thread src/univers/version_range.py Outdated
Comment thread src/univers/version_range.py Outdated
Comment thread src/univers/version_range.py
Comment thread tests/data/inverse-data.json Outdated
Comment thread src/univers/version_range.py Outdated
Comment thread src/univers/version_range.py Outdated
Comment thread src/univers/version_range.py Outdated
Add unit tests for each kind

Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. Here are a few extra nit pickings for your consideration.

Comment thread src/univers/version_constraint.py
Comment thread tests/test_version_range.py Outdated
assert str(result) == test_case["expected_vers"]


def test_inverse():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
@pombredanne pombredanne changed the title Add inverse function to VersionRange #91 Add function to invert constraints and ranges #91 Nov 21, 2022

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!
👍

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.

2 participants