this_algorithm/tests/common/mod.rs

52 lines
1.5 KiB
Rust
Raw Normal View History

2023-02-24 00:31:32 -05:00
use std::fs::File;
use csv::ReaderBuilder;
use serde::{Deserialize, Serialize};
2023-02-22 21:55:40 -05:00
#[macro_export]
macro_rules! assert_eq_u64 {
($a:expr, $b:expr) => {{
let are_equal = $a == $b;
let diff = $a ^ $b;
eprintln!("Comparing u64:");
let a_txt = format!("{:0>64b}", $a).replace('0', " ");
let b_txt = format!("{:0>64b}", $b).replace('0', " ");
let diff_txt = if diff == 0 {
String::from("NONE")
} else {
format!("{:0>64b}", diff)
.replace('0', " ")
.replace('1', "~")
};
2023-02-24 00:31:32 -05:00
eprintln!("\t.{a_txt}.");
eprintln!("\t.{b_txt}.");
eprintln!("Diff:\t.{diff_txt}.");
2023-02-15 21:16:43 -05:00
2023-02-24 00:31:32 -05:00
assert!(are_equal);
2023-02-22 21:55:40 -05:00
}};
}
2023-02-24 00:31:32 -05:00
/// Get a Vec of test entries
pub fn test_events() -> Vec<TestEntry> {
ReaderBuilder::new()
.from_reader(File::open("./test-data/01-sample-latlon-s2cpp-cellid.csv").unwrap())
.deserialize()
.collect::<Result<Vec<_>, _>>()
.unwrap()
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct TestEntry {
pub lat: f64,
pub lon: f64,
pub cell_id: u64,
}
2023-02-25 11:14:15 -05:00
/// Bitmask to preserve all data bits at level 23
2023-02-24 00:31:32 -05:00
pub const CELLID_LEVEL_23_BITMASK: u64 =
0b11111111_11111111_11111111_11111111_11111111_11111111_10000000_00000000;
2023-02-25 11:14:15 -05:00
/// The single 1 bit at the end of level 23
2023-02-24 00:31:32 -05:00
pub const CELLID_LEVEL_23_END_BIT: u64 =
0b00000000_00000000_00000000_00000000_00000000_00000000_01000000_00000000;