Skip to content

Commit 8496277

Browse files
committed
implement not_equal
1 parent 8bb045a commit 8496277

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/checks/consistency.rs

+3
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ pub use min_less_than_single::min_less_than_single;
1313
mod max_less_than_single;
1414
pub use max_less_than_single::max_less_than_single;
1515

16+
mod not_equal;
17+
pub use not_equal::not_equal;
18+
1619
// TODO: Figure out the ideal container type (Analogous to [`crate::DataCache`]) to pass large
1720
// amounts of data into consistency checks

src/checks/consistency/not_equal.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::Flag;
2+
3+
/// Consistency check between 2 climate parameters, where both should be within a threshold of
4+
/// each other.
5+
///
6+
/// Useful for comparing observations against model data, or comparing two instruments measuring
7+
/// the same climate parameter at the same site.
8+
///
9+
/// Returns [`Flag::DataMissing`] if either datum is missing,
10+
/// [`Flag::Fail`] if the difference between datum1 and datum2 is greater than threshold,
11+
/// [`Flag::Pass`] otherwise.
12+
pub fn not_equal(datum1: Option<f32>, datum2: Option<f32>, threshold: f32) -> Flag {
13+
if datum1.is_none() || datum2.is_none() {
14+
return Flag::DataMissing;
15+
}
16+
17+
if (datum1.unwrap() - datum2.unwrap()).abs() > threshold {
18+
Flag::Fail
19+
} else {
20+
Flag::Pass
21+
}
22+
}
23+
24+
#[cfg(test)]
25+
mod tests {
26+
use super::*;
27+
28+
#[test]
29+
fn test_not_equal() {
30+
assert_eq!(not_equal(Some(1.), Some(1.1), 0.2), Flag::Pass);
31+
assert_eq!(not_equal(Some(1.), Some(1.2), 0.1), Flag::Fail);
32+
assert_eq!(not_equal(Some(1.), None, 0.1), Flag::DataMissing);
33+
}
34+
}

0 commit comments

Comments
 (0)