public void testParseInt() { try { for (long a : UNSIGNED_INTS) { assertEquals((int) a, UnsignedInts.parseUnsignedInt(Long.toString(a))); } } catch (NumberFormatException e) { fail(e.getMessage()); } try { UnsignedInts.parseUnsignedInt(Long.toString(1L << 32)); fail("Expected NumberFormatException"); } catch (NumberFormatException expected) { } }
public void testParseIntWithRadix() { for (long a : UNSIGNED_INTS) { for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { assertEquals((int) a, UnsignedInts.parseUnsignedInt(Long.toString(a, radix), radix)); } } }
public void testParseIntFail() { try { int unused = UnsignedInts.parseUnsignedInt(Long.toString(1L << 32)); fail("Expected NumberFormatException"); } catch (NumberFormatException expected) { } }
public void testParseIntWithRadixLimits() { // loops through all legal radix values. for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { // tests can successfully parse a number string with this radix. String maxAsString = Long.toString((1L << 32) - 1, radix); assertEquals(-1, UnsignedInts.parseUnsignedInt(maxAsString, radix)); try { // tests that we get exception whre an overflow would occur. long overflow = 1L << 32; String overflowAsString = Long.toString(overflow, radix); int unused = UnsignedInts.parseUnsignedInt(overflowAsString, radix); fail(); } catch (NumberFormatException expected) { } } }
public void testParseIntThrowsExceptionForInvalidRadix() { // Valid radix values are Character.MIN_RADIX to Character.MAX_RADIX, // inclusive. try { int unused = UnsignedInts.parseUnsignedInt("0", Character.MIN_RADIX - 1); fail(); } catch (NumberFormatException expected) { } try { int unused = UnsignedInts.parseUnsignedInt("0", Character.MAX_RADIX + 1); fail(); } catch (NumberFormatException expected) { } // The radix is used as an array index, so try a negative value. try { int unused = UnsignedInts.parseUnsignedInt("0", -1); fail(); } catch (NumberFormatException expected) { } }
public void testParseInt() { for (long a : UNSIGNED_INTS) { assertEquals((int) a, UnsignedInts.parseUnsignedInt(Long.toString(a))); } }