Skip to content

Commit

Permalink
test: add test case mutable::range & `merge_stream::merge_mutable_r…
Browse files Browse the repository at this point in the history
…emove_duplicates`
  • Loading branch information
KKould authored and ethe committed Jul 16, 2024
1 parent 590e793 commit 2601443
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
64 changes: 63 additions & 1 deletion src/inmem/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where

#[cfg(test)]
mod tests {
use std::ops::Bound;
use std::collections::Bound;

use super::Mutable;
use crate::{
Expand Down Expand Up @@ -157,4 +157,66 @@ mod tests {
}
)
}

#[test]
fn range() {
let mutable = Mutable::<String>::new();

mutable.insert("1".into(), 0_u32.into());
mutable.insert("2".into(), 0_u32.into());
mutable.insert("2".into(), 1_u32.into());
mutable.insert("3".into(), 1_u32.into());
mutable.insert("4".into(), 0_u32.into());

let mut scan = mutable.scan((Bound::Unbounded, Bound::Unbounded), 0_u32.into());

assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("1".into(), 0_u32.into())
);
assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("2".into(), 1_u32.into())
);
assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("2".into(), 0_u32.into())
);
assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("3".into(), 1_u32.into())
);
assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("4".into(), 0_u32.into())
);

let lower = "1".to_string();
let upper = "4".to_string();
let mut scan = mutable.scan(
(Bound::Included(&lower), Bound::Included(&upper)),
1_u32.into(),
);

assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("1".into(), 0_u32.into())
);
assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("2".into(), 1_u32.into())
);
assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("2".into(), 0_u32.into())
);
assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("3".into(), 1_u32.into())
);
assert_eq!(
scan.next().unwrap().key(),
&Timestamped::new("4".into(), 0_u32.into())
);
}
}
32 changes: 32 additions & 0 deletions src/stream/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,36 @@ mod tests {
dbg!(merge.next().await);
dbg!(merge.next().await);
}

#[tokio::test]
async fn merge_mutable_remove_duplicates() {
let m1 = Mutable::<String>::new();
m1.insert("1".into(), 0_u32.into());
m1.insert("2".into(), 0_u32.into());
m1.insert("2".into(), 1_u32.into());
m1.insert("3".into(), 1_u32.into());
m1.insert("4".into(), 0_u32.into());

let lower = "1".to_string();
let upper = "4".to_string();
let bound = (Bound::Included(&lower), Bound::Included(&upper));
let mut merge = MergeStream::from_vec(vec![m1.scan(bound, 0.into()).into()])
.await
.unwrap();

dbg!(merge.next().await);
dbg!(merge.next().await);
dbg!(merge.next().await);

let lower = "1".to_string();
let upper = "4".to_string();
let bound = (Bound::Included(&lower), Bound::Included(&upper));
let mut merge = MergeStream::from_vec(vec![m1.scan(bound, 1.into()).into()])
.await
.unwrap();

dbg!(merge.next().await);
dbg!(merge.next().await);
dbg!(merge.next().await);
}
}

0 comments on commit 2601443

Please sign in to comment.