Skip to content

Commit 17fe429

Browse files
authored
Add MaxValueTest and remove main from MaxValue (#4756)
* Create MaxValueTest.java * Update MaxValue.java
1 parent ced9678 commit 17fe429

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/main/java/com/thealgorithms/maths/MaxValue.java

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
package com.thealgorithms.maths;
22

3-
import java.util.Random;
4-
5-
public class MaxValue {
6-
7-
/**
8-
* Driver Code
9-
*/
10-
public static void main(String[] args) {
11-
Random rand = new Random();
12-
13-
/* test 100 times using rand numbers */
14-
for (int i = 1; i <= 100; ++i) {
15-
/* generate number from -50 to 49 */
16-
int a = rand.nextInt(100) - 50;
17-
int b = rand.nextInt(100) - 50;
18-
assert max(a, b) == Math.max(a, b);
19-
}
3+
public final class MaxValue {
4+
private MaxValue() {
205
}
21-
226
/**
237
* Returns the greater of two {@code int} values. That is, the result is the
248
* argument closer to the value of {@link Integer#MAX_VALUE}. If the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.thealgorithms.maths;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class MaxValueTest {
8+
@Test
9+
public void maxTest() {
10+
assertEquals(-1, MaxValue.max(-1, -3));
11+
assertEquals(3, MaxValue.max(3, 2));
12+
assertEquals(5, MaxValue.max(5, 5));
13+
}
14+
}

0 commit comments

Comments
 (0)