use serde::{Deserialize, Serialize}; use solverforge::prelude::*; /// TODO — describe this fact. #[problem_fact] #[derive(Serialize, Deserialize)] pub struct Location { #[planning_id] pub id: String, pub name: String, pub label: String, pub lat_e6: i32, pub lng_e6: i32, pub kind: String, } impl Location { pub fn new( id: impl Into, name: impl Into, label: String, lat_e6: i32, lng_e6: i32, kind: String, ) -> Self { Self { id: id.into(), name: name.into(), label, lat_e6, lng_e6, kind, } } pub fn lat(&self) -> f64 { f64::from(self.lat_e6) / 1_000_000.0 } pub fn lng(&self) -> f64 { f64::from(self.lng_e6) / 1_000_000.0 } } #[cfg(test)] mod tests { use super::*; #[test] fn test_location_construction() { let fact = Location::new( "test-id", "test", "test".to_string(), 0, 0, "test".to_string(), ); assert_eq!(fact.id, "test-id"); assert_eq!(fact.name, "test"); let _ = &fact.label; let _ = &fact.lat_e6; let _ = &fact.lng_e6; let _ = &fact.kind; } }