Spaces:
Running
Running
| use serde::{Deserialize, Serialize}; | |
| use solverforge::prelude::*; | |
| /// TODO — describe this fact. | |
| pub struct Location { | |
| 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<String>, | |
| name: impl Into<String>, | |
| 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 | |
| } | |
| } | |
| mod tests { | |
| use super::*; | |
| 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; | |
| } | |
| } | |