wolandscat / EOMF

Application framework for Eiffel apps
6 stars 3 forks source link

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

Open ghost opened 8 years ago

ghost commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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