"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "hsqldb/src/org/hsqldb/test/TestHashStructures.java" between
hsqldb-2.6.0.zip and hsqldb-2.6.1.zip

About: HSQLDB (HyperSQL DataBase) is a SQL relational database engine written in Java. It supports nearly full ANSI-92 SQL (BNF format) and full core SQL:2008.

TestHashStructures.java  (hsqldb-2.6.0):TestHashStructures.java  (hsqldb-2.6.1)
skipping to change at line 53 skipping to change at line 53
public class TestHashStructures extends TestCase { public class TestHashStructures extends TestCase {
public TestHashStructures(String s) { public TestHashStructures(String s) {
super(s); super(s);
} }
Random randomgen = new java.util.Random(); Random randomgen = new java.util.Random();
public void testHashMap() throws Exception { public void testHashMap() throws Exception {
boolean failed = false; int passed = 0;
int testSize = 33; int testSize = 33;
org.hsqldb.lib.HashMap hMap = new org.hsqldb.lib.HashMap(); org.hsqldb.lib.HashMap hMap = new org.hsqldb.lib.HashMap();
org.hsqldb.lib.IntKeyHashMap hIntMap = org.hsqldb.lib.IntKeyHashMap hIntMap =
new org.hsqldb.lib.IntKeyHashMap(); new org.hsqldb.lib.IntKeyHashMap();
java.util.HashMap uMap = new java.util.HashMap(); java.util.HashMap uMap = new java.util.HashMap();
try { try {
populateBySerialIntKeys(uMap, hMap, testSize); populateBySerialIntKeys(uMap, hMap, testSize);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
passed++;
// - // -
populateByRandomIntKeys(uMap, hMap, testSize); populateByRandomIntKeys(uMap, hMap, testSize);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
passed++;
// //
depopulateRandomly(uMap, hMap, 20); depopulateRandomly(uMap, hMap, 20);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
// - passed++;
//
populateBySerialIntKeys(uMap, hMap, testSize); populateBySerialIntKeys(uMap, hMap, testSize);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
passed++;
// //
depopulateByIterator(uMap, hMap, 20); depopulateByIterator(uMap, hMap, 20);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
} catch (Exception e) {
failed = true;
}
assertTrue(!failed); passed++;
} catch (Exception e) {}
assertTrue(passed == 5);
} }
public void testIntKeyHashMap() throws Exception { public void testIntKeyHashMap() throws Exception {
boolean failed = false; int passed = 0;
int testSize = 33; int testSize = 33;
org.hsqldb.lib.IntKeyHashMap hIntMap = org.hsqldb.lib.IntKeyHashMap hIntMap =
new org.hsqldb.lib.IntKeyHashMap(); new org.hsqldb.lib.IntKeyHashMap();
java.util.HashMap uMap = new java.util.HashMap(); java.util.HashMap uMap = new java.util.HashMap();
try { try {
populateBySerialIntKeysInt(uMap, hIntMap, testSize); populateBySerialIntKeysInt(uMap, hIntMap, testSize);
compareByUIteratorInt(uMap, hIntMap); compareByUIteratorInt(uMap, hIntMap);
passed++;
populateByRandomIntKeysInt(uMap, hIntMap, testSize); populateByRandomIntKeysInt(uMap, hIntMap, testSize);
compareByUIteratorInt(uMap, hIntMap); compareByUIteratorInt(uMap, hIntMap);
compareByHIteratorInt(uMap, hIntMap); compareByHIteratorInt(uMap, hIntMap);
passed++;
// //
depopulateByIntIterator(uMap, hIntMap, 20); depopulateByIntIterator(uMap, hIntMap, 20);
compareByUIteratorInt(uMap, hIntMap); compareByUIteratorInt(uMap, hIntMap);
compareByHIteratorInt(uMap, hIntMap); compareByHIteratorInt(uMap, hIntMap);
passed++;
// //
clearByIntIterator(uMap, hIntMap); clearByIntIterator(uMap, hIntMap);
compareByUIteratorInt(uMap, hIntMap); compareByUIteratorInt(uMap, hIntMap);
compareByHIteratorInt(uMap, hIntMap); compareByHIteratorInt(uMap, hIntMap);
passed++;
// - // -
populateBySerialIntKeysInt(uMap, hIntMap, testSize); populateBySerialIntKeysInt(uMap, hIntMap, testSize);
compareByUIteratorInt(uMap, hIntMap); compareByUIteratorInt(uMap, hIntMap);
compareByHIteratorInt(uMap, hIntMap); compareByHIteratorInt(uMap, hIntMap);
passed++;
// //
clearByIntIterator(uMap, hIntMap); clearByIntIterator(uMap, hIntMap);
compareByUIteratorInt(uMap, hIntMap); compareByUIteratorInt(uMap, hIntMap);
compareByHIteratorInt(uMap, hIntMap); compareByHIteratorInt(uMap, hIntMap);
} catch (Exception e) { } catch (Exception e) {}
failed = true;
}
assertTrue(!failed); assertTrue(passed == 5);
} }
public void testHashMappedList() throws Exception { public void testHashMappedList() throws Exception {
boolean failed = false; int passed = 0;
int testSize = 33; int testSize = 33;
org.hsqldb.lib.OrderedHashMap hMap = org.hsqldb.lib.OrderedHashMap hMap =
new org.hsqldb.lib.OrderedHashMap(); new org.hsqldb.lib.OrderedHashMap();
java.util.HashMap uMap = new java.util.HashMap(); java.util.HashMap uMap = new java.util.HashMap();
try { try {
populateBySerialIntKeys(uMap, hMap, testSize); populateBySerialIntKeys(uMap, hMap, testSize);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
passed++;
populateByRandomIntKeys(uMap, hMap, testSize); populateByRandomIntKeys(uMap, hMap, testSize);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
passed++;
depopulateRandomly(uMap, hMap, 20); depopulateRandomly(uMap, hMap, 20);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
passed++;
populateByRandomIntKeys(uMap, hMap, testSize); populateByRandomIntKeys(uMap, hMap, testSize);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
passed++;
depopulateRandomly(uMap, hMap, 20); depopulateRandomly(uMap, hMap, 20);
populateBySerialIntKeys(uMap, hMap, testSize); populateBySerialIntKeys(uMap, hMap, testSize);
compareByUIterator(uMap, hMap); compareByUIterator(uMap, hMap);
compareByHIterator(uMap, hMap); compareByHIterator(uMap, hMap);
} catch (Exception e) {
failed = true;
}
assertTrue(!failed); passed++;
} catch (Exception e) {}
assertTrue(passed == 5);
} }
public void testDoubleIntLookup() throws Exception { public void testDoubleIntLookup() throws Exception {
boolean failed = false; int passed = 0;
int testSize = 512; int testSize = 512;
org.hsqldb.lib.IntKeyHashMap hIntMap = org.hsqldb.lib.IntKeyHashMap hIntMap =
new org.hsqldb.lib.IntKeyHashMap(); new org.hsqldb.lib.IntKeyHashMap();
DoubleIntIndex intLookup = new DoubleIntIndex(12); DoubleIntIndex intLookup = new DoubleIntIndex(12);
try { try {
populateBySerialIntKeysInt(intLookup, hIntMap, testSize); populateBySerialIntKeysInt(intLookup, hIntMap, testSize);
compareByHIteratorInt(intLookup, hIntMap); compareByHIteratorInt(intLookup, hIntMap);
passed++;
hIntMap.clear();
intLookup.clear();
populateByRandomIntKeysInt(intLookup, hIntMap, testSize); populateByRandomIntKeysInt(intLookup, hIntMap, testSize);
compareByHIteratorInt(intLookup, hIntMap); compareByHIteratorInt(intLookup, hIntMap);
} catch (Exception e) {
failed = true;
}
assertTrue(!failed); passed++;
} catch (Exception e) {}
assertTrue(passed == 2);
} }
public void testDoubleIntSpeed() throws Exception { public void testDoubleIntSpeed() throws Exception {
boolean failed = false; boolean failed = false;
int testSize = 500; int testSize = 500;
org.hsqldb.lib.IntKeyHashMap hIntMap = org.hsqldb.lib.IntKeyHashMap hIntMap =
new org.hsqldb.lib.IntKeyHashMap(); new org.hsqldb.lib.IntKeyHashMap();
DoubleIntIndex intLookup = new DoubleIntIndex(testSize); DoubleIntIndex intLookup = new DoubleIntIndex(testSize);
skipping to change at line 494 skipping to change at line 528
void compareByUIteratorInt(java.util.HashMap uMap, void compareByUIteratorInt(java.util.HashMap uMap,
org.hsqldb.lib.IntKeyHashMap hMap) org.hsqldb.lib.IntKeyHashMap hMap)
throws Exception { throws Exception {
java.util.Iterator uIt = uMap.keySet().iterator(); java.util.Iterator uIt = uMap.keySet().iterator();
for (int i = 0; uIt.hasNext(); i++) { for (int i = 0; uIt.hasNext(); i++) {
Object uKey = uIt.next(); Object uKey = uIt.next();
Object oU = uMap.get(uKey); Object oU = uMap.get(uKey);
Object hU = hMap.get(((Integer) uKey).intValue()); Object hU = hMap.get(uKey);
if (!oU.equals(hU)) { if (!oU.equals(hU)) {
throw new Exception("HashMap value mismatch"); throw new Exception("HashMap value mismatch");
} }
} }
} }
void compareByHIteratorInt(java.util.HashMap uMap, void compareByHIteratorInt(java.util.HashMap uMap,
org.hsqldb.lib.IntKeyHashMap hMap) org.hsqldb.lib.IntKeyHashMap hMap)
throws Exception { throws Exception {
org.hsqldb.lib.Iterator hIt = hMap.keySet().iterator(); org.hsqldb.lib.Iterator hIt = hMap.keySet().iterator();
for (int i = 0; hIt.hasNext(); i++) { for (int i = 0; hIt.hasNext(); i++) {
Integer hKey = Integer.valueOf(hIt.nextInt()); Integer hKey = Integer.valueOf(hIt.nextInt());
Object oU = uMap.get(hKey); Object oU = uMap.get(hKey);
Object hU = hMap.get(hKey.intValue()); Object hU = hMap.get(hKey.intValue());
if (!oU.equals(hU)) { if (!oU.equals(hU)) {
throw new Exception("HashMap value mismatch"); throw new Exception("HashMap value mismatch");
} }
} }
} }
void compareByHIteratorInt(DoubleIntIndex intLookup, void compareByHIteratorInt(DoubleIntIndex intLookup,
org.hsqldb.lib.IntKeyHashMap hMap) org.hsqldb.lib.IntKeyHashMap hMap)
throws Exception { throws Exception {
org.hsqldb.lib.Iterator hIt = hMap.keySet().iterator(); org.hsqldb.lib.Iterator hIt = hMap.keySet().iterator();
for (int i = 0; hIt.hasNext(); i++) { for (int i = 0; hIt.hasNext(); i++) {
int hK = hIt.nextInt(); int hK = hIt.nextInt();
int lookup = intLookup.findFirstEqualKeyIndex(hK); int lookup = intLookup.findFirstEqualKeyIndex(hK);
int lV = intLookup.getValue(lookup); int lV = intLookup.getValue(lookup);
if (lV == 0) {
Object o = hMap.get(hK);
}
Integer hV = (Integer) hMap.get(hK); Integer hV = (Integer) hMap.get(hK);
if (hV.intValue() != lV) { if (hV.intValue() != lV) {
throw new Exception("HashMap value mismatch"); throw new Exception("HashMap value mismatch");
} }
} }
} }
int nextIntRandom(Random r, int range) { int nextIntRandom(Random r, int range) {
 End of changes. 29 change blocks. 
27 lines changed or deleted 65 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)