From c6a22de12f820f3f6f92a60515acce979ff16162 Mon Sep 17 00:00:00 2001 From: Lukas <142339568+lukasb1b@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:17:02 +0200 Subject: [PATCH] Add `MinValueTest` and remove `main` from `MinValue` (#4713) * Update MinValue.java * Create MinValueTest.java * Revert "Create MinValueTest.java" * Create MinValueTest.java * Update MinValueTest.java * Update MinValueTest.java * Update MinValue.java * Update src/test/java/com/thealgorithms/maths/MinValueTest.java Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com> * Update src/test/java/com/thealgorithms/maths/MinValueTest.java Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com> * Update src/main/java/com/thealgorithms/maths/MinValue.java Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com> --------- Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com> --- .../com/thealgorithms/maths/MinValue.java | 20 ++----------------- .../com/thealgorithms/maths/MinValueTest.java | 14 +++++++++++++ 2 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 src/test/java/com/thealgorithms/maths/MinValueTest.java diff --git a/src/main/java/com/thealgorithms/maths/MinValue.java b/src/main/java/com/thealgorithms/maths/MinValue.java index badc6c7c..88e28e88 100644 --- a/src/main/java/com/thealgorithms/maths/MinValue.java +++ b/src/main/java/com/thealgorithms/maths/MinValue.java @@ -1,24 +1,8 @@ package com.thealgorithms.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); - } +public final class MinValue { + private MinValue() { } - /** * Returns the smaller of two {@code int} values. That is, the result the * argument closer to the value of {@link Integer#MIN_VALUE}. If the diff --git a/src/test/java/com/thealgorithms/maths/MinValueTest.java b/src/test/java/com/thealgorithms/maths/MinValueTest.java new file mode 100644 index 00000000..beb0ccb1 --- /dev/null +++ b/src/test/java/com/thealgorithms/maths/MinValueTest.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 MinValueTest { + @Test + public void minTest() { + assertEquals(-1, MinValue.min(-1, 3)); + assertEquals(2, MinValue.min(3, 2)); + assertEquals(5, MinValue.min(5, 5)); + } +}