Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve HexTreeMap::subtree_iter tests #43

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/iteration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,47 @@ mod tests {

assert_eq!(value_sum, expected_sum);
}

#[test]
fn test_subtree_iter() {
use crate::{compaction::NullCompactor, Cell, HexTreeMap};
use h3o::{CellIndex, Resolution};
use std::convert::TryFrom;

// https://wolf-h3-viewer.glitch.me/?h3=863969a47ffffff
let monaco_res6_cellidx = CellIndex::try_from(0x863969a47ffffff).unwrap();
let monaco_res6_cell = Cell::try_from(u64::from(monaco_res6_cellidx)).unwrap();
// https://wolf-h3-viewer.glitch.me/?h3=863969a6fffffff
let not_monaco_res6_cellidx = CellIndex::try_from(0x863969a6fffffff).unwrap();

let monaco_res10_cells = monaco_res6_cellidx
.children(Resolution::Ten)
.map(|ci| Cell::try_from(u64::from(ci)).unwrap())
.collect::<Vec<_>>();

let not_monaco_res10_cells = not_monaco_res6_cellidx
.children(Resolution::Ten)
.map(|ci| Cell::try_from(u64::from(ci)).unwrap())
.collect::<Vec<_>>();

let monaco_hextree: HexTreeMap<(), NullCompactor> = monaco_res10_cells
.iter()
.copied()
.zip(std::iter::repeat(()))
.collect();

let combined_hextree: HexTreeMap<(), NullCompactor> = monaco_res10_cells
.iter()
.chain(not_monaco_res10_cells.iter())
.copied()
.zip(std::iter::repeat(()))
.collect();

let monaco_hextree_collect = monaco_hextree.iter().map(|item| item.0).collect::<Vec<_>>();
let combined_subtree_collect = combined_hextree
.subtree_iter(monaco_res6_cell)
.map(|item| item.0)
.collect::<Vec<_>>();
assert_eq!(monaco_hextree_collect, combined_subtree_collect);
}
}
Loading