Files
open-meteo-cli/src/coords.rs
T
midefos 1affcb9d1a
ci/woodpecker/push/woodpecker Pipeline was successful
Correct stdout, updating lib and some clippy clean
2023-07-30 18:13:42 +02:00

49 lines
1002 B
Rust

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());
}
}