test: cleanup ReverseNumberTest (#5381)

This commit is contained in:
Alex Klymenko 2024-08-25 08:43:39 +02:00 committed by GitHub
parent 38688440ef
commit a8d3b6ad2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,27 +3,21 @@ package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.HashMap; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
public class ReverseNumberTest { public class ReverseNumberTest {
@Test @ParameterizedTest
public void testReverseNumber() { @CsvSource({"0, 0", "1, 1", "10, 1", "123, 321", "7890, 987"})
HashMap<Integer, Integer> testCases = new HashMap<>(); public void testReverseNumber(int input, int expected) {
testCases.put(0, 0); assertEquals(expected, ReverseNumber.reverseNumber(input));
testCases.put(1, 1);
testCases.put(10, 1);
testCases.put(123, 321);
testCases.put(7890, 987);
for (final var tc : testCases.entrySet()) {
assertEquals(ReverseNumber.reverseNumber(tc.getKey()), tc.getValue());
}
} }
@Test @ParameterizedTest
public void testReverseNumberThrowsExceptionForNegativeInput() { @ValueSource(ints = {-1, -123, -7890})
assertThrows(IllegalArgumentException.class, () -> ReverseNumber.reverseNumber(-1)); public void testReverseNumberThrowsExceptionForNegativeInput(int input) {
assertThrows(IllegalArgumentException.class, () -> ReverseNumber.reverseNumber(input));
} }
} }