@Test
public void testFindAndPrevious()
    throws InterruptedException, DeadlockException, TransactionRolledBackException, IOException
{

    for (int n = 0; n < 100; n++) {
        // debug("n: %s", n);
        loadDisklessDatabase(n);
        Cursor cursor;
        TestRecord record;
        TestKey key;
        int expected;
        // Complete cursor
        {
            expected = n;
            cursor = map.last();
            while ((record = (TestRecord) cursor.previous()) != null) {
                // debug("expected: %s, actual: %s", (expected - 1) * GAP, record.key());
                checkRecord(--expected, record);
            }
            assertEquals(0, expected);
        }
        // Random access
        {
            // Test:
            // -    k * GAP - GAP/2 (missing)
            // -    k * GAP (present if k < n, missing if k = n)
            for (int k = 0; k <= n; k++) {
                // Test missing
                {
                    int missingKey = k * GAP - GAP / 2;
                    key = new TestKey(missingKey);
                    // test find -> record
                    record = (TestRecord) map.find(key);
                    assertNull(record);
                    // test find -> cursor
                    cursor = map.cursor(key);
                    expected = k;
                    while ((record = (TestRecord) cursor.previous()) != null) {
                        checkRecord(--expected, record);
                    }
                    assertEquals(0, expected);
                }
                // Test present
                int presentKey = k * GAP;
                expected = k;
                key = new TestKey(presentKey);
                // test find -> record
                record = (TestRecord) map.find(key);
                if (k < n) {
                    checkRecord(expected, record);
                    // test find -> cursor
                    cursor = map.cursor(key);
                    while ((record = (TestRecord) cursor.previous()) != null) {
                        checkRecord(expected--, record);
                    }
                    assertEquals(n == 0 ? 0 : -1, expected);
                } else {
                    assertEquals(n, k);
                    assertNull(record);
                }
            }
        }
    }
}