Skip to content

Commit

Permalink
add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
wngr committed Mar 17, 2021
1 parent 2fea7fa commit cab7d66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion banyan-utils/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ async fn main() -> Result<()> {
}
Command::DumpValues { root } => {
let tree = forest.load_tree(root)?;
let iter = forest.iter_from(&tree, 0);
let iter = forest.iter_from(&tree);
for res in iter {
let (i, k, v) = res?;
println!("{:?} {:?} {:?}", i, k, v);
Expand Down
24 changes: 24 additions & 0 deletions banyan/tests/build_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use banyan::{
};
use futures::prelude::*;
use libipld::{cbor::DagCborCodec, codec::Codec, Cid};
use quickcheck_macros::quickcheck;
use std::{convert::TryInto, iter, ops::Range, str::FromStr};

use common::{create_test_tree, test, txn, Key, KeySeq, Sha256Digest, TT};
Expand Down Expand Up @@ -259,6 +260,29 @@ async fn retain(xss: Vec<Vec<(Key, u64)>>) -> quickcheck::TestResult {
.await
}

#[quickcheck]
fn iter_from_should_return_all_items(xs: Vec<(Key, u64)>) -> anyhow::Result<bool> {
let store = MemStore::new(usize::max_value(), Sha256Digest::digest);
let forest = txn(store, 1000);
let mut tree = Tree::<TT>::empty();
tree = forest.extend(&tree, xs.clone().into_iter())?;
forest.assert_invariants(&tree)?;
let actual = forest
.iter_from(&tree)
.map(Result::unwrap)
.collect::<Vec<_>>();
let expected = xs
.iter()
.cloned()
.enumerate()
.map(|(i, (k, v))| (i as u64, k, v))
.collect::<Vec<_>>();
if expected != actual {
println!("{:?} {:?}", expected, actual);
}
Ok(expected == actual)
}

#[tokio::test]
async fn filter_test_simple() -> anyhow::Result<()> {
let _ = env_logger::builder().is_test(true).try_init();
Expand Down

0 comments on commit cab7d66

Please sign in to comment.