Adding automatic IP address, some refactor and better texts. Upgrading version.

This commit is contained in:
2023-05-23 01:17:03 +02:00
parent 3bd55576ce
commit 01ac2ca7b7
12 changed files with 496 additions and 149 deletions
+48
View File
@@ -0,0 +1,48 @@
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 {
return self.latitude > -90.0 && self.latitude < 90.0;
}
pub fn is_correct_longitude(&self) -> bool {
return 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());
}
}