mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
refactor: OctalToHexadecimal
(#5345)
This commit is contained in:
@ -1,14 +1,23 @@
|
||||
package com.thealgorithms.conversions;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
public class OctalToHexadecimalTest {
|
||||
|
||||
@Test
|
||||
public void testOctalToHexadecimal() {
|
||||
assertEquals("1EA", OctalToHexadecimal.decimalToHex(OctalToHexadecimal.octToDec("752")));
|
||||
assertEquals("15E", OctalToHexadecimal.decimalToHex(OctalToHexadecimal.octToDec("536")));
|
||||
@ParameterizedTest
|
||||
@CsvSource({"0, 0", "7, 7", "10, 8", "17, F", "20, 10", "777, 1FF", "1234, 29C", "752, 1EA", "536, 15E"})
|
||||
void testCorrectInputs(String inputOctal, String expectedHex) {
|
||||
int decimal = OctalToHexadecimal.octalToDecimal(inputOctal);
|
||||
String hex = OctalToHexadecimal.decimalToHexadecimal(decimal);
|
||||
Assertions.assertEquals(expectedHex, hex);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"'', Input cannot be null or empty", "'8', Incorrect octal digit: 8", "'19', Incorrect octal digit: 9"})
|
||||
void testIncorrectInputs(String inputOctal, String expectedMessage) {
|
||||
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> OctalToHexadecimal.octalToDecimal(inputOctal));
|
||||
Assertions.assertEquals(expectedMessage, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user