Skip to content

Commit

Permalink
Add test case for erroneous ZeroMap2d construction
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Oct 14, 2023
1 parent a887449 commit da7e169
Showing 1 changed file with 220 additions and 0 deletions.
220 changes: 220 additions & 0 deletions components/timezone/src/metazone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,223 @@ impl MetazoneCalculator {
}
}
}

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

#[test]
fn zeromap2d_metazone() {
let source_data = [
(
TimeZoneBcp47Id(tinystr!(8, "sydam")),
0,
Some(MetazoneId(tinystr!(4, "euea"))),
),
(TimeZoneBcp47Id(tinystr!(8, "bddac")), 0, None),
(
TimeZoneBcp47Id(tinystr!(8, "bddac")),
646200,
Some(MetazoneId(tinystr!(4, "bang"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "tldil")),
0,
Some(MetazoneId(tinystr!(4, "eati"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "tldil")),
3331620,
Some(MetazoneId(tinystr!(4, "ince"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "tldil")),
16152000,
Some(MetazoneId(tinystr!(4, "eati"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "aedxb")),
0,
Some(MetazoneId(tinystr!(4, "gulf"))),
),
(TimeZoneBcp47Id(tinystr!(8, "tjdyu")), 0, None),
(
TimeZoneBcp47Id(tinystr!(8, "tjdyu")),
11406060,
Some(MetazoneId(tinystr!(4, "taji"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "cyfmg")),
0,
Some(MetazoneId(tinystr!(4, "euea"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "gazastrp")),
0,
Some(MetazoneId(tinystr!(4, "isra"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "gazastrp")),
13674120,
Some(MetazoneId(tinystr!(4, "euea"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "hebron")),
0,
Some(MetazoneId(tinystr!(4, "isra"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "hebron")),
13674120,
Some(MetazoneId(tinystr!(4, "euea"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "hkhkg")),
0,
Some(MetazoneId(tinystr!(4, "hoko"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "mnhvd")),
0,
Some(MetazoneId(tinystr!(4, "hovd"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "ruikt")),
0,
Some(MetazoneId(tinystr!(4, "irku"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "idjkt")),
0,
Some(MetazoneId(tinystr!(4, "inwe"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "iddjj")),
0,
Some(MetazoneId(tinystr!(4, "inea"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "jeruslm")),
0,
Some(MetazoneId(tinystr!(4, "isra"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "afkbl")),
0,
Some(MetazoneId(tinystr!(4, "afgh"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "rupkc")),
0,
Some(MetazoneId(tinystr!(4, "kamc"))),
),
(TimeZoneBcp47Id(tinystr!(8, "pkkhi")), 0, None),
(
TimeZoneBcp47Id(tinystr!(8, "pkkhi")),
646260,
Some(MetazoneId(tinystr!(4, "paki"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "npktm")),
0,
Some(MetazoneId(tinystr!(4, "nepa"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "rukhndg")),
0,
Some(MetazoneId(tinystr!(4, "yaku"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "rukhndg")),
17881380,
Some(MetazoneId(tinystr!(4, "vlad"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "rukhndg")),
21930540,
Some(MetazoneId(tinystr!(4, "yaku"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "rukra")),
0,
Some(MetazoneId(tinystr!(4, "kras"))),
),
(TimeZoneBcp47Id(tinystr!(8, "mykul")), 0, None),
(
TimeZoneBcp47Id(tinystr!(8, "mykul")),
6311070,
Some(MetazoneId(tinystr!(4, "mala"))),
),
(TimeZoneBcp47Id(tinystr!(8, "mykch")), 0, None),
(
TimeZoneBcp47Id(tinystr!(8, "mykch")),
6311040,
Some(MetazoneId(tinystr!(4, "mala"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "kwkwi")),
0,
Some(MetazoneId(tinystr!(4, "arab"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "pst8pdt")),
0,
Some(MetazoneId(tinystr!(4, "ampa"))),
),
(TimeZoneBcp47Id(tinystr!(8, "ushnl")), 0, None),
(
TimeZoneBcp47Id(tinystr!(8, "ushnl")),
7272660,
Some(MetazoneId(tinystr!(4, "haal"))),
),
(TimeZoneBcp47Id(tinystr!(8, "ushnl")), 0, None),
(
TimeZoneBcp47Id(tinystr!(8, "ushnl")),
7272660,
Some(MetazoneId(tinystr!(4, "haal"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "kicxi")),
0,
Some(MetazoneId(tinystr!(4, "liis"))),
),
(
TimeZoneBcp47Id(tinystr!(8, "fmksa")),
0,
Some(MetazoneId(tinystr!(4, "kosr"))),
),
(TimeZoneBcp47Id(tinystr!(8, "mhkwa")), 0, None),
(
TimeZoneBcp47Id(tinystr!(8, "mhkwa")),
12432240,
Some(MetazoneId(tinystr!(4, "mais"))),
),
];

let btreemap: BTreeMap<(TimeZoneBcp47Id, i32), Option<MetazoneId>> = source_data
.iter()
.copied()
.map(|(a, b, c)| ((a, b), c))
.collect();

let zeromap2d: ZeroMap2d<TimeZoneBcp47Id, i32, Option<MetazoneId>> =
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 da7e169

Please sign in to comment.