public void testToString() { for (long value : TEST_LONGS) { UnsignedLong unsignedValue = UnsignedLong.fromLongBits(value); assertEquals(unsignedValue.bigIntegerValue().toString(), unsignedValue.toString()); } }
public void testAsUnsignedBigIntegerValue() { for (long value : TEST_LONGS) { BigInteger expected = (value >= 0) ? BigInteger.valueOf(value) : BigInteger.valueOf(value).add(BigInteger.ZERO.setBit(64)); assertEquals( UnsignedLongs.toString(value), expected, UnsignedLong.fromLongBits(value).bigIntegerValue()); } }
public void testIntValue() { for (long a : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); int intValue = aUnsigned.bigIntegerValue().intValue(); assertEquals(intValue, aUnsigned.intValue()); } }
public void testToStringRadixQuick() { int[] radices = {2, 3, 5, 7, 10, 12, 16, 21, 31, 36}; for (int radix : radices) { for (long l : TEST_LONGS) { UnsignedLong value = UnsignedLong.fromLongBits(l); assertEquals(value.bigIntegerValue().toString(radix), value.toString(radix)); } } }
public void testDoubleValue() { for (long value : TEST_LONGS) { UnsignedLong unsignedValue = UnsignedLong.fromLongBits(value); assertEquals(unsignedValue.bigIntegerValue().doubleValue(), unsignedValue.doubleValue()); } }
public void testAsUnsignedAndLongValueAreInverses() { for (long value : TEST_LONGS) { assertEquals( UnsignedLongs.toString(value), value, UnsignedLong.fromLongBits(value).longValue()); } }
@GwtIncompatible // too slow public void testToStringRadix() { for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { for (long l : TEST_LONGS) { UnsignedLong value = UnsignedLong.fromLongBits(l); assertEquals(value.bigIntegerValue().toString(radix), value.toString(radix)); } } }
public void testValueOfBigInteger() { BigInteger min = BigInteger.ZERO; BigInteger max = UnsignedLong.MAX_VALUE.bigIntegerValue(); for (BigInteger big : TEST_BIG_INTEGERS) { boolean expectSuccess = big.compareTo(min) >= 0 && big.compareTo(max) <= 0; try { assertEquals(big, UnsignedLong.valueOf(big).bigIntegerValue()); assertTrue(expectSuccess); } catch (IllegalArgumentException e) { assertFalse(expectSuccess); } } }
public void testDividedBy() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { if (b != 0) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned.bigIntegerValue().divide(bUnsigned.bigIntegerValue()).longValue(); UnsignedLong unsignedDiv = aUnsigned.dividedBy(bUnsigned); assertEquals(expected, unsignedDiv.longValue()); } } } }
public void testPlus() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned.bigIntegerValue().add(bUnsigned.bigIntegerValue()).longValue(); UnsignedLong unsignedSum = aUnsigned.plus(bUnsigned); assertEquals(expected, unsignedSum.longValue()); } } }
public void testMinus() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned.bigIntegerValue().subtract(bUnsigned.bigIntegerValue()).longValue(); UnsignedLong unsignedSub = aUnsigned.minus(bUnsigned); assertEquals(expected, unsignedSub.longValue()); } } }
public void testTimes() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned.bigIntegerValue().multiply(bUnsigned.bigIntegerValue()).longValue(); UnsignedLong unsignedMul = aUnsigned.times(bUnsigned); assertEquals(expected, unsignedMul.longValue()); } } }
public void testValueOfLong() { for (long value : TEST_LONGS) { boolean expectSuccess = value >= 0; try { assertEquals(value, UnsignedLong.valueOf(value).longValue()); assertTrue(expectSuccess); } catch (IllegalArgumentException e) { assertFalse(expectSuccess); } } }
public void testCompare() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); assertEquals( aUnsigned.bigIntegerValue().compareTo(bUnsigned.bigIntegerValue()), aUnsigned.compareTo(bUnsigned)); } } }
public void testMod() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { if (b != 0) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned.bigIntegerValue().remainder(bUnsigned.bigIntegerValue()).longValue(); UnsignedLong unsignedRem = aUnsigned.mod(bUnsigned); assertEquals(expected, unsignedRem.longValue()); } } } }
public void testFloatValue() { for (long value : TEST_LONGS) { UnsignedLong unsignedValue = UnsignedLong.fromLongBits(value); assertEquals(unsignedValue.bigIntegerValue().floatValue(), unsignedValue.floatValue()); } }
public void testToString() { for (long value : TEST_LONGS) { UnsignedLong unsignedValue = UnsignedLong.fromLongBits(value); assertEquals(unsignedValue.bigIntegerValue().toString(), unsignedValue.toString()); } }
@GwtIncompatible // too slow public void testToStringRadix() { for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { for (long l : TEST_LONGS) { UnsignedLong value = UnsignedLong.fromLongBits(l); assertEquals(value.bigIntegerValue().toString(radix), value.toString(radix)); } } }
public void testAsUnsignedAndLongValueAreInverses() { for (long value : TEST_LONGS) { assertEquals( UnsignedLongs.toString(value), value, UnsignedLong.fromLongBits(value).longValue()); } }
public void testCompare() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); assertEquals(aUnsigned.bigIntegerValue().compareTo(bUnsigned.bigIntegerValue()), aUnsigned.compareTo(bUnsigned)); } } }