this_algorithm/tests/common/mod.rs
Austen Adler 0546720e3d Cleanup
2023-02-25 16:44:22 -05:00

53 lines
1.5 KiB
Rust

#![allow(dead_code)]
use std::fs::File;
use csv::ReaderBuilder;
use serde::{Deserialize, Serialize};
#[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', "~")
};
eprintln!("\t.{a_txt}.");
eprintln!("\t.{b_txt}.");
eprintln!("Diff:\t.{diff_txt}.");
assert!(are_equal);
}};
}
/// 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,
}
/// Bitmask to preserve all data bits at level 23
pub const CELLID_LEVEL_23_BITMASK: u64 =
0b11111111_11111111_11111111_11111111_11111111_11111111_10000000_00000000;
/// The single 1 bit at the end of level 23
pub const CELLID_LEVEL_23_END_BIT: u64 =
0b00000000_00000000_00000000_00000000_00000000_00000000_01000000_00000000;