OrderedCode { @VisibleForTesting int getSignedEncodingLength(long n) { return BITS_TO_LENGTH[log2Floor(n < 0 ? ~n : n) + 1]; } 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 testGetSignedEncodingLength() { OrderedCode orderedCode = new OrderedCode(); assertEquals(10, orderedCode.getSignedEncodingLength(Long.MIN_VALUE)); assertEquals(10, orderedCode.getSignedEncodingLength(~(1L << 62))); assertEquals(9, orderedCode.getSignedEncodingLength(~(1L << 62) + 1)); assertEquals(3, orderedCode.getSignedEncodingLength(-8193)); assertEquals(2, orderedCode.getSignedEncodingLength(-8192)); assertEquals(2, orderedCode.getSignedEncodingLength(-65)); assertEquals(1, orderedCode.getSignedEncodingLength(-64)); assertEquals(1, orderedCode.getSignedEncodingLength(-2)); assertEquals(1, orderedCode.getSignedEncodingLength(-1)); assertEquals(1, orderedCode.getSignedEncodingLength(0)); assertEquals(1, orderedCode.getSignedEncodingLength(1)); assertEquals(1, orderedCode.getSignedEncodingLength(63)); assertEquals(2, orderedCode.getSignedEncodingLength(64)); assertEquals(2, orderedCode.getSignedEncodingLength(8191)); assertEquals(3, orderedCode.getSignedEncodingLength(8192)); assertEquals(9, orderedCode.getSignedEncodingLength(1L << 62) - 1); assertEquals(10, orderedCode.getSignedEncodingLength(1L << 62)); assertEquals(10, orderedCode.getSignedEncodingLength(Long.MAX_VALUE)); }