Skip to content

Add MaxValueTest and remove main from MaxValue #4756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions src/main/java/com/thealgorithms/maths/MaxValue.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
package com.thealgorithms.maths;

import java.util.Random;

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);
}
public final class MaxValue {
private MaxValue() {
}

/**
* 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
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/thealgorithms/maths/MaxValueTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}