this_algorithm/tests/algorithm.rs

52 lines
1.5 KiB
Rust
Raw Normal View History

2023-02-24 00:31:32 -05:00
use common::test_events;
2023-02-22 21:55:40 -05:00
use s2::cellid::CellID;
use this_algorithm::{Address, CELLID_LEVEL};
#[macro_use]
mod common;
2023-02-24 00:31:32 -05:00
use common::CELLID_LEVEL_23_BITMASK;
use common::CELLID_LEVEL_23_END_BIT;
2023-02-22 21:55:40 -05:00
#[test]
fn test_cellid_translation() {
2023-02-24 00:31:32 -05:00
for (idx, entry) in test_events().iter().enumerate() {
let addr = Address::from_lat_lon(entry.lat, entry.lon).unwrap();
2023-02-24 00:37:55 -05:00
let addr_cellid = addr.as_cell_id();
2023-02-22 21:55:40 -05:00
2023-02-24 00:31:32 -05:00
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,
2023-02-25 11:14:15 -05:00
CellID(entry.cell_id).parent(CELLID_LEVEL).0
2023-02-24 00:31:32 -05:00
);
2023-02-22 21:55:40 -05:00
// Make sure the address is at the right level
2023-02-25 11:14:15 -05:00
assert_eq!(addr_cellid.level(), CELLID_LEVEL);
2023-02-22 21:55:40 -05:00
// 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
2023-02-25 11:14:15 -05:00
assert_eq_u64!(addr_cellid.0, CellID(entry.cell_id).parent(CELLID_LEVEL).0);
2023-02-22 21:55:40 -05:00
}
}
#[test]
2023-02-24 00:31:32 -05:00
fn test_encoding() {
for (_idx, entry) in test_events().iter().enumerate() {
let addr = Address::from_lat_lon(entry.lat, entry.lon).unwrap();
2023-02-25 11:14:15 -05:00
eprintln!("({}, {}) => {addr}", entry.lat, entry.lon);
2023-02-24 00:31:32 -05:00
}
assert!(false);
}
2023-02-22 21:55:40 -05:00
#[test]
fn test_decoding() {}