[
https://issues.apache.org/jira/browse/NUMBERS-207?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17935769#comment-17935769
]
Gilles Sadowski commented on NUMBERS-207:
-----------------------------------------
Oops, that's a nasty one. :-(
Thanks a lot for the report.
I think that commit e429d6378ca4070623c3abe147b96d0e7e577f70 has fixed it.
WDYT?
> Fraction and BigFraction compareTo incorrect for negative values
> ----------------------------------------------------------------
>
> Key: NUMBERS-207
> URL: https://issues.apache.org/jira/browse/NUMBERS-207
> Project: Commons Numbers
> Issue Type: Bug
> Components: fraction
> Affects Versions: 1.2
> Reporter: Richard Mullender
> Priority: Major
>
> Both `Fraction` and `BigFraction` display incorrect `compareTo` behaviour
> when comparing negative fractions against one another.
> See the below test class:
> {code:java}
> public class FractionTest {
> @Test
> public void testFraction() {
> var fraction1 = org.apache.commons.numbers.fraction.Fraction.of(-10,
> 1);
> var fraction2 = org.apache.commons.numbers.fraction.Fraction.of(-5, 1);
>
> assert fraction1.compareTo(fraction2) < 0;
> }
>
> @Test
> public void testBigFraction() {
> var fraction1 =
> org.apache.commons.numbers.fraction.BigFraction.of(-10, 1);
> var fraction2 = org.apache.commons.numbers.fraction.BigFraction.of(-5,
> 1);
>
> assert fraction1.compareTo(fraction2) < 0;
> }
>
> @Test
> public void testApacheLang3() {
> var fraction1 =
> org.apache.commons.lang3.math.Fraction.getFraction(-10, 1);
> var fraction2 = org.apache.commons.lang3.math.Fraction.getFraction(-5,
> 1);
>
> assert fraction1.compareTo(fraction2) < 0;
> }
> }
> {code}
>
> Out of these three tests, only Lang3's Fraction passes. The other two tests
> (fraction.Fraction and fraction.BigFraction) fail.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)