Files
flightplanner/crates/core/tests/navdata_import.rs
T
Alexandre 2cb633e99d Initial commit: offline flight planner (Rust, PFPX-class)
Clean-room reproduction of PFPX: route generation + IFPS validation + OFP.
Independent design — official ICAO/EUROCONTROL data only (RAD, FRA points,
IFPUV oracle); no community FPL sources.

Workspace crates: core (routing/discover/rad/navdata/perf/export),
cli, server, rad (Annex parser), gui (Tauri v2 + React + MapLibre).
Route discovery: oracle-in-the-loop repair against Eurocontrol IFPUV.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 11:10:35 +02:00

58 lines
1.8 KiB
Rust

//! End-to-end step-2 test: parse the hand-made fixtures and import them into an
//! in-memory SQLite database, then assert row counts and a couple of lookups.
use std::path::PathBuf;
use flightplanner_core::db;
use rusqlite::Connection;
fn fixtures_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures")
}
fn count(conn: &Connection, table: &str) -> i64 {
conn.query_row(&format!("SELECT COUNT(*) FROM {table}"), [], |r| r.get(0))
.unwrap()
}
#[test]
fn imports_fixture_navdata() {
let mut conn = Connection::open_in_memory().unwrap();
let stats = db::import_navdata(&mut conn, &fixtures_dir()).unwrap();
// Fixtures: 5 fixes, 1 VOR + 1 NDB (ILS skipped), 4 airway segments, 2 airports.
assert_eq!(stats.waypoints, 5);
assert_eq!(stats.navaids, 2);
assert_eq!(stats.airway_segments, 4);
assert_eq!(stats.airports, 2);
assert_eq!(count(&conn, "waypoints"), 5);
assert_eq!(count(&conn, "navaids"), 2);
assert_eq!(count(&conn, "airway_segments"), 4);
assert_eq!(count(&conn, "airports"), 2);
// A specific fix carries the right region.
let region: String = conn
.query_row(
"SELECT region FROM waypoints WHERE ident = 'DOVER'",
[],
|r| r.get(0),
)
.unwrap();
assert_eq!(region, "EG");
// LFPG reference point is the centroid of its two runway thresholds.
let (lat, lon): (f64, f64) = conn
.query_row(
"SELECT lat, lon FROM airports WHERE icao = 'LFPG'",
[],
|r| Ok((r.get(0)?, r.get(1)?)),
)
.unwrap();
assert!((lat - 48.99).abs() < 0.05, "lat = {lat}");
assert!((lon - 2.56).abs() < 0.05, "lon = {lon}");
// Distinct airway names were recorded.
assert_eq!(count(&conn, "airways"), 2);
}