/* * (c) Copyright 2009 Hewlett-Packard Development Company, LP * All rights reserved. * [See end of file] */ package structure.radix; import org.junit.Test; import org.openjena.atlas.junit.BaseTest ; public class TestRadix extends BaseTest { // Test order : This sequence of keys triggers every case of insert. static byte[] key1 = { 2 , 4 , 6 , 8 } ; static byte[] key2 = { 2 , 4 , 6 , 10 } ; // Insert - shorter key static byte[] key3 = { 2 } ; // Insert - existing leaf static byte[] key4 = { 2 , 4 , 6, 8 , 10 } ; // Insert - partial prefix match. static byte[] key5 = { 2 , 4 , 3 , 1 } ; static byte[] key6 = { 0 , 1 , 2 , 3 , 4 } ; @Test public void radix_01() { RadixTree t = new RadixTree() ; test(0, t) ; } @Test public void radix_02() { RadixTree t = new RadixTree() ; t.insert(new byte[]{1,2,3,4}) ; test(1, t) ; } @Test public void radix_03() { RadixTree t = new RadixTree() ; t.insert(new byte[]{1,2,3,4}) ; t.insert(new byte[]{0,1,2,3}) ; test(2, t) ; } @Test public void radix_04() { RadixTree t = new RadixTree() ; t.insert(new byte[]{0,1,2,3}) ; t.insert(new byte[]{1,2,3,4}) ; test(2, t) ; } private static void insert(RadixTree t, byte[] key) { t.insert(key) ; t.check(); RadixNode n = t.find(key) ; assertNotNull(n) ; assertEquals(key.length, n.lenFinish) ; } private static void test(int size, RadixTree t) { t.check(); assertEquals(size, t.size()) ; } } /* * (c) Copyright 2009 Hewlett-Packard Development Company, LP * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */