More tests and cleanup
This commit is contained in:
parent
8b6e3b5d1a
commit
9c99cf46d6
Binary file not shown.
13
justfile
13
justfile
@ -1,9 +1,13 @@
|
||||
build: fmt build-rust build-wasm build-js
|
||||
|
||||
all: clean build # build-docs
|
||||
all: clean fmt test-rust build # build-docs
|
||||
rsync -ha ./web-frontend/build/ build/
|
||||
du -shc build/* | sort -h
|
||||
|
||||
test-rust:
|
||||
cargo test --all
|
||||
cargo fmt --all --check
|
||||
|
||||
build-rust:
|
||||
cargo build --all
|
||||
|
||||
@ -28,10 +32,13 @@ watch-js:
|
||||
|
||||
fmt:
|
||||
# just --fmt --unstable
|
||||
cargo fmt
|
||||
cargo fmt --all
|
||||
yarn --cwd ./web-frontend/ format
|
||||
|
||||
init:
|
||||
serve:
|
||||
http-server --verbose ./web-frontend/build/
|
||||
|
||||
init-verbose:
|
||||
yarn --cwd ./web-frontend/
|
||||
cargo fetch
|
||||
cargo install wasm-pack
|
||||
|
@ -200,7 +200,6 @@ impl Address<'_> {
|
||||
}
|
||||
|
||||
/// Get the address as a latitude and longitude `f64` value
|
||||
// TODO: Test this
|
||||
#[must_use]
|
||||
pub fn as_lat_lon(&self) -> (f64, f64) {
|
||||
let lat_lng = LatLng::from(self.as_cellid());
|
||||
|
@ -1,9 +1,12 @@
|
||||
use common::test_events;
|
||||
use s2::cellid::CellID;
|
||||
use std::cmp;
|
||||
use this_algorithm::Error;
|
||||
use this_algorithm::{Address, CELLID_LEVEL};
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::approx_geodetic_difference_m;
|
||||
use common::ALLOWED_DISTANCE_ERROR_M;
|
||||
use common::CELLID_LEVEL_23_BITMASK;
|
||||
use common::CELLID_LEVEL_23_END_BIT;
|
||||
|
||||
@ -19,14 +22,64 @@ fn test_invalid_lat_lon() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decoding_lat_lon() {
|
||||
let mut max = f64::MIN;
|
||||
let mut min = f64::MAX;
|
||||
for (idx, entry) in test_events().iter().enumerate() {
|
||||
eprintln!("Testing row {idx}");
|
||||
|
||||
let addr = Address::from_lat_lon(entry.lat, entry.lon).unwrap();
|
||||
let addr_latlon = addr.as_lat_lon();
|
||||
|
||||
let (lat_diff, lon_diff) = (
|
||||
(entry.lat - addr_latlon.0).abs(),
|
||||
(entry.lon - addr_latlon.1).abs(),
|
||||
);
|
||||
|
||||
min = if lat_diff < min {
|
||||
lat_diff
|
||||
} else if lon_diff < min {
|
||||
lon_diff
|
||||
} else {
|
||||
min
|
||||
};
|
||||
|
||||
max = if lat_diff > max && lat_diff < 1_f64 {
|
||||
lat_diff
|
||||
} else if lon_diff > max && lon_diff < 1_f64 {
|
||||
lon_diff
|
||||
} else {
|
||||
max
|
||||
};
|
||||
|
||||
if lat_diff > 0.01_f64 || lon_diff > 0.01_f64 {
|
||||
eprintln!(
|
||||
"Uh oh: {lat_diff}, {lon_diff}, ({}, {}) => ({:?}) => ({:?})",
|
||||
entry.lat, entry.lon, addr, addr_latlon
|
||||
);
|
||||
}
|
||||
|
||||
// Ensure the distance is not more than the allowed distance
|
||||
assert!(
|
||||
approx_geodetic_difference_m(addr_latlon, (entry.lat, entry.lon))
|
||||
< ALLOWED_DISTANCE_ERROR_M
|
||||
);
|
||||
|
||||
// assert_eq!((entry.lat, entry.lon), (latlon.0, latlon.1));
|
||||
}
|
||||
eprintln!("Got max: {max} and min: {min}");
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cellid_translation() {
|
||||
for (idx, entry) in test_events().iter().enumerate() {
|
||||
eprintln!("Testing row {idx}");
|
||||
|
||||
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.cellid
|
||||
|
@ -4,6 +4,23 @@ use std::fs::File;
|
||||
use csv::ReaderBuilder;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The allowed error for encoding and decoding points, in meters
|
||||
///
|
||||
/// Due to the selected S2 level being 23, our error is expected to be under 2 meters
|
||||
pub const ALLOWED_DISTANCE_ERROR_M: f64 = 0.0_f64;
|
||||
// The earth's approximate latitude circumfrence
|
||||
pub const EARTH_CIRCUMFERENCE_LAT: f64 = 0.0_f64;
|
||||
// The earth's approximate longitude circumfrence
|
||||
pub const EARTH_CIRCUMFERENCE_LON: f64 = 0.0_f64;
|
||||
|
||||
/// 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;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_eq_u64 {
|
||||
($a:expr, $b:expr) => {{
|
||||
@ -43,10 +60,7 @@ pub struct TestEntry {
|
||||
pub cellid: 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;
|
||||
/// Gets the approximate geodetic difference in meters between two latlons
|
||||
pub fn approx_geodetic_difference_m((lat1, lon1): (f64, f64), (lat2, lon2): (f64, f64)) -> f64 {
|
||||
1000.0_f64
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user