|
| 1 | +package com.algorithms.conversions; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | + |
| 7 | +class AnyBaseToDecimalTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + void testAnyBaseToDecimal() { |
| 11 | + AnyBaseToDecimal anyBaseToDecimal = new AnyBaseToDecimal(); |
| 12 | + assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("2", 2)); |
| 13 | + assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("3", 2)); |
| 14 | + assertEquals("3", anyBaseToDecimal.convertToDecimal("11", 2)); |
| 15 | + assertEquals("4", anyBaseToDecimal.convertToDecimal("100", 2)); |
| 16 | + assertEquals("5", anyBaseToDecimal.convertToDecimal("101", 2)); |
| 17 | + assertEquals("10", anyBaseToDecimal.convertToDecimal("1010", 2)); |
| 18 | + assertEquals("1024", anyBaseToDecimal.convertToDecimal("10000000000", 2)); |
| 19 | + |
| 20 | + assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("8", 8)); |
| 21 | + assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("9", 8)); |
| 22 | + assertEquals("7", anyBaseToDecimal.convertToDecimal("7", 8)); |
| 23 | + assertEquals("8", anyBaseToDecimal.convertToDecimal("10", 8)); |
| 24 | + assertEquals("9", anyBaseToDecimal.convertToDecimal("11", 8)); |
| 25 | + assertEquals("10", anyBaseToDecimal.convertToDecimal("12", 8)); |
| 26 | + assertEquals("1024", anyBaseToDecimal.convertToDecimal("2000", 8)); |
| 27 | + |
| 28 | + assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("A", 10)); |
| 29 | + assertEquals("10", anyBaseToDecimal.convertToDecimal("10", 10)); |
| 30 | + assertEquals("1024", anyBaseToDecimal.convertToDecimal("1024", 10)); |
| 31 | + |
| 32 | + assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("G", 16)); |
| 33 | + assertEquals("16", anyBaseToDecimal.convertToDecimal("10", 16)); |
| 34 | + assertEquals("17", anyBaseToDecimal.convertToDecimal("11", 16)); |
| 35 | + assertEquals("100", anyBaseToDecimal.convertToDecimal("64", 16)); |
| 36 | + assertEquals("225", anyBaseToDecimal.convertToDecimal("E1", 16)); |
| 37 | + assertEquals("1024", anyBaseToDecimal.convertToDecimal("400", 16)); |
| 38 | + } |
| 39 | +} |
0 commit comments