@Test
public void toRange() {

    final Tuple a = Tuple.from("a");
    final Tuple b = Tuple.from("b");
    List<Pair<TupleRange, Range>> testCases = Arrays.asList(
            Pair.of(TupleRange.allOf(null), new Range(new byte[0], new byte[]{(byte)0xff})),
            Pair.of(TupleRange.allOf(PREFIX_TUPLE), Range.startsWith(PREFIX_BYTES)),
            Pair.of(new TupleRange(a, b, EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_EXCLUSIVE),
                    new Range(a.pack(), b.pack())),
            Pair.of(new TupleRange(a, b, EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_INCLUSIVE),
                    new Range(a.pack(), ByteArrayUtil.strinc(b.pack()))),
            Pair.of(new TupleRange(a, b, EndpointType.RANGE_EXCLUSIVE, EndpointType.RANGE_EXCLUSIVE),
                    new Range(ByteArrayUtil.strinc(a.pack()), b.pack())),
            Pair.of(new TupleRange(a, b, EndpointType.RANGE_EXCLUSIVE, EndpointType.RANGE_INCLUSIVE),
                    new Range(ByteArrayUtil.strinc(a.pack()), ByteArrayUtil.strinc(b.pack()))),
            Pair.of(new TupleRange(null, b, EndpointType.TREE_START, EndpointType.RANGE_EXCLUSIVE),
                    new Range(new byte[0], b.pack())),
            Pair.of(new TupleRange(a, null, EndpointType.RANGE_INCLUSIVE, EndpointType.TREE_END),
                    new Range(a.pack(), new byte[]{(byte)0xff})),
            Pair.of(new TupleRange(a, b, EndpointType.CONTINUATION, EndpointType.RANGE_EXCLUSIVE),
                    new Range(ByteArrayUtil.join(a.pack(), new byte[]{0x00}), b.pack())),
            Pair.of(new TupleRange(a, b, EndpointType.RANGE_INCLUSIVE, EndpointType.CONTINUATION),
                    new Range(a.pack(), b.pack())),
            Pair.of(TupleRange.prefixedBy("a"),
                    new Range(new byte[]{0x02, (byte)'a'}, new byte[]{0x02, (byte)'b'})),
            Pair.of(new TupleRange(Tuple.from("apple"), a, EndpointType.CONTINUATION, EndpointType.PREFIX_STRING),
                    new Range(ByteArrayUtil.join(Tuple.from("apple").pack(), new byte[]{0x00}), new byte[]{0x02, (byte)'b'})),
            Pair.of(new TupleRange(a, Tuple.from("apple"), EndpointType.PREFIX_STRING, EndpointType.CONTINUATION),
                    new Range(new byte[]{0x02, (byte)'a'}, Tuple.from("apple").pack()))
    );
    testCases.forEach(pair -> {
        assertEquals(pair.getRight(), pair.getLeft().toRange());
        TupleRange expectedRange = pair.getLeft().prepend(PREFIX_TUPLE);
        assertEquals(expectedRange.toRange(), pair.getLeft().toRange(PREFIX_SUBSPACE));
    });
}