Package

Source Code of HashStoreTest

import java.io.File;
import junit.framework.TestCase;
import dijjer.io.store.HashStore;
import dijjer.util.VeryLongInteger;
import dijjer.util.VeryLongIntegerKey;

/*
* Created on Nov 29, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
/**
* @author ian
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class HashStoreTest extends TestCase {
  public static final int HS_SIZE = 3;
  public static final int HS_INSERTS = 5;
  File _index;
  HashStore _hs;
 
  protected void setUp() throws Exception {
    _index = File.createTempFile("dijjer-hstest", ".dat");
    _index.deleteOnExit();
   
    _hs = new HashStore(_index, HS_SIZE);
  }
 
  protected void tearDown() throws Exception {
    _hs.close();
  }
 
  public void testHashStore() throws Exception {
    for (int x=0; x<HS_INSERTS; x++) {
      VeryLongIntegerKey key = new VeryLongIntegerKey(x,x);
      VeryLongInteger hash = new VeryLongInteger(x*x, x*x);
      _hs.put(key, hash);
    }
   
    _hs.close();
   
    assertEquals("File length doesn't correspond to HashStore size", _index.length(), HS_SIZE*40);
   
    _hs = new HashStore(_index, HS_SIZE);
   
    VeryLongInteger v = _hs.getHash(new VeryLongIntegerKey(2,2));
    assertEquals("Retrieved VLI was not as expected", v, new VeryLongInteger(4,4));

    // This shouldn't be in there any more as it should have been displayed
    v = _hs.getHash(new VeryLongIntegerKey(0,0));
    assertNull("Object should have been deleted, but wasn't", v);
   
    _hs.put(new VeryLongIntegerKey(20, 20), new VeryLongInteger(400, 400));
   
    v = _hs.getHash(new VeryLongIntegerKey(3,3));
    assertNull("Object should have been deleted, but wasn't", v);
   
    v = _hs.getHash(new VeryLongIntegerKey(2,2));
   
    assertNotNull("Object should have been retained, but wasn't", v);
    assertEquals("Retrieved VLI was not as expected", v, new VeryLongInteger(4,4));
   
    _hs.close();
   
    _hs = new HashStore(_index, HS_SIZE);
   
    v = _hs.getHash(new VeryLongIntegerKey(4,4));
    assertNotNull("Failed to retrieve hash", v);
    assertEquals("Retrieved VLI is not as expected", v, new VeryLongInteger(16, 16));
   
    v = _hs.getHash(new VeryLongIntegerKey(3,3));
    assertNull(v);
   
    _hs.delete(new VeryLongIntegerKey(4,4));
    assertNull(_hs.getHash(new VeryLongIntegerKey(4,4)));
   
    _hs.close();
   
    _hs = new HashStore(_index, HS_SIZE);
   
    assertNull(_hs.getHash(new VeryLongIntegerKey(4,4)));
   
    v = _hs.getHash(new VeryLongIntegerKey(2,2));
   
    assertNotNull("Object should have been retained, but wasn't", v);
    assertEquals("Retrieved VLI was not as expected", v, new VeryLongInteger(4,4));
  }
}
TOP

Related Classes of HashStoreTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.