mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Enhance docs, remove main. add more tests in `HexaDecimal… (#5923)
This commit is contained in:
@@ -1,14 +1,37 @@
|
||||
package com.thealgorithms.conversions;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
public class HexaDecimalToDecimalTest {
|
||||
|
||||
@Test
|
||||
public void testhexaDecimalToDecimal() {
|
||||
assertEquals(161, HexaDecimalToDecimal.getHexaToDec("A1"));
|
||||
assertEquals(428, HexaDecimalToDecimal.getHexaToDec("1ac"));
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"A1, 161", // Simple case with two characters
|
||||
"1AC, 428", // Mixed-case input
|
||||
"0, 0", // Single zero
|
||||
"F, 15", // Single digit
|
||||
"10, 16", // Power of 16
|
||||
"FFFF, 65535", // Max 4-character hex
|
||||
"7FFFFFFF, 2147483647" // Max positive int value
|
||||
})
|
||||
public void
|
||||
testValidHexaToDecimal(String hexInput, int expectedDecimal) {
|
||||
assertEquals(expectedDecimal, HexaDecimalToDecimal.getHexaToDec(hexInput));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"G", // Invalid character
|
||||
"1Z", // Mixed invalid input
|
||||
"123G", // Valid prefix with invalid character
|
||||
"#$%" // Non-hexadecimal symbols
|
||||
})
|
||||
public void
|
||||
testInvalidHexaToDecimal(String invalidHex) {
|
||||
assertThrows(IllegalArgumentException.class, () -> HexaDecimalToDecimal.getHexaToDec(invalidHex));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user