/** * The test class NumeralTest. * * @author (your name) * @version (a version number or a date) */ public class NumeralTest extends junit.framework.TestCase { /** * Default constructor for test class NumeralTest */ public NumeralTest() { } /** * Sets up the test fixture. * * Called before every test case method. */ protected void setUp() { } /** * Tears down the test fixture. * * Called after every test case method. */ protected void tearDown() { } public void testNumeralsWithOrdinaryBases() { for ( short base : new short[] {2,7,8,10,16}) { for (int i=0; i < 100000; ++i) { assertEquals(i, Numeral.stoi(Numeral.itos(i,base), base) ); if (base<=16) { assertEquals(Integer.toString(i,base), Numeral.itos(i, base).toLowerCase() ); } } } } public void testNumeralsWithWeirdBases() { // Note: largest allowed digit is 41, // since otherwise reach 'a' (0,1,2,..,9; A,B,..,F,..,Y,Z,!,?,...,a <-- 32nd char after 'A') // and that's ambiguous upper/lower case. for ( short base : new short[] {17,27,Numeral.MAX_DIGIT}) { for (int i=0; i < 100000; ++i) { assertEquals(i, Numeral.stoi(Numeral.itos(i,base), base) ); if (base<=16) { assertEquals(Integer.toString(i,base), Numeral.itos(i, base).toLowerCase() ); } } } } public void testNumeralsWithBaseTooBig() { // Note: largest allowed digit is 41, // since otherwise reach 'a' (0,1,2,..,9; A,B,..,F,..,Y,Z,!,?,...,a <-- 32nd char after 'A') // and that's ambiguous upper/lower case. for ( short base : new short[] {Numeral.MAX_DIGIT+1}) { for (int i=0; i < 100000; ++i) { assertEquals(i, Numeral.stoi(Numeral.itos(i,base), base) ); if (base<=16) { assertEquals(Integer.toString(i,base), Numeral.itos(i, base).toLowerCase() ); } } } } }