Skip to content

Commit 3c33538

Browse files
Merge #54
54: use `approx` for better failure output r=urschrei a=michaelkirk Gives output like: ``` assert_relative_eq!(t.x(), 1450880.29) left = 0.0 right = 1450880.29 ``` vs previously: ``` thread 'proj::test::test_london_inverse' panicked at 'assertion failed: f > 0.99999', src/proj.rs:885:9 ``` Co-authored-by: Michael Kirk <[email protected]>
2 parents a6cc3a1 + 0cdb489 commit 3c33538

File tree

6 files changed

+69
-72
lines changed

6 files changed

+69
-72
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pkg_config = [ "proj-sys/pkg_config" ]
2929
network = ["reqwest"]
3030

3131
[dev-dependencies]
32-
assert_approx_eq = "1.1.0"
32+
approx = "0.3"
3333

3434
[package.metadata.docs.rs]
3535
features = [ "proj-sys/nobuild", "network", "geo-types" ]

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ let ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap();
4040
let result = ft_to_m
4141
.convert((4760096.421921f64, 3744293.729449f64))
4242
.unwrap();
43-
assert_approx_eq!(result.0, 1450880.2910605003);
44-
assert_approx_eq!(result.1, 1141263.0111604529);
43+
assert_relative_eq!(result.0, 1450880.2910605003);
44+
assert_relative_eq!(result.1, 1141263.0111604529);
4545
```
4646

4747
### Convert from [NAD 83 US Survey Feet](https://epsg.io/2230) to [NAD 83 Meters](https://epsg.io/26946) Using the `pipeline` Operator
@@ -71,8 +71,8 @@ let ft_to_m = Proj::new("
7171

7272
// The Presidio, approximately
7373
let result = ft_to_m.convert((4760096.421921f64, 3744293.729449f64)).unwrap();
74-
assert_approx_eq!(result.0, 1450880.2910605003);
75-
assert_approx_eq!(result.1, 1141263.01116045);
74+
assert_relative_eq!(result.0, 1450880.2910605003);
75+
assert_relative_eq!(result.1, 1141263.01116045);
7676
```
7777

7878
### Inverse Projection from [Stereo70](https://epsg.io/3844) to Geodetic
@@ -90,8 +90,8 @@ let stereo70 = Proj::new("
9090
let geodetic_radians_point = stereo70.project(
9191
(500119.70352012233f64, 500027.77896348457f64), true
9292
).unwrap();
93-
assert_approx_eq!(geodetic_radians_point.0, 0.436332);
94-
assert_approx_eq!(geodetic_radians_point.1, 0.802851);
93+
assert_relative_eq!(geodetic_radians_point.0, 0.436332, epsilon=1e-5);
94+
assert_relative_eq!(geodetic_radians_point.1, 0.802851, epsiolon=1e-5);
9595
```
9696

9797
## Usage
@@ -187,8 +187,8 @@ let proj = Proj::new_known_crs(&from, &to, None).unwrap();
187187

188188
let result = proj.convert(donut_shop).unwrap();
189189

190-
assert_approx_eq!(result.x(), 158458.67251293268);
191-
assert_approx_eq!(result.y(), -434296.8803996085);
190+
assert_relative_eq!(result.x(), 158458.67251293268);
191+
assert_relative_eq!(result.y(), -434296.8803996085);
192192
```
193193

194194
### Integration with `geo-types`
@@ -197,7 +197,7 @@ If you've enabled the `geo-types` feature, you can skip allocating an intermedia
197197
and pass the [`geo-types`](https://crates.io/crates/geo-types) directly.
198198

199199
```rust
200-
# use assert_approx_eq::assert_approx_eq;
200+
# use approx::assert_relative_eq;
201201
use proj::Proj;
202202
use geo_types::Point;
203203

@@ -209,8 +209,8 @@ let nad_ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap();
209209

210210
let result = nad_ft_to_m.convert(my_point).unwrap();
211211

212-
assert_approx_eq!(result.x(), 1450880.2910605003f64);
213-
assert_approx_eq!(result.y(), 1141263.0111604529f64);
212+
assert_relative_eq!(result.x(), 1450880.2910605003f64);
213+
assert_relative_eq!(result.y(), 1141263.0111604529f64);
214214
```
215215

216216
License: MIT/Apache-2.0

proj-sys/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! [`proj`](https://github.com/georust/proj) crate for general use.
1111
//!
1212
//! A guide to the functions can be found here:
13-
//! https://proj.org/development/reference/functions.html.
13+
//! <https://proj.org/development/reference/functions.html>.
1414
//!
1515
//! By default, the crate will search for an existing `libproj` (via `PROJ v7.1.x`)
1616
//! installation on your system using

src/geo_types.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///```rust
2-
/// # use assert_approx_eq::assert_approx_eq;
2+
/// # use approx::assert_relative_eq;
33
/// extern crate proj;
44
/// use proj::Proj;
55
/// use geo_types::Coordinate;
@@ -10,8 +10,8 @@
1010
/// let result = nad_ft_to_m
1111
/// .convert(Coordinate { x: 4760096.421921f64, y: 3744293.729449f64 })
1212
/// .unwrap();
13-
/// assert_approx_eq!(result.x, 1450880.29f64, 1.0e-2);
14-
/// assert_approx_eq!(result.y, 1141263.01f64, 1.0e-2);
13+
/// assert_relative_eq!(result.x, 1450880.29f64, epsilon=1.0e-2);
14+
/// assert_relative_eq!(result.y, 1141263.01f64, epsilon=1.0e-2);
1515
/// ```
1616
impl<T: crate::proj::CoordinateType> crate::Coord<T> for geo_types::Coordinate<T> {
1717
fn x(&self) -> T {
@@ -26,7 +26,7 @@ impl<T: crate::proj::CoordinateType> crate::Coord<T> for geo_types::Coordinate<T
2626
}
2727

2828
///```rust
29-
/// # use assert_approx_eq::assert_approx_eq;
29+
/// # use approx::assert_relative_eq;
3030
/// extern crate proj;
3131
/// use proj::Proj;
3232
/// use geo_types::Point;
@@ -37,8 +37,8 @@ impl<T: crate::proj::CoordinateType> crate::Coord<T> for geo_types::Coordinate<T
3737
/// let result = nad_ft_to_m
3838
/// .convert(Point::new(4760096.421921f64, 3744293.729449f64))
3939
/// .unwrap();
40-
/// assert_approx_eq!(result.x(), 1450880.29f64, 1.0e-2);
41-
/// assert_approx_eq!(result.y(), 1141263.01f64, 1.0e-2);
40+
/// assert_relative_eq!(result.x(), 1450880.29f64, epsilon=1.0e-2);
41+
/// assert_relative_eq!(result.y(), 1141263.01f64, epsilon=1.0e-2);
4242
/// ```
4343
impl<T: crate::proj::CoordinateType> crate::Coord<T> for geo_types::Point<T> {
4444
fn x(&self) -> T {

src/lib.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
//! ## Convert from [NAD 83 US Survey Feet](https://epsg.io/2230) to [NAD 83 Meters](https://epsg.io/26946) Using EPSG Codes
3030
//!
3131
//! ```rust
32-
//! # use assert_approx_eq::assert_approx_eq;
32+
//! # use approx::assert_relative_eq;
3333
//! use proj::Proj;
3434
//!
3535
//! let from = "EPSG:2230";
@@ -38,8 +38,8 @@
3838
//! let result = ft_to_m
3939
//! .convert((4760096.421921f64, 3744293.729449f64))
4040
//! .unwrap();
41-
//! assert_approx_eq!(result.0, 1450880.2910605003);
42-
//! assert_approx_eq!(result.1, 1141263.0111604529);
41+
//! assert_relative_eq!(result.0, 1450880.29, epsilon=1e-2);
42+
//! assert_relative_eq!(result.1, 1141263.01, epsilon=1e-2);
4343
//! ```
4444
//!
4545
//! ## Convert from [NAD 83 US Survey Feet](https://epsg.io/2230) to [NAD 83 Meters](https://epsg.io/26946) Using the `pipeline` Operator
@@ -54,7 +54,7 @@
5454
//!
5555
//!
5656
//! ```rust
57-
//! # use assert_approx_eq::assert_approx_eq;
57+
//! # use approx::assert_relative_eq;
5858
//! use proj::Proj;
5959
//!
6060
//! let ft_to_m = Proj::new("
@@ -70,14 +70,14 @@
7070
//!
7171
//! // The Presidio, approximately
7272
//! let result = ft_to_m.convert((4760096.421921f64, 3744293.729449f64)).unwrap();
73-
//! assert_approx_eq!(result.0, 1450880.2910605003);
74-
//! assert_approx_eq!(result.1, 1141263.01116045);
73+
//! assert_relative_eq!(result.0, 1450880.29, epsilon=1e-2);
74+
//! assert_relative_eq!(result.1, 1141263.01, epsilon=1e-2);
7575
//! ```
7676
//!
7777
//! ## Inverse Projection from [Stereo70](https://epsg.io/3844) to Geodetic
7878
//!
7979
//! ```rust
80-
//! # use assert_approx_eq::assert_approx_eq;
80+
//! # use approx::assert_relative_eq;
8181
//! use proj::Proj;
8282
//!
8383
//! // Carry out an inverse projection from Pulkovo 1942(58) / Stereo70 (EPSG 3844)
@@ -90,8 +90,8 @@
9090
//! let geodetic_radians_point = stereo70.project(
9191
//! (500119.70352012233f64, 500027.77896348457f64), true
9292
//! ).unwrap();
93-
//! assert_approx_eq!(geodetic_radians_point.0, 0.436332);
94-
//! assert_approx_eq!(geodetic_radians_point.1, 0.802851);
93+
//! assert_relative_eq!(geodetic_radians_point.0, 0.436332, epsilon=1e-5);
94+
//! assert_relative_eq!(geodetic_radians_point.1, 0.802851, epsilon=1e-5);
9595
//! ```
9696
//!
9797
//! # Usage
@@ -160,7 +160,7 @@
160160
//! without any intermediate allocation.
161161
//!
162162
//! ```rust
163-
//! # use assert_approx_eq::assert_approx_eq;
163+
//! # use approx::assert_relative_eq;
164164
//! use proj::{Proj, Coord};
165165
//!
166166
//! struct MyPointOfIntereset {
@@ -188,8 +188,8 @@
188188
//!
189189
//! let result = proj.convert(donut_shop).unwrap();
190190
//!
191-
//! assert_approx_eq!(result.x(), 158458.67251293268);
192-
//! assert_approx_eq!(result.y(), -434296.8803996085);
191+
//! assert_relative_eq!(result.x(), 158458.67, epsilon=1e-2);
192+
//! assert_relative_eq!(result.y(), -434296.88, epsilon=1e-2);
193193
//! ```
194194
#![cfg_attr(
195195
feature = "geo-types",
@@ -200,7 +200,7 @@ If you've enabled the `geo-types` feature, you can skip allocating an intermedia
200200
and pass the [`geo-types`](https://crates.io/crates/geo-types) directly.
201201
202202
```rust
203-
# use assert_approx_eq::assert_approx_eq;
203+
# use approx::assert_relative_eq;
204204
use proj::Proj;
205205
use geo_types::Point;
206206
@@ -212,12 +212,11 @@ let nad_ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap();
212212
213213
let result = nad_ft_to_m.convert(my_point).unwrap();
214214
215-
assert_approx_eq!(result.x(), 1450880.2910605003f64);
216-
assert_approx_eq!(result.y(), 1141263.0111604529f64);
215+
assert_relative_eq!(result.x(), 1450880.29, epsilon=1e-2);
216+
assert_relative_eq!(result.y(), 1141263.01, epsilon=1e-2);
217217
```
218218
"##
219219
)]
220-
221220
#![cfg_attr(docsrs, feature(doc_cfg))]
222221

223222
#[cfg(feature = "network")]
@@ -227,6 +226,10 @@ mod network;
227226
#[cfg(feature = "geo-types")]
228227
mod geo_types;
229228

229+
#[cfg(test)]
230+
#[macro_use]
231+
extern crate approx;
232+
230233
mod proj;
231234

232235
pub use crate::proj::Area;

0 commit comments

Comments
 (0)