-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathHexaDecimalToDecimalTest.java
37 lines (32 loc) · 1.19 KB
/
HexaDecimalToDecimalTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
public class HexaDecimalToDecimalTest {
@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));
}
}