Adding automatic IP address, some refactor and better texts. Upgrading version.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user