Skip to content

test: cleanup ReverseNumberTest #5381

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
Aug 25, 2024
Merged
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
28 changes: 11 additions & 17 deletions src/test/java/com/thealgorithms/maths/ReverseNumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.HashMap;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

public class ReverseNumberTest {

@Test
public void testReverseNumber() {
HashMap<Integer, Integer> testCases = new HashMap<>();
testCases.put(0, 0);
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());
}
@ParameterizedTest
@CsvSource({"0, 0", "1, 1", "10, 1", "123, 321", "7890, 987"})
public void testReverseNumber(int input, int expected) {
assertEquals(expected, ReverseNumber.reverseNumber(input));
}

@Test
public void testReverseNumberThrowsExceptionForNegativeInput() {
assertThrows(IllegalArgumentException.class, () -> ReverseNumber.reverseNumber(-1));
@ParameterizedTest
@ValueSource(ints = {-1, -123, -7890})
public void testReverseNumberThrowsExceptionForNegativeInput(int input) {
assertThrows(IllegalArgumentException.class, () -> ReverseNumber.reverseNumber(input));
}
}