mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-24 21:14:00 +08:00
test using rand numbers
This commit is contained in:
@ -1,11 +1,26 @@
|
||||
package Maths;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
public class FindMin {
|
||||
|
||||
//Driver
|
||||
/**
|
||||
* Driver Code
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
int[] array = {2, 4, 9, 7, 19, 94, 5};
|
||||
assert findMin(array) == 2;
|
||||
Random random = new Random();
|
||||
|
||||
/* random size */
|
||||
int size = random.nextInt(100) + 1;
|
||||
int[] array = new int[size];
|
||||
|
||||
/* init array with random numbers */
|
||||
for (int i = 0; i < size; i++) {
|
||||
array[i] = random.nextInt() % 100;
|
||||
}
|
||||
|
||||
assert Arrays.stream(array).min().getAsInt() == findMin(array);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user