mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
refactor: OctalToDecimal
(#5344)
This commit is contained in:
@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user