
/*
 * Copyright (C) 2014 Archie L. Cobbs. All rights reserved.
 *
 * $Id$
 */

package org.jsimpledb.kv;

import org.jsimpledb.TestSupport;
import org.testng.Assert;
import org.testng.annotations.Test;

public class KeyRangeTest extends TestSupport {

    @Test
    public void testFull() {
        final KeyRange kr = new KeyRange(new byte[0], null);
        Assert.assertTrue(kr.isFull());
    }

    @Test
    public void testPrefix1() {
        final KeyRange kr1 = new KeyRange(new byte[] { 0x20 }, new byte[] { 0x20, 0x60 });
        Assert.assertEquals(kr1.prefixedBy(new byte[0]), kr1);
        final KeyRange kr2 = kr1.prefixedBy(new byte[] { 0x30 });
        Assert.assertEquals(kr2.getMin(), new byte[] { 0x30, 0x20 });
        Assert.assertEquals(kr2.getMax(), new byte[] { 0x30, 0x20, 0x60 });
    }

    @Test
    public void testPrefix2() {
        final KeyRange kr1 = new KeyRange(new byte[] { 0x20 }, null);
        Assert.assertEquals(kr1.prefixedBy(new byte[0]), kr1);
        final KeyRange kr2 = kr1.prefixedBy(new byte[] { 0x30 });
        Assert.assertEquals(kr2.getMin(), new byte[] { 0x30, 0x20 });
        Assert.assertEquals(kr2.getMax(), new byte[] { 0x31 });
    }

    @Test
    public void testPrefix3() {
        final KeyRange kr1 = new KeyRange(new byte[0], null);
        Assert.assertEquals(kr1.prefixedBy(new byte[0]), kr1);
        final KeyRange kr2 = kr1.prefixedBy(new byte[] { 0x30 });
        Assert.assertEquals(kr2.getMin(), new byte[] { 0x30 });
        Assert.assertEquals(kr2.getMax(), new byte[] { 0x31 });
    }
}


@@ -1556,12 +1556,369 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testPrefix4() %7B%0A        final KeyRange kr1 = new KeyRange(new byte%5B0%5D, null);%0A        Assert.assertEquals(kr1.prefixedBy(new byte%5B0%5D), kr1);%0A        final KeyRange kr2 = kr1.prefixedBy(new byte%5B%5D %7B (byte)0xff %7D);%0A        Assert.assertEquals(kr2.getMin(), new byte%5B%5D %7B (byte)0xff %7D);%0A        Assert.assertNull(kr2.getMax());%0A    %7D
 %0A%7D%0A%0A

Add another unit test.