Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Nov 22, 2024
1 parent 39e0edd commit afe58c1
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/segment_range_oob.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use lsm_tree::{AbstractTree, Config};
use test_log::test;

const ITEM_COUNT: usize = 100;

#[test]
fn segment_range_out_of_bounds_lo() -> lsm_tree::Result<()> {
let folder = tempfile::tempdir()?.into_path();

let tree = Config::new(folder)
.data_block_size(1_024)
.index_block_size(1_024)
.open()?;

for key in ('h'..='o').map(|c| c.to_string()) {
let value = nanoid::nanoid!();
tree.insert(key, value.as_bytes(), 0);
}
tree.flush_active_memtable(0)?;

assert_eq!(4, tree.range(..="k").count());
assert_eq!(4, tree.range(..="k").rev().count());

assert_eq!(4, tree.range("0"..="k").count());
assert_eq!(4, tree.range("0"..="k").rev().count());

Ok(())
}

#[test]
fn segment_range_out_of_bounds_hi() -> lsm_tree::Result<()> {
let folder = tempfile::tempdir()?.into_path();

let tree = Config::new(folder)
.data_block_size(1_024)
.index_block_size(1_024)
.open()?;

for x in 0..ITEM_COUNT as u64 {
let key = x.to_be_bytes();
let value = nanoid::nanoid!();
tree.insert(key, value.as_bytes(), 0);
}
tree.flush_active_memtable(0)?;

assert_eq!(50, tree.range((50u64.to_be_bytes())..).count());
assert_eq!(50, tree.range((50u64.to_be_bytes())..).rev().count());

assert_eq!(
50,
tree.range((50u64.to_be_bytes())..(150u64.to_be_bytes()))
.count()
);
assert_eq!(
50,
tree.range((50u64.to_be_bytes())..(150u64.to_be_bytes()))
.rev()
.count()
);

Ok(())
}

0 comments on commit afe58c1

Please sign in to comment.