66 lines
1.8 KiB
Rust
66 lines
1.8 KiB
Rust
use common::test_events;
|
|
use s2::cellid::CellID;
|
|
use this_algorithm::Error;
|
|
use this_algorithm::{Address, CELLID_LEVEL};
|
|
#[macro_use]
|
|
mod common;
|
|
use common::CELLID_LEVEL_23_BITMASK;
|
|
use common::CELLID_LEVEL_23_END_BIT;
|
|
|
|
#[test]
|
|
fn test_invalid_lat_lon() {
|
|
assert_eq!(
|
|
Address::from_lat_lon(1.0_f64, 400.0_f64),
|
|
Err(Error::InvalidLatLng)
|
|
);
|
|
assert_eq!(
|
|
Address::from_lat_lon(1.0_f64, f64::NAN),
|
|
Err(Error::InvalidLatLng)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_cellid_translation() {
|
|
for (idx, entry) in test_events().iter().enumerate() {
|
|
let addr = Address::from_lat_lon(entry.lat, entry.lon).unwrap();
|
|
let addr_cellid = addr.as_cellid();
|
|
|
|
eprintln!("Testing word {idx}");
|
|
|
|
eprintln!(
|
|
"Entry: ({},{}) => {:0>64b}",
|
|
entry.lat, entry.lon, entry.cell_id
|
|
);
|
|
eprintln!("\taddr: {addr}");
|
|
|
|
// Make sure the rust s2 implementation is accurate
|
|
assert_eq!(entry.cell_id, CellID(entry.cell_id).0);
|
|
assert_eq!(
|
|
(entry.cell_id & CELLID_LEVEL_23_BITMASK) | CELLID_LEVEL_23_END_BIT,
|
|
CellID(entry.cell_id).parent(CELLID_LEVEL).0
|
|
);
|
|
|
|
// Make sure the address is at the right level
|
|
assert_eq!(addr_cellid.level(), CELLID_LEVEL);
|
|
|
|
// Next, check if creating an address from a cellid matches itself
|
|
assert_eq!(addr, Address::from_cellid_u64(entry.cell_id));
|
|
|
|
// Now check if the actual cell id matches
|
|
assert_eq_u64!(addr_cellid.0, CellID(entry.cell_id).parent(CELLID_LEVEL).0);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_encoding() {
|
|
for (_idx, entry) in test_events().iter().enumerate() {
|
|
let addr = Address::from_lat_lon(entry.lat, entry.lon).unwrap();
|
|
eprintln!("({}, {}) => {addr}", entry.lat, entry.lon);
|
|
}
|
|
// TODO:
|
|
// assert!(false);
|
|
}
|
|
|
|
#[test]
|
|
fn test_decoding() {}
|