Skip to content

Commit

Permalink
Move test to zerovec component
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Oct 14, 2023
1 parent e6856fd commit 40ad0ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 43 deletions.
43 changes: 0 additions & 43 deletions components/timezone/src/metazone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,3 @@ impl MetazoneCalculator {
}
}
}

#[cfg(test)]
mod tests {
use alloc::collections::BTreeMap;
use zerovec::ZeroMap2d;

#[test]
fn zeromap2d_metazone() {
let source_data = [
(*b"aedxb", 0, Some(*b"gulf")),
(*b"afkbl", 0, Some(*b"afgh")),
(*b"ushnl", 0, None),
(*b"ushnl", 7272660, Some(*b"haal")),
(*b"ushnl", 0, None),
(*b"ushnl", 7272660, Some(*b"haal")),
];

let btreemap: BTreeMap<([u8; 5], i32), Option<[u8; 4]>> = source_data
.iter()
.copied()
.map(|(a, b, c)| ((a, b), c))
.collect();

let zeromap2d: ZeroMap2d<[u8; 5], i32, Option<[u8; 4]>> =
source_data.iter().copied().collect();

let mut btreemap_iter = btreemap.iter();

eprintln!("{zeromap2d:?}");

for cursor in zeromap2d.iter0() {
for (key1, value) in cursor.iter1() {
// This code runs for every (key0, key1) pair in order
let expected = btreemap_iter.next().unwrap();
assert_eq!(
(expected.0 .0, expected.0 .1, expected.1),
(*cursor.key0(), key1.as_unsigned_int() as i32, &value.get())
);
}
}
assert!(btreemap_iter.next().is_none());
}
}
36 changes: 36 additions & 0 deletions utils/zerovec/src/map2d/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ where
#[cfg(test)]
mod test {
use super::*;
use alloc::collections::BTreeMap;

#[test]
fn stress_test() {
Expand Down Expand Up @@ -824,4 +825,39 @@ mod test {

assert_eq!(format!("{zm2d:?}"), "ZeroMap2d { keys0: ZeroVec([3, 6, 7]), joiner: ZeroVec([1, 4, 7]), keys1: [\"eee\", \"ddd\", \"mmm\", \"nnn\", \"ddd\", \"eee\", \"www\"], values: [\"EEE\", \"DD3\", \"MM1\", \"NNN\", \"DD2\", \"EEE\", \"WWW\"] }");
}

#[test]
fn zeromap2d_metazone() {
let source_data = [
(*b"aedxb", 0, Some(*b"gulf")),
(*b"afkbl", 0, Some(*b"afgh")),
(*b"ushnl", 0, None),
(*b"ushnl", 7272660, Some(*b"haal")),
(*b"ushnl", 0, None),
(*b"ushnl", 7272660, Some(*b"haal")),
];

let btreemap: BTreeMap<([u8; 5], i32), Option<[u8; 4]>> = source_data
.iter()
.copied()
.map(|(a, b, c)| ((a, b), c))
.collect();

let zeromap2d: ZeroMap2d<[u8; 5], i32, Option<[u8; 4]>> =
source_data.iter().copied().collect();

let mut btreemap_iter = btreemap.iter();

for cursor in zeromap2d.iter0() {
for (key1, value) in cursor.iter1() {
// This code runs for every (key0, key1) pair in order
let expected = btreemap_iter.next().unwrap();
assert_eq!(
(expected.0 .0, expected.0 .1, expected.1),
(*cursor.key0(), key1.as_unsigned_int() as i32, &value.get())
);
}
}
assert!(btreemap_iter.next().is_none());
}
}

0 comments on commit 40ad0ec

Please sign in to comment.