Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up lint in tests #76

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- uses: actions/checkout@v3
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo clippy -- --deny warnings
- run: cargo clippy --tests -- --deny warnings
- run: cargo fmt --check
- run: cargo build --verbose
- run: cargo test --verbose
9 changes: 5 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ default: list
list:
just -l

# Basic test: Just library unit tests. Use target "test-all" or "check" for successively more in depth check ups.
# Basic test: Just library unit tests. Use target "test-all", "check" or "clean-check" for successively more in depth check ups.
test:
cargo test --lib

# Unit tests, doc tests, pile test, and compiling of examples
# Unit tests, doc tests, and compiling of examples
test-all:
cargo test
cargo test --all

# Check that all tests pass, and that formatting and coding conventions are OK.
check:
cargo clippy
cargo clippy -- --deny warnings
cargo clippy --tests -- --deny warnings
cargo fmt -- --check
cargo test
cargo doc --all-features --no-deps
Expand Down
2 changes: 1 addition & 1 deletion src/context/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ mod tests {
assert!(ctx.get_resource("stupid:way_three")?.starts_with("addone"));

// And just to be sure: once again for the plain resource file
assert!(ctx.get_resource("stupid:way")?.starts_with("#"));
assert!(ctx.get_resource("stupid:way")?.starts_with('#'));
assert!(ctx.get_resource("stupid:way")?.ends_with("addone"));

// Now make sure, we can actually also *instantiate* a recipe
Expand Down
4 changes: 2 additions & 2 deletions src/coordinate/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ mod tests {
fn array() {
let mut operands = some_basic_coor4dinates();
assert_eq!(operands.len(), 2);
assert_eq!(operands.is_empty(), false);
assert!(!operands.is_empty());

let cph = operands.get_coord(0);
assert_eq!(cph[0], 55.);
Expand All @@ -301,7 +301,7 @@ mod tests {
fn vector() {
let mut operands = Vec::from(some_basic_coor4dinates());
assert_eq!(operands.len(), 2);
assert_eq!(operands.is_empty(), false);
assert!(!operands.is_empty());

let cph = operands.get_coord(0);
assert_eq!(cph[0], 55.);
Expand Down
17 changes: 11 additions & 6 deletions src/ellipsoid/latitudes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {
let ellps = Ellipsoid::named("GRS80")?;
let lats = Vec::from([35., 45., 55.]);
for lat in &lats {
let lat = *lat as f64;
let lat: f64 = *lat;
let theta = ellps.latitude_geographic_to_geocentric(lat.to_radians());
let roundtrip = ellps.latitude_geocentric_to_geographic(theta).to_degrees();
assert!((lat - roundtrip).abs() < 1e-14);
Expand Down Expand Up @@ -195,9 +195,10 @@ mod tests {
#[test]
fn rectifying() -> Result<(), Error> {
let ellps = Ellipsoid::named("GRS80")?;
let latitudes = vec![35., 45., 55., -35., -45., -55., 0., 90.];
let latitudes = [35., 45., 55., -35., -45., -55., 0., 90.];
let coefficients = ellps.coefficients_for_rectifying_latitude_computations();
// Roundtrip 𝜙 -> 𝜇 -> 𝜙
#[allow(clippy::unnecessary_cast)]
for phi in latitudes {
let lat = (phi as f64).to_radians();
let mu = ellps.latitude_geographic_to_rectifying(lat, &coefficients);
Expand All @@ -213,9 +214,10 @@ mod tests {
#[test]
fn conformal() -> Result<(), Error> {
let ellps = Ellipsoid::named("GRS80")?;
let latitudes = vec![35., 45., 55., -35., -45., -55., 0., 90.];
let latitudes = [35., 45., 55., -35., -45., -55., 0., 90.];
#[rustfmt::skip]
let conformal_latitudes = vec![
#[allow(clippy::excessive_precision)]
let conformal_latitudes = [
34.819454814955349775, 44.807684055145067248, 54.819109023689023275, // Northern hemisphere
-34.819454814955349775, -44.807684055145067248, -54.819109023689023275, // Symmetry wrt. the Equator
0., 90., // Extreme values are invariant
Expand All @@ -224,6 +226,7 @@ mod tests {
let chi_coefs = ellps.latitude_fourier_coefficients(&constants::CONFORMAL);
let pairs = latitudes.iter().zip(conformal_latitudes.iter());

#[allow(clippy::unnecessary_cast)]
for pair in pairs {
// The casts are necessary, at least as of Rust 1.66
let phi = (*(pair.0) as f64).to_radians();
Expand All @@ -235,7 +238,7 @@ mod tests {
let lat = 55_f64.to_radians();
let chi = ellps.latitude_geographic_to_conformal(lat, &chi_coefs);
let phi = ellps.latitude_conformal_to_geographic(chi, &chi_coefs);
assert!((chi.to_degrees() - 54.819109023689023275).abs() < 1e-12);
assert!((chi.to_degrees() - 54.819_109_023_689_02).abs() < 1e-12);
assert_eq!(phi.to_degrees(), 55.0);
Ok(())
}
Expand Down Expand Up @@ -264,8 +267,9 @@ mod tests {

let pairs = geographic_latitudes.iter().zip(authalic_latitudes.iter());

#[allow(clippy::unnecessary_cast)]
for pair in pairs.clone() {
// These casts to f64 are necessary, at least as of Rust 1.66. It appears that the 'Chalk'
// These casts to f64 are necessary, at least as of Rust 1.66..1.73. It appears that the 'Chalk'
// trait checker used in Rust-Analyzer has this correctly, so perhaps the need for these
// casts may be eliminated in a later Rust version
let phi = (*(pair.0) as f64).to_radians();
Expand All @@ -287,6 +291,7 @@ mod tests {
// Despite the name "authlat", the PROJ implementation appears to go from
// authalic to geographic latitudes.
let proj_coefs = authset(ellps.eccentricity_squared());
#[allow(clippy::unnecessary_cast)]
for pair in pairs {
let phi = (*(pair.0) as f64).to_radians();
let xi = (*(pair.1) as f64).to_radians();
Expand Down
24 changes: 13 additions & 11 deletions src/ellipsoid/meridians.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,21 @@ mod tests {

// Meridional distances for angles 0, 10, 20, 30 ... 90, obtained from Charles Karney's
// online geodesic solver, https://geographiclib.sourceforge.io/cgi-bin/GeodSolve
#[allow(clippy::excessive_precision)]
let s = [
0_000_000.000000000,
1_105_854.833198446,
2_212_366.254102976,
3_320_113.397845014,
4_429_529.030236580,
5_540_847.041560960,
6_654_072.819367435,
7_768_980.727655508,
8_885_139.871836751,
10_001_965.729230457,
0_000_000.000_000_000,
1_105_854.833_198_446,
2_212_366.254_102_976,
3_320_113.397_845_014,
4_429_529.030_236_580,
5_540_847.041_560_960,
6_654_072.819_367_435,
7_768_980.727_655_508,
8_885_139.871_836_751,
10_001_965.729_230_457,
];

#[allow(clippy::needless_range_loop)]
for i in 0..s.len() {
let angle = (10.0 * i as f64).to_radians();
assert!((ellps.meridian_latitude_to_distance(angle) - s[i]).abs() < 6e-6);
Expand All @@ -188,7 +190,7 @@ mod tests {

// Since we suspect the deviation might be worst at 45°, we check that as well
let angle = 45f64.to_radians();
let length = 4984944.377857987;
let length = 4_984_944.377_857_987;
assert!((ellps.meridian_latitude_to_distance(angle) - length).abs() < 4e-6);
assert!((ellps.meridian_distance_to_latitude(length) - angle).abs() < 4e-6);
Ok(())
Expand Down
24 changes: 12 additions & 12 deletions src/ellipsoid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ mod tests {

let ellps = Ellipsoid::named("GRS80")?;
assert_eq!(ellps.semimajor_axis(), 6378137.0);
assert_eq!(ellps.flattening(), 1. / 298.25722_21008_82711_24316);
assert_eq!(ellps.flattening(), 1. / 298.257_222_100_882_7);

assert!((ellps.normalized_meridian_arc_unit() - 0.9983242984230415).abs() < 1e-13);
assert!((4.0 * ellps.meridian_quadrant() - 40007862.9169218).abs() < 1e-7);
assert!((ellps.normalized_meridian_arc_unit() - 0.998_324_298_423_041_5).abs() < 1e-13);
assert!((4.0 * ellps.meridian_quadrant() - 40_007_862.916_921_8).abs() < 1e-7);
Ok(())
}

Expand All @@ -215,11 +215,11 @@ mod tests {
let ellps = Ellipsoid::new(ellps.semimajor_axis(), ellps.flattening());
let ellps = Ellipsoid::triaxial(ellps.a, ellps.a - 1., ellps.f);
assert_eq!(ellps.semimajor_axis(), 6378137.0);
assert_eq!(ellps.flattening(), 1. / 298.25722_21008_82711_24316);
assert_eq!(ellps.flattening(), 1. / 298.257_222_100_882_7);

// Additional shape descriptors
assert!((ellps.eccentricity() - 0.081819191).abs() < 1.0e-10);
assert!((ellps.eccentricity_squared() - 0.00669_43800_22903_41574).abs() < 1.0e-10);
assert!((ellps.eccentricity_squared() - 0.006_694_380_022_903_416).abs() < 1.0e-10);

// Additional size descriptors
assert!((ellps.semiminor_axis() - 6_356_752.31414_0347).abs() < 1e-9);
Expand All @@ -245,10 +245,11 @@ mod tests {
let ellps = Ellipsoid::named("GRS80")?;
// The curvatures at the North Pole
assert!(
(ellps.meridian_radius_of_curvature(90_f64.to_radians()) - 6_399_593.6259).abs() < 1e-4
(ellps.meridian_radius_of_curvature(90_f64.to_radians()) - 6_399_593.625_9).abs()
< 1e-4
);
assert!(
(ellps.prime_vertical_radius_of_curvature(90_f64.to_radians()) - 6_399_593.6259).abs()
(ellps.prime_vertical_radius_of_curvature(90_f64.to_radians()) - 6_399_593.625_9).abs()
< 1e-4
);
assert!(
Expand All @@ -265,7 +266,7 @@ mod tests {
);

// The curvatures at the Equator
assert!((ellps.meridian_radius_of_curvature(0.0) - 6_335_439.3271).abs() < 1.0e-4);
assert!((ellps.meridian_radius_of_curvature(0.0) - 6_335_439.327_1).abs() < 1.0e-4);
assert!(
(ellps.prime_vertical_radius_of_curvature(0.0) - ellps.semimajor_axis()).abs() < 1.0e-4
);
Expand All @@ -274,6 +275,8 @@ mod tests {
let latitudes = [
50f64, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0,
];

#[allow(clippy::excessive_precision)]
let prime_vertical_radii_of_curvature = [
6390702.044256360,
6391069.984921544,
Expand All @@ -288,6 +291,7 @@ mod tests {
6394209.173926849,
];

#[allow(clippy::excessive_precision)]
let meridian_radii_of_curvature = [
6372955.9257095090,
6374056.7459167000,
Expand All @@ -301,16 +305,12 @@ mod tests {
6382470.6113096075,
6383453.8572549970,
];
// println!("lat; N; M; R");

for (i, lat) in latitudes.iter().enumerate() {
let n = ellps.prime_vertical_radius_of_curvature(lat.to_radians());
let m = ellps.meridian_radius_of_curvature(lat.to_radians());
// let r = (n*m).sqrt();
assert!((n - prime_vertical_radii_of_curvature[i]).abs() < 1e-9);
assert!((m - meridian_radii_of_curvature[i]).abs() < 1e-9);

// println!("{lat}; {n}; {m}; {r}");
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/grid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ mod tests {
// Interpolation
let c = Coor4D::geo(55.06, 12.03, 0., 0.);
// Check that we're not extrapolating
assert_eq!(datum.contains(&c, 0.0), true);
assert!(datum.contains(&c, 0.0));
// ...with output converted back to arcsec
let d = datum.at(&c, 0.0).unwrap().to_arcsec();
// We can do slightly better for interpolation than for extrapolation,
Expand All @@ -391,8 +391,8 @@ mod tests {
let geoid = BaseGrid::plain(&geoid_header, Some(&geoid_grid), None)?;

let c = Coor4D::geo(58.75, 08.25, 0., 0.);
assert_eq!(geoid.contains(&c, 0.0), false);
assert_eq!(geoid.contains(&c, 1.0), true);
assert!(!geoid.contains(&c, 0.0));
assert!(geoid.contains(&c, 1.0));

let n = geoid.at(&c, 1.0).unwrap();
assert!((n[0] - (58.75 + 0.0825)).abs() < 0.0001);
Expand Down
2 changes: 1 addition & 1 deletion src/grid/ntv2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ mod tests {
let ntv2_grid = Ntv2Grid::new(&grid_buff)?;

assert!(ntv2_grid.subgrids.len() == 2);
assert!(ntv2_grid.lookup_table.get("NONE").unwrap().len() > 0);
assert!(!ntv2_grid.lookup_table.get("NONE").unwrap().is_empty());
assert!(ntv2_grid
.lookup_table
.get("NONE")
Expand Down
12 changes: 6 additions & 6 deletions src/inner_op/adapt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ mod tests {
assert_eq!([-1., 1., -1., 1.], descriptor("sedf_any").unwrap().mult);

// noop
assert_eq!(false, descriptor("sedf_any").unwrap().noop);
assert_eq!(true, descriptor("enuf_any").unwrap().noop);
assert_eq!(true, descriptor("enuf_rad").unwrap().noop);
assert_eq!(true, descriptor("enuf").unwrap().noop);
assert_eq!(true, descriptor("pass").unwrap().noop);
assert!(!descriptor("sedf_any").unwrap().noop);
assert!(descriptor("enuf_any").unwrap().noop);
assert!(descriptor("enuf_rad").unwrap().noop);
assert!(descriptor("enuf").unwrap().noop);
assert!(descriptor("pass").unwrap().noop);

// Invalid angular unit "pap"
assert!(descriptor("sedf_pap").is_none());
Expand All @@ -322,7 +322,7 @@ mod tests {
assert!(give.mult[1] - 400. / 360. < 1e-10); // mult[1] is positive for northish
assert!(give.mult[2] + 1.0 < 1e-10); // mult[2] is negative for downish
assert!(give.mult[3] - 1.0 < 1e-10); // mult[3] is positive for timeish
assert!(give.noop == false);
assert!(!give.noop);
}

// Test the basic adapt functionality
Expand Down
6 changes: 3 additions & 3 deletions src/inner_op/btmerc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod tests {
Coor4D::raw(-455_673.814_189_040,-6_198_246.671_090_279, 0., 0.)
];

let mut operands = geo.clone();
let mut operands = geo;
ctx.apply(op, Fwd, &mut operands)?;
for i in 0..operands.len() {
assert!(operands[i].hypot2(&projected[i]) < 5e-3);
Expand Down Expand Up @@ -231,7 +231,7 @@ mod tests {
Coor4D::raw(-455_673.814_189_040,-6_198_246.671_090_279, 0., 0.)
];

let mut operands = geo.clone();
let mut operands = geo;
ctx.apply(op, Fwd, &mut operands)?;
for i in 0..operands.len() {
assert!(operands[i].hypot2(&projected[i]) < 5e-3);
Expand Down Expand Up @@ -265,7 +265,7 @@ mod tests {
Coor4D::raw(-455_673.814_189_040, 1e7-6_198_246.671_090_279, 0., 0.)
];

let mut operands = geo.clone();
let mut operands = geo;
ctx.apply(op, Fwd, &mut operands)?;
for i in 0..operands.len() {
assert!(operands[i].hypot2(&projected[i]) < 5e-3);
Expand Down
36 changes: 18 additions & 18 deletions src/inner_op/cart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,42 +135,42 @@ mod tests {
];

let cart = [
Coor4D::raw(566462.633537476765923, 0.0, 6432020.33369012735784, 0.0),
Coor4D::raw(566_462.633_537_476_8, 0.0, 6_432_020.333_690_127, 0.0),
Coor4D::raw(
3554403.47587193036451,
626737.23312017065473,
5119468.31865925621241,
3_554_403.475_871_930_4,
626_737.233_120_170_7,
5_119_468.318_659_256,
0.,
),
Coor4D::raw(
5435195.38214521575719,
1978249.33652197546325,
2679074.46287727775052,
5_435_195.382_145_216,
1_978_249.336_521_975_5,
2_679_074.462_877_277_8,
0.,
),
Coor4D::raw(5993488.27326157130301, -2181451.33089075051248, 0., 0.),
Coor4D::raw(5_993_488.273_261_571, -2_181_451.330_890_750_5, 0., 0.),
Coor4D::raw(
5435203.89865261223167,
1978252.43627716740593,
-2679078.68905989499763,
5_435_203.898_652_612,
1_978_252.436_277_167_4,
-2_679_078.689_059_895,
0.,
),
Coor4D::raw(
5435203.89865261223167,
-1978252.43627716740593,
-2679078.68905989499763,
5_435_203.898_652_612,
-1_978_252.436_277_167_4,
-2_679_078.689_059_895,
0.,
),
Coor4D::raw(
5435203.89865261223167,
-1978252.43627716740593,
2679078.68905989499763,
5_435_203.898_652_612,
-1_978_252.436_277_167_4,
2_679_078.689_059_895,
0.,
),
];

// Forward
let mut operands = geo.clone();
let mut operands = geo;
ctx.apply(op, Fwd, &mut operands)?;
for i in 0..4 {
assert!(operands[i].hypot3(&cart[i]) < 20e-9);
Expand Down
Loading