not sure how to go about defining equalities, intersections, and differences. I keep getting assertion or type errors.
note: class Interval cannot be edited
56 messages ยท Page 1 of 1 (latest)
not sure how to go about defining equalities, intersections, and differences. I keep getting assertion or type errors.
note: class Interval cannot be edited
@fast helm
Remember to:
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
don't use &
Use and
You're not comparing properly
Do one comparison individually
Interval(3,10) == Interval(6,10)
But I don't think you're using either functions properly
how would i use the functions properly?
You call them
oh wait you're overloading the methods
then it should be fine
Do individual comparisons
You need to parenthesize since == has higher precedence than 'and'
assert (Interval1 and Interval2) == Interval3
no you have to compare individually
like this
assert Interval(3,10) == Interval(6,10)
Do you also have a custom equal comparator?
If you want to compare both at the same time, you can add and after that
assert Interval(3,10) == Interval(6,10) and Interval(6,20) == Interval(6,10)
(i.e. Did you override __eq__)
OP did
No, he wants to get the intersection of both, so using 'and' is correct .
U sure that indent is right?
You return before it can reach Interval.__eq__ = func
Your interval equality check seems strange. It only checks if the other interval is an Interval.
You should be checking if the endpoints are equal too?
Oh good catch.
the parts that say test were written by the prof to grade the def, not sure if i am allowed to edit those or why they are the way they are
how do i fix this?
Unindent?
The others funcs don't seem like they have this issue
Wait, then the test is correct, it should be bitwise and (&) instead of logical and (and)
I'd assume you're meant to change those def, then if you pass the tests you get the points
No need to parenthesize now, but change the asserts back to use bitwise and (&)
Dunder __and__ overrides bitwise and
Now the problem is that your equality check doesn't work
As I said, you need to do more than just test for 'other' being an Interval.
Two intervals are equal if and only if their corresponding endpoints are equal.
Also, make sure you have overridden dunder __ne__
(as a shortcut, you can define __ne__ using __eq__)
__ne__
Oh my bad
But you don't have to, it uses the inverted result of eq by default
Anyway,
now it's correctly setting the funcs, now change the defs so the tests pass
Is this also true for say lt and ge?
If so, what's the 'minimum' that I need to override?
Or any docs I can read about this?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.