Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
- Rename test
- Format tweak
  • Loading branch information
garydgregory committed Jan 7, 2025
1 parent d272066 commit fc3638e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/apache/commons/lang3/tuple/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ public <V, E extends Throwable> V apply(final FailableBiFunction<L, R, V, E> fun
*/
@Override
public int compareTo(final Pair<L, R> other) {
return new CompareToBuilder().append(getLeft(), other.getLeft())
.append(getRight(), other.getRight()).toComparison();
// @formatter:off
return new CompareToBuilder()
.append(getLeft(), other.getLeft())
.append(getRight(), other.getRight())
.toComparison();
// @formatter:on
}

/**
Expand Down
16 changes: 13 additions & 3 deletions src/test/java/org/apache/commons/lang3/tuple/PairTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testApply() {
}

@Test
public void testComparable1() {
public void testComparableAllDifferent() {
final Pair<String, String> pair1 = Pair.of("A", "D");
final Pair<String, String> pair2 = Pair.of("B", "C");
assertEquals(0, pair1.compareTo(pair1));
Expand All @@ -93,8 +93,18 @@ public void testComparable1() {

@Test
public void testComparableLeftEquals() {
final Pair<String, String> pair1 = Pair.of("A", "C");
final Pair<String, String> pair2 = Pair.of("A", "D");
final Pair<String, String> pair1 = Pair.of("E", "C");
final Pair<String, String> pair2 = Pair.of("E", "D");
assertEquals(0, pair1.compareTo(pair1));
assertTrue(pair1.compareTo(pair2) < 0);
assertEquals(0, pair2.compareTo(pair2));
assertTrue(pair2.compareTo(pair1) > 0);
}

@Test
public void testComparableRightEquals() {
final Pair<String, String> pair1 = Pair.of("A", "E");
final Pair<String, String> pair2 = Pair.of("B", "E");
assertEquals(0, pair1.compareTo(pair1));
assertTrue(pair1.compareTo(pair2) < 0);
assertEquals(0, pair2.compareTo(pair2));
Expand Down

0 comments on commit fc3638e

Please sign in to comment.