@Test
  public void testNumericReal() {
    /*
     * assert encoded values match decoded values. encode into target buffer starting at an offset
     * to detect over/underflow conditions.
     */
    for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
      for (int i = 0; i < D_VALS.length; i++) {
        // allocate a buffer 3-bytes larger than necessary to detect over/underflow
        byte[] a = new byte[D_LENGTHS[i] + 3];
        PositionedByteRange buf1 = new SimplePositionedMutableByteRange(a, 1, D_LENGTHS[i] + 1);
        buf1.setPosition(1);

        // verify encode
        assertEquals("Surprising return value.", D_LENGTHS[i],
          OrderedBytes.encodeNumeric(buf1, D_VALS[i], ord));
        assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
          buf1.getPosition());
        assertEquals("Surprising serialized length.", D_LENGTHS[i], buf1.getPosition() - 1);
        assertEquals("Buffer underflow.", 0, a[0]);
        assertEquals("Buffer underflow.", 0, a[1]);
        assertEquals("Buffer overflow.", 0, a[a.length - 1]);

        // verify skip
        buf1.setPosition(1);
        assertEquals("Surprising return value.", D_LENGTHS[i], OrderedBytes.skip(buf1));
        assertEquals("Did not skip enough bytes.", D_LENGTHS[i], buf1.getPosition() - 1);

        // verify decode
        buf1.setPosition(1);
        assertEquals("Deserialization failed.", D_VALS[i], OrderedBytes.decodeNumericAsDouble(buf1),
          MIN_EPSILON);
        assertEquals("Did not consume enough bytes.", D_LENGTHS[i], buf1.getPosition() - 1);
      }
    }

    /*
     * assert natural sort order is preserved by the codec.
     */
    for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
      byte[][] encoded = new byte[D_VALS.length][];
      PositionedByteRange pbr = new SimplePositionedMutableByteRange();
      for (int i = 0; i < D_VALS.length; i++) {
        encoded[i] = new byte[D_LENGTHS[i]];
        OrderedBytes.encodeNumeric(pbr.set(encoded[i]), D_VALS[i], ord);
      }

      Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
      Double[] sortedVals = Arrays.copyOf(D_VALS, D_VALS.length);

      if (ord == Order.ASCENDING) {
        Arrays.sort(sortedVals);
      } else {
        Arrays.sort(sortedVals, Collections.reverseOrder());
      }

      for (int i = 0; i < sortedVals.length; i++) {
        pbr.set(encoded[i]);
        double decoded = OrderedBytes.decodeNumericAsDouble(pbr);
        assertEquals(
          String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
            sortedVals[i], decoded, ord),
          sortedVals[i], decoded, MIN_EPSILON);
      }
    }
  }
Test real encoding. Example input values come from reference wiki page.
hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java