parent
e0a1164cf5
commit
fa2231788f
@ -41,14 +41,14 @@ public class FindKthNumberTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFindKthMaxLargeArray() {
|
public void testFindKthMaxLargeArray() {
|
||||||
int[] array = generateArray(1000);
|
int[] array = generateArray(1000);
|
||||||
int k = new Random().nextInt(array.length);
|
int k = new Random().nextInt(1, array.length);
|
||||||
int result = FindKthNumber.findKthMax(array, k);
|
int result = FindKthNumber.findKthMax(array, k);
|
||||||
Arrays.sort(array);
|
Arrays.sort(array);
|
||||||
assertEquals(array[array.length - k], result);
|
assertEquals(array[array.length - k], result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] generateArray(int capacity) {
|
public static int[] generateArray(int capacity) {
|
||||||
int size = new Random().nextInt(capacity) + 1;
|
int size = new Random().nextInt(2, capacity);
|
||||||
int[] array = new int[size];
|
int[] array = new int[size];
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user