Skip to content

Commit 49c6f8d

Browse files
authored
Fix #293 regression. isGreaterThan(A)/isLesserThan(A) were not using strict inequality
1 parent 353507b commit 49c6f8d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

core/src/main/java/fj/Ord.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public boolean isGreaterThan(final A a1, final A a2) {
129129
* @return A function that returns true if its argument is less than the argument to this method.
130130
*/
131131
public F<A, Boolean> isLessThan(final A a) {
132-
return compose(o -> o != Ordering.LT, f.f(a));
132+
return compose(o -> o == Ordering.GT, f.f(a));
133133
}
134134

135135
/**
@@ -139,7 +139,7 @@ public F<A, Boolean> isLessThan(final A a) {
139139
* @return A function that returns true if its argument is greater than the argument to this method.
140140
*/
141141
public F<A, Boolean> isGreaterThan(final A a) {
142-
return compose(o -> o != Ordering.GT, f.f(a));
142+
return compose(o -> o == Ordering.LT, f.f(a));
143143
}
144144

145145
/**

core/src/test/java/fj/OrdTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fj;
2+
3+
import org.junit.Test;
4+
5+
import static org.hamcrest.CoreMatchers.is;
6+
import static org.hamcrest.MatcherAssert.assertThat;
7+
8+
public class OrdTest {
9+
10+
@Test
11+
public void isGreaterThan() {
12+
F<Long, Boolean> pred = Ord.longOrd.isGreaterThan(1L);
13+
14+
assertThat(pred.f(0L), is(false));
15+
assertThat(pred.f(1L), is(false));
16+
assertThat(pred.f(2L), is(true));
17+
}
18+
19+
@Test
20+
public void isLessThan() {
21+
F<Long, Boolean> pred = Ord.longOrd.isLessThan(1L);
22+
23+
assertThat(pred.f(0L), is(true));
24+
assertThat(pred.f(1L), is(false));
25+
assertThat(pred.f(2L), is(false));
26+
}
27+
}

0 commit comments

Comments
 (0)