Add MaxValueTest and remove main from MaxValue (#4756)
* Create MaxValueTest.java * Update MaxValue.java
This commit is contained in:
parent
ced9678699
commit
17fe4298b6
@ -1,24 +1,8 @@
|
|||||||
package com.thealgorithms.maths;
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
import java.util.Random;
|
public final class MaxValue {
|
||||||
|
private MaxValue() {
|
||||||
public class MaxValue {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 max(a, b) == Math.max(a, b);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the greater of two {@code int} values. That is, the result is the
|
* Returns the greater of two {@code int} values. That is, the result is the
|
||||||
* argument closer to the value of {@link Integer#MAX_VALUE}. If the
|
* argument closer to the value of {@link Integer#MAX_VALUE}. If the
|
||||||
|
14
src/test/java/com/thealgorithms/maths/MaxValueTest.java
Normal file
14
src/test/java/com/thealgorithms/maths/MaxValueTest.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class MaxValueTest {
|
||||||
|
@Test
|
||||||
|
public void maxTest() {
|
||||||
|
assertEquals(-1, MaxValue.max(-1, -3));
|
||||||
|
assertEquals(3, MaxValue.max(3, 2));
|
||||||
|
assertEquals(5, MaxValue.max(5, 5));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user