Use assert_eq for float tests; drop dev depend on float_eq crate
This commit is contained in:
parent
6030134a34
commit
129b29da26
|
@ -26,5 +26,4 @@ thiserror = "1.0.35"
|
||||||
url = { version = "2.3.1", optional = true }
|
url = { version = "2.3.1", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
float_eq = "1.0.0"
|
|
||||||
serde_test = "1.0.145"
|
serde_test = "1.0.145"
|
||||||
|
|
77
src/lib.rs
77
src/lib.rs
|
@ -624,7 +624,6 @@ impl GeoUriBuilder {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use float_eq::assert_float_eq;
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde_test::{assert_de_tokens_error, assert_tokens, Token};
|
use serde_test::{assert_de_tokens_error, assert_tokens, Token};
|
||||||
|
|
||||||
|
@ -662,8 +661,8 @@ mod tests {
|
||||||
|
|
||||||
builder.longitude(5.134);
|
builder.longitude(5.134);
|
||||||
let geo_uri = builder.build()?;
|
let geo_uri = builder.build()?;
|
||||||
assert_float_eq!(geo_uri.latitude, 52.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 52.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_eq!(geo_uri.altitude, None);
|
assert_eq!(geo_uri.altitude, None);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
|
@ -691,8 +690,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn geo_uri_parse() -> Result<(), Error> {
|
fn geo_uri_parse() -> Result<(), Error> {
|
||||||
let geo_uri = GeoUri::parse("geo:52.107,5.134")?;
|
let geo_uri = GeoUri::parse("geo:52.107,5.134")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 52.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 52.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_eq!(geo_uri.altitude, None);
|
assert_eq!(geo_uri.altitude, None);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
|
@ -727,9 +726,9 @@ mod tests {
|
||||||
assert!(matches!(geo_uri, Err(Error::InvalidCoord(_))));
|
assert!(matches!(geo_uri, Err(Error::InvalidCoord(_))));
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6")?;
|
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 52.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 52.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_float_eq!(geo_uri.altitude.unwrap(), 3.6, abs <= 0.1);
|
assert_eq!(geo_uri.altitude.unwrap(), 3.6);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:52.107,5.34,3.6;u=");
|
let geo_uri = GeoUri::parse("geo:52.107,5.34,3.6;u=");
|
||||||
|
@ -745,24 +744,24 @@ mod tests {
|
||||||
assert!(matches!(geo_uri, Err(Error::OutOfRangeUncertainty)));
|
assert!(matches!(geo_uri, Err(Error::OutOfRangeUncertainty)));
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6;u=25000")?;
|
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6;u=25000")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 52.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 52.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_float_eq!(geo_uri.altitude.unwrap(), 3.6, abs <= 0.1);
|
assert_eq!(geo_uri.altitude.unwrap(), 3.6);
|
||||||
assert_eq!(geo_uri.uncertainty, Some(25_000.0));
|
assert_eq!(geo_uri.uncertainty, Some(25_000.0));
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6;crs=wgs84;u=25000")?;
|
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6;crs=wgs84;u=25000")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 52.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 52.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_float_eq!(geo_uri.altitude.unwrap(), 3.6, abs <= 0.1);
|
assert_eq!(geo_uri.altitude.unwrap(), 3.6);
|
||||||
assert_eq!(geo_uri.uncertainty, Some(25_000.0));
|
assert_eq!(geo_uri.uncertainty, Some(25_000.0));
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6;CRS=wgs84;U=25000")?;
|
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6;CRS=wgs84;U=25000")?;
|
||||||
assert_eq!(geo_uri.uncertainty, Some(25_000.0));
|
assert_eq!(geo_uri.uncertainty, Some(25_000.0));
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6;crs=wgs84;u=25000;foo=bar")?;
|
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6;crs=wgs84;u=25000;foo=bar")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 52.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 52.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_float_eq!(geo_uri.altitude.unwrap(), 3.6, abs <= 0.1);
|
assert_eq!(geo_uri.altitude.unwrap(), 3.6);
|
||||||
assert_eq!(geo_uri.uncertainty, Some(25_000.0));
|
assert_eq!(geo_uri.uncertainty, Some(25_000.0));
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:52.107,5.34,3.6;crs=foo");
|
let geo_uri = GeoUri::parse("geo:52.107,5.34,3.6;crs=foo");
|
||||||
|
@ -773,21 +772,21 @@ mod tests {
|
||||||
|
|
||||||
// Examples from RFC 5870 (sections 1, 6.1, 6.2 and 9.4)!
|
// Examples from RFC 5870 (sections 1, 6.1, 6.2 and 9.4)!
|
||||||
let geo_uri = GeoUri::parse("geo:13.4125,103.8667")?;
|
let geo_uri = GeoUri::parse("geo:13.4125,103.8667")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 13.4125, abs <= 0.0001);
|
assert_eq!(geo_uri.latitude, 13.4125);
|
||||||
assert_float_eq!(geo_uri.longitude, 103.8667, abs <= 0.0001);
|
assert_eq!(geo_uri.longitude, 103.8667);
|
||||||
assert_eq!(geo_uri.altitude, None);
|
assert_eq!(geo_uri.altitude, None);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:48.2010,16.3695,183")?;
|
let geo_uri = GeoUri::parse("geo:48.2010,16.3695,183")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 48.2010, abs <= 0.0001);
|
assert_eq!(geo_uri.latitude, 48.2010);
|
||||||
assert_float_eq!(geo_uri.longitude, 16.3695, abs <= 0.0001);
|
assert_eq!(geo_uri.longitude, 16.3695);
|
||||||
assert_float_eq!(geo_uri.altitude.unwrap(), 183.0, abs <= 0.1);
|
assert_eq!(geo_uri.altitude.unwrap(), 183.0);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
let geo_uri = GeoUri::parse("geo:48.198634,16.371648;crs=wgs84;u=40")?;
|
let geo_uri = GeoUri::parse("geo:48.198634,16.371648;crs=wgs84;u=40")?;
|
||||||
assert_eq!(geo_uri.crs, CoordRefSystem::Wgs84);
|
assert_eq!(geo_uri.crs, CoordRefSystem::Wgs84);
|
||||||
assert_float_eq!(geo_uri.latitude, 48.198634, abs <= 0.000001);
|
assert_eq!(geo_uri.latitude, 48.198634);
|
||||||
assert_float_eq!(geo_uri.longitude, 16.371648, abs <= 0.000001);
|
assert_eq!(geo_uri.longitude, 16.371648);
|
||||||
assert_eq!(geo_uri.altitude, None);
|
assert_eq!(geo_uri.altitude, None);
|
||||||
assert_eq!(geo_uri.uncertainty, Some(40.0));
|
assert_eq!(geo_uri.uncertainty, Some(40.0));
|
||||||
|
|
||||||
|
@ -896,8 +895,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn geo_uri_from_str() -> Result<(), Error> {
|
fn geo_uri_from_str() -> Result<(), Error> {
|
||||||
let geo_uri = GeoUri::from_str("geo:52.107,5.134")?;
|
let geo_uri = GeoUri::from_str("geo:52.107,5.134")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 52.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 52.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_eq!(geo_uri.altitude, None);
|
assert_eq!(geo_uri.altitude, None);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
|
@ -930,15 +929,15 @@ mod tests {
|
||||||
fn geo_uri_try_from() -> Result<(), Error> {
|
fn geo_uri_try_from() -> Result<(), Error> {
|
||||||
// &str
|
// &str
|
||||||
let geo_uri = GeoUri::try_from("geo:52.107,5.134")?;
|
let geo_uri = GeoUri::try_from("geo:52.107,5.134")?;
|
||||||
assert_float_eq!(geo_uri.latitude, 52.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 52.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_eq!(geo_uri.altitude, None);
|
assert_eq!(geo_uri.altitude, None);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
// (f64, f64)
|
// (f64, f64)
|
||||||
let geo_uri = GeoUri::try_from((51.107, 5.134))?;
|
let geo_uri = GeoUri::try_from((51.107, 5.134))?;
|
||||||
assert_float_eq!(geo_uri.latitude, 51.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 51.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_eq!(geo_uri.altitude, None);
|
assert_eq!(geo_uri.altitude, None);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
|
@ -953,9 +952,9 @@ mod tests {
|
||||||
|
|
||||||
// (f64, f64, f64)
|
// (f64, f64, f64)
|
||||||
let geo_uri = GeoUri::try_from((51.107, 5.134, 3.6))?;
|
let geo_uri = GeoUri::try_from((51.107, 5.134, 3.6))?;
|
||||||
assert_float_eq!(geo_uri.latitude, 51.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 51.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_float_eq!(geo_uri.altitude.unwrap(), 3.6, abs <= 0.1);
|
assert_eq!(geo_uri.altitude.unwrap(), 3.6);
|
||||||
assert_eq!(geo_uri.uncertainty, None);
|
assert_eq!(geo_uri.uncertainty, None);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -976,15 +975,15 @@ mod tests {
|
||||||
// Url
|
// Url
|
||||||
let url = Url::parse("geo:51.107,5.134,3.6;crs=wgs84;u=1000;foo=bar").expect("valid URL");
|
let url = Url::parse("geo:51.107,5.134,3.6;crs=wgs84;u=1000;foo=bar").expect("valid URL");
|
||||||
let geo_uri = GeoUri::try_from(&url)?;
|
let geo_uri = GeoUri::try_from(&url)?;
|
||||||
assert_float_eq!(geo_uri.latitude, 51.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 51.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_float_eq!(geo_uri.altitude.unwrap(), 3.6, abs <= 0.1);
|
assert_eq!(geo_uri.altitude.unwrap(), 3.6);
|
||||||
assert_eq!(geo_uri.uncertainty, Some(1000.0));
|
assert_eq!(geo_uri.uncertainty, Some(1000.0));
|
||||||
|
|
||||||
let geo_uri = GeoUri::try_from(url)?;
|
let geo_uri = GeoUri::try_from(url)?;
|
||||||
assert_float_eq!(geo_uri.latitude, 51.107, abs <= 0.001);
|
assert_eq!(geo_uri.latitude, 51.107);
|
||||||
assert_float_eq!(geo_uri.longitude, 5.134, abs <= 0.001);
|
assert_eq!(geo_uri.longitude, 5.134);
|
||||||
assert_float_eq!(geo_uri.altitude.unwrap(), 3.6, abs <= 0.1);
|
assert_eq!(geo_uri.altitude.unwrap(), 3.6);
|
||||||
assert_eq!(geo_uri.uncertainty, Some(1000.0));
|
assert_eq!(geo_uri.uncertainty, Some(1000.0));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue