Files
open-meteo-cli/src/coords.rs
T

49 lines
1002 B
Rust
Raw Normal View History

pub struct Coordinates {
pub latitude: f64,
pub longitude: f64,
}
impl Coordinates {
pub fn new(latitude: f64, longitude: f64) -> Coordinates {
Coordinates {
latitude,
longitude,
}
}
pub fn is_correct_latitude(&self) -> bool {
self.latitude > -90.0 && self.latitude < 90.0
}
pub fn is_correct_longitude(&self) -> bool {
self.longitude > -180.0 && self.longitude < 180.0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn valid_coords() {
let coords = Coordinates {
latitude: -20.0,
longitude: 15.0,
};
assert!(coords.is_correct_latitude());
assert!(coords.is_correct_longitude());
}
#[test]
fn invalid_coords() {
let coords = Coordinates {
latitude: -95.0,
longitude: 185.0,
};
assert!(!coords.is_correct_latitude());
assert!(!coords.is_correct_longitude());
}
}