/* * (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP * All rights reserved. * [See end of file] */ package structure.exthash; import static structure.exthash.ExtHashMemTestBase.check; import static structure.exthash.ExtHashMemTestBase.create; import static structure.exthash.ExtHashMemTestBase.delete; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import structure.exthash.ExtHashMem; import org.openjena.atlas.junit.BaseTest ; public class TestExtHashMem extends BaseTest { @BeforeClass static public void setup() { ExtHashMem.NullOut = true ; ExtHashMem.Checking = true ; ExtHashMem.DefaultBucketSize = 4 ; } @AfterClass static public void teardown() { } @Test public void create1() { ExtHashMem eHash = new ExtHashMem() ; check(eHash) ; } // @Test public void create2() // { ExtHash eHash = build() ; assertNotNull(eHash) ; } @Test public void insert1() { ExtHashMem eHash = create(1) ; check(eHash, 1) ; assertEquals(eHash.get(1), "X1") ; assertEquals(1, eHash.size()) ; } @Test public void insert2() { ExtHashMem eHash = create(1,2) ; check(eHash, 1, 2) ; assertEquals(eHash.get(1), "X1") ; assertEquals(eHash.get(2), "X2") ; assertEquals(2, eHash.size()) ; } @Test public void insert3() { ExtHashMem eHash = create(1,2,3,4,5,6,7,8) ; check(eHash, 1, 2, 3, 4, 5, 6, 7, 8) ; } // Nasty cases @Test public void insert4() { ExtHashMem eHash = create(0,2,4,8,16) ; assertEquals(5, eHash.size()) ; } @Test public void delete1() { ExtHashMem eHash = createAndCheck(1) ; assertEquals(1, eHash.size()) ; delete(eHash, 1) ; assertFalse(eHash.contains(1)) ; assertEquals(0, eHash.size()) ; } @Test public void delete2() { ExtHashMem eHash = createAndCheck(1, 2, 3, 4, 5, 6, 7, 8) ; delete(eHash, 1, 2, 3, 4, 5, 6, 7, 8) ; check(eHash) ; } @Test public void delete3() { ExtHashMem eHash = createAndCheck(1, 2, 3, 4, 5, 6, 7, 8) ; delete(eHash, 8, 7, 6, 5, 4, 3, 2, 1) ; check(eHash) ; } static private ExtHashMem createAndCheck(int... keys) { ExtHashMem eHash = create(keys) ; check(eHash, keys); assertEquals(keys.length, eHash.size()) ; return eHash ; } } /* * (c) Copyright 2008, 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. */