refactor: DecimalToAnyBase (#5343)

This commit is contained in:
Alex Klymenko
2024-08-18 20:45:30 +02:00
committed by GitHub
parent 404ad7272f
commit 2905ccbb20
2 changed files with 69 additions and 46 deletions

View File

@ -0,0 +1,23 @@
package com.thealgorithms.conversions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
public class DecimalToAnyBaseTest {
@ParameterizedTest
@CsvSource({"0, 2, 0", "0, 16, 0", "0, 36, 0", "10, 2, 1010", "255, 16, FF", "100, 8, 144", "42, 2, 101010", "1234, 16, 4D2", "1234, 36, YA"})
void testConvertToAnyBase(int decimal, int base, String expected) {
assertEquals(expected, DecimalToAnyBase.convertToAnyBase(decimal, base));
}
@Test
void testBaseOutOfRange() {
assertThrows(IllegalArgumentException.class, () -> DecimalToAnyBase.convertToAnyBase(10, 1));
assertThrows(IllegalArgumentException.class, () -> DecimalToAnyBase.convertToAnyBase(10, 37));
}
}