From 17fe4298b699ff4cb6282a5e1e0edcd7541f6735 Mon Sep 17 00:00:00 2001 From: Lukas <142339568+lukasb1b@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:27:23 +0200 Subject: [PATCH] Add MaxValueTest and remove main from MaxValue (#4756) * Create MaxValueTest.java * Update MaxValue.java --- .../com/thealgorithms/maths/MaxValue.java | 20 ++----------------- .../com/thealgorithms/maths/MaxValueTest.java | 14 +++++++++++++ 2 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 src/test/java/com/thealgorithms/maths/MaxValueTest.java diff --git a/src/main/java/com/thealgorithms/maths/MaxValue.java b/src/main/java/com/thealgorithms/maths/MaxValue.java index a4603533..d8829106 100644 --- a/src/main/java/com/thealgorithms/maths/MaxValue.java +++ b/src/main/java/com/thealgorithms/maths/MaxValue.java @@ -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 diff --git a/src/test/java/com/thealgorithms/maths/MaxValueTest.java b/src/test/java/com/thealgorithms/maths/MaxValueTest.java new file mode 100644 index 00000000..3c0fe844 --- /dev/null +++ b/src/test/java/com/thealgorithms/maths/MaxValueTest.java @@ -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)); + } +}