mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-18 17:31:13 +08:00
test using rand numbers
This commit is contained in:
@ -1,7 +1,24 @@
|
||||
package Maths;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MinValue {
|
||||
|
||||
/**
|
||||
* Driver Code
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Random rand = new Random();
|
||||
|
||||
/* test 100 times using rand numbers */
|
||||
for (int i = 1; i <= 100; ++i) {
|
||||
/* generate number from -50 to 49 */
|
||||
int a = rand.nextInt(100) - 50;
|
||||
int b = rand.nextInt(100) - 50;
|
||||
assert min(a, b) == Math.min(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smaller of two {@code int} values. That is,
|
||||
* the result the argument closer to the value of
|
||||
@ -15,15 +32,4 @@ public class MinValue {
|
||||
public static int min(int a, int b) {
|
||||
return a <= b ? a : b;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
assert min(-3,3) == -3;
|
||||
assert min(-6,-20) == -20;
|
||||
assert min(100,32) == 32;
|
||||
assert min(13,13) == 13;
|
||||
|
||||
int a = 3;
|
||||
int b = 4;
|
||||
System.out.format("min:%d between %d and %d", min(a, b), a, b);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user