public void test_insertKeyIntoLeaf02(){
  final int branchingFactor=20;
  final BTree btree=getBTree(branchingFactor);
  final Leaf root=(Leaf)btree.root;
  final byte[][] expectedKeys=new byte[branchingFactor][];
  int nkeys=0;
  while (nkeys < branchingFactor) {
    final byte[] key=new byte[3];
    r.nextBytes(key);
    final int nkeysBefore=root.getKeyCount();
    final boolean exists=btree.lookup(key) != null;
    btree.insert(key,new SimpleEntry());
    if (nkeysBefore == root.getKeyCount()) {
      assertTrue(exists);
      continue;
    }
    assertFalse(exists);
    expectedKeys[nkeys]=key;
    nkeys++;
    assertEquals(nkeys,root.getKeyCount());
  }
  Arrays.sort(expectedKeys,BytesUtil.UnsignedByteArrayComparator.INSTANCE);
  assertTrue(root.dump(Level.DEBUG,System.err));
  assertKeys(expectedKeys,root);
}

public void test_insertKeyIntoLeaf02 ( ) { final int branchingFactor = 20 ; final BTree btree = getBTree ( branchingFactor ) ; final Leaf root = ( Leaf ) btree . root ; final byte [ ] [ ] expectedKeys = new byte [ branchingFactor ] [ ] ; int nkeys = 0 ; while ( nkeys < branchingFactor ) { final byte [ ] key = new byte [ 3 ] ; r . nextBytes ( key ) ; final int nkeysBefore = root . getKeyCount ( ) ; final boolean exists = btree . lookup ( key ) != null ; btree . insert ( key , new SimpleEntry ( ) ) ; if ( nkeysBefore == root . getKeyCount ( ) ) { assertTrue ( exists ) ; continue ; } assertFalse ( exists ) ; expectedKeys [ nkeys ] = key ; nkeys ++ ; assertEquals ( nkeys , root . getKeyCount ( ) ) ; } Arrays . sort ( expectedKeys , BytesUtil . UnsignedByteArrayComparator . INSTANCE ) ; assertTrue ( root . dump ( Level . DEBUG , System . err ) ) ; assertKeys ( expectedKeys , root ) ; }
test ability to insert entries into a leaf . random ( legal ) external keys are inserted into a leaf until the leaf would overflow . the random keys are then sorted and compared with the actual keys in the leaf . if the keys were inserted correctly into the leaf then the two arrays of keys will have the same values in the same order . ( this is a variation on the previous test that inserts keys into the leaf using a slightly higher level api ) .
