Skip to content

Commit

Permalink
test: Roundtrip z_from_p x p_from_z
Browse files Browse the repository at this point in the history
Confirm that there is an issue with dynamic height and geopotential
extra arguments. Fix in the following PR.
  • Loading branch information
castelao committed Jul 12, 2024
1 parent 9dceb83 commit 944f146
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,39 @@ pub fn z_from_p(
-2.0 * c / (b + libm::sqrt(b * b - 4.0 * a * c))
}

#[cfg(test)]
mod test_z_from_p {
use super::{p_from_z, z_from_p};

#[test]
fn surface() {
assert!((0.0 - z_from_p(0.0, 33.3482, 0.0, 0.0)).abs() < f64::EPSILON);
// assert_eq!(-6010.85496, z_from_p(6131.0, 11.0, 0.0, 0.0));
}

#[test]
fn roundtrip() {
let p1 = 6131.0;
let lat = 11.0;
let p2 = p_from_z(z_from_p(p1, lat, 0.0, 0.0), lat, Some(0.0), Some(0.0)).unwrap();
// Precision defined by (McDougall and Wotherspoon, 2013)
assert!((p1 - p2).abs() <= 1.6e-10);
}

#[test]
fn roundtrip_with_extras() {
let p1 = 6131.0;
let lat = 11.0;
for dh in [0.0, 1.0] {
for gp in [0.0, 1.0] {
let p2 = p_from_z(z_from_p(p1, lat, dh, gp), lat, Some(dh), Some(gp)).unwrap();
// Precision defined by (McDougall and Wotherspoon, 2013)
assert!((p1 - p2).abs() <= 1.6e-10);
}
}
}
}

/// Pressure from height (75-term polynomial approximation)
///
/// # Arguments
Expand Down Expand Up @@ -511,7 +544,7 @@ gsw_ionic_strength_from_SA

#[cfg(test)]
mod tests {
use super::{t90_from_t68, z_from_p};
use super::t90_from_t68;

#[test]
fn test_t90_from_t68() {
Expand All @@ -522,10 +555,4 @@ mod tests {
assert!((10.0 - t90_from_t68(10.0024)).abs() < f64::EPSILON);
}
}

#[test]
fn test_z_from_p() {
assert!((0.0 - z_from_p(0.0, 33.3482, 0.0, 0.0)).abs() < f64::EPSILON);
// assert_eq!(-6010.85496, z_from_p(6131.0, 11.0, 0.0, 0.0));
}
}

0 comments on commit 944f146

Please sign in to comment.