refactor: OctalToHexadecimal (#5345)

This commit is contained in:
Alex Klymenko
2024-08-18 21:03:28 +02:00
committed by GitHub
parent a9f5b82708
commit 33fd79ad55
2 changed files with 52 additions and 47 deletions

View File

@ -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());
}
}