refactor: OctalToDecimal (#5344)

This commit is contained in:
Alex Klymenko
2024-08-18 20:58:57 +02:00
committed by GitHub
parent 2905ccbb20
commit a9f5b82708
2 changed files with 40 additions and 38 deletions

View File

@ -1,14 +1,21 @@
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 OctalToDecimalTest {
@Test
public void testOctalToDecimal() {
assertEquals(1465, OctalToDecimal.convertOctalToDecimal("2671"));
assertEquals(189, OctalToDecimal.convertOctalToDecimal("275"));
@ParameterizedTest
@CsvSource({"10, 8", "7, 7", "77, 63", "123, 83", "0, 0", "777, 511", "2671, 1465", "275, 189"})
void testConvertOctalToDecimal(String inputOctal, int expectedDecimal) {
Assertions.assertEquals(expectedDecimal, OctalToDecimal.convertOctalToDecimal(inputOctal));
}
@ParameterizedTest
@CsvSource({"'', Input cannot be null or empty", "'8', Incorrect input: Expecting an octal number (digits 0-7)", "'19', Incorrect input: Expecting an octal number (digits 0-7)"})
void testIncorrectInput(String inputOctal, String expectedMessage) {
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> OctalToDecimal.convertOctalToDecimal(inputOctal));
Assertions.assertEquals(expectedMessage, exception.getMessage());
}
}