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

Possible a problem in EOMF/library/basic/data_structures/proper_interval.e #2

Open
ghost opened this issue Jan 28, 2016 · 2 comments
Open

Comments

@ghost
Copy link

ghost commented Jan 28, 2016

I don't know if this is the right place to announce it, nor do I know if it is an error. So forgive me if I make noise for nothing.

The possible problem is in the method intersects in proper_interval.e

It is possible that I don't understand the Eiffel code well, I am not used to work with it.
But, OK, what I see:

Imagine two intervals, one 3..7 and the other, 8..10. They do not intersect. So the result should be false. When I run them in my converted Javacode, the test fails at the last line of the method, which says in Eiffel:
((attached other.lower as other_l and then attached upper as u and then u >= other_l) OR
(attached other.upper as other_u and then attached lower as l and then l <= other_u))

Lower should not be smaller then the other.upper (because the result must be FALSE, doesn't it? But lower is smaller then the other.upper, so the function returns TRUE were it should return FALSE.

I think it must be AND where now I emphasized with OR


Definition in comment: Does current interval properly contain `other'? True if at least one limit of other is stricly inside the limits of this interval

I wrote it this way in Java:
In Java Comparables are compared in this way. Although the function seems complex there is a trick to read what it does easy. Replace the function compareTo with the operator behind it, and forget the 0.
So
boolean l_ol = lower.compareTo(other.lower) > 0;
should be read as
boolean l_ol = lower > (other.lower);

            boolean l_ol = lower.compareTo(other.lower) > 0; //(lower > other.lower)
            boolean l_ou = lower.compareTo(other.upper) > 0;//(etc)
            boolean u_ol = upper.compareTo(other.lower) > 0;//(etc)
            boolean u_ou = upper.compareTo(other.upper) > 0;//(etc)
            return (l_ol && l_ou && u_ol && u_ou)!=(l_ol || l_ou || u_ol || u_ou);

In case of 3..5 and 6..8 all comparisons are FALSE //(=not contains)
In case of 3..5 and 1..2 all comparisons are TRUE. //(=not contains)
So the return value must have one or more but not all unequal boolean, and then the contains-rule counts:

@wolandscat
Copy link
Owner

I just got the time to set up some unit tests. You are right, there are a couple of errors. I'll fix my classes, but in the meantime, you may as well build the logic in yours according to your preference. Thanks for the error report.

@ghost
Copy link
Author

ghost commented Jan 29, 2016

I hope I understood the intended purpose of the functions well. I will check that later.

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

No branches or pull requests

1 participant