Skip to content

Commit 9036e10

Browse files
committed
Bug: no assert... in test ArraysTest.testArraysBinarySearchString2
The assert was commented-out because it failed. The bug was is the test code: no comparator was passed to Arrays.binarySearch, thus given an undefined result as the array was not sorted in natural order, but a "user defined" one.
1 parent 6df6a98 commit 9036e10

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/net.sf.j2s.test.junit/src/net/sf/j2s/test/junit/ArraysTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ public int compare(String o1, String o2) {
8484
}
8585
public void testArraysBinarySearchString2() {
8686
String[] bs = new String[] {"Hello", "World", "JavaScript", "AJAX", "SWT", "JavaScript"};
87-
Arrays.sort(bs, new Comparator<String>() {
87+
Comparator<String> comp = new Comparator<String>() {
8888
public int compare(String o1, String o2) {
8989
return o1.charAt(1) - o2.charAt(1);
9090
}
91-
});
92-
// int idx = Arrays.binarySearch(bs, "SWT");
93-
// assertEquals(1, idx);
91+
};
92+
Arrays.sort(bs, comp);
93+
94+
int idx = Arrays.binarySearch(bs, "SWT", comp);
95+
assertEquals(1, idx);
9496
}
97+
9598
public void testArraysEqualsString2() {
9699
String[] bs1 = new String[] {"Hello", "World", "JavaScript", "AJAX", "SWT", "JavaScript"};
97100
String[] bs2 = new String[] {"Hello", "World", "JavaScript", "AJAX", "SWT", "JavaScript"};

0 commit comments

Comments
 (0)