OrderedCode { @VisibleForTesting int log2Floor(long n) { checkArgument(n >= 0); return n == 0 ? -1 : LongMath.log2(n, RoundingMode.FLOOR); } OrderedCode();  OrderedCode(byte[] encodedByteArray); void writeBytes(byte[] value); void writeBytesDecreasing(byte[] value); void writeNumIncreasing(long value); void writeNumIncreasing(UnsignedInteger unsignedInt); void writeNumDecreasing(long value); void writeNumDecreasing(UnsignedInteger unsignedInt); void writeSignedNumIncreasing(long val); void writeSignedNumDecreasing(long val); void writeInfinity(); void writeInfinityDecreasing(); void writeTrailingBytes(byte[] value); byte[] readBytes(); byte[] readBytesDecreasing(); long readNumIncreasing(); long readNumDecreasing(); long readSignedNumIncreasing(); long readSignedNumDecreasing(); boolean readInfinity(); boolean readInfinityDecreasing(); byte[] readTrailingBytes(); byte[] getEncodedBytes(); boolean hasRemainingEncodedBytes();  }
@Test public void testLog2Floor_Positive() { OrderedCode orderedCode = new OrderedCode(); assertEquals(0, orderedCode.log2Floor(1)); assertEquals(1, orderedCode.log2Floor(2)); assertEquals(1, orderedCode.log2Floor(3)); assertEquals(2, orderedCode.log2Floor(4)); assertEquals(5, orderedCode.log2Floor(63)); assertEquals(6, orderedCode.log2Floor(64)); assertEquals(62, orderedCode.log2Floor(Long.MAX_VALUE)); }
@Test public void testLog2Floor_zero() { OrderedCode orderedCode = new OrderedCode(); assertEquals(-1, orderedCode.log2Floor(0)); }
@Test public void testLog2Floor_negative() { OrderedCode orderedCode = new OrderedCode(); try { orderedCode.log2Floor(-1); fail("Expected an IllegalArgumentException."); } catch (IllegalArgumentException expected) { } }