Skip to content

Commit 8a3e4d1

Browse files
committed
simplify x_x_than_single checks from 4 to 3
1 parent 2d863a2 commit 8a3e4d1

6 files changed

+132
-209
lines changed

src/checks/consistency.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
mod greater_than;
22
pub use greater_than::greater_than;
33

4-
mod min_greater_than_single;
5-
pub use min_greater_than_single::min_greater_than_single;
4+
mod single_greater_than_min;
5+
pub use single_greater_than_min::single_greater_than_min;
66

7-
mod max_greater_than_single;
8-
pub use max_greater_than_single::max_greater_than_single;
7+
mod single_less_than_max;
8+
pub use single_less_than_max::single_less_than_max;
99

10-
mod min_less_than_single;
11-
pub use min_less_than_single::min_less_than_single;
12-
13-
mod max_less_than_single;
14-
pub use max_less_than_single::max_less_than_single;
10+
mod single_outside_sequence;
11+
pub use single_outside_sequence::single_outside_sequence;
1512

1613
mod not_equal;
1714
pub use not_equal::not_equal;

src/checks/consistency/max_greater_than_single.rs

-84
This file was deleted.

src/checks/consistency/min_less_than_single.rs

-84
This file was deleted.

src/checks/consistency/min_greater_than_single.rs src/checks/consistency/single_greater_than_min.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use crate::Flag;
22

3-
/// Compares a single value to a higher resolution sequence, where the minimum value in the
4-
/// sequence (including an adjustment) should never be greater than the single value
3+
/// Compares a single value to a higher resolution sequence, where the single value should never
4+
/// be greater than the minimum value in the sequence (including an adjustment)
55
///
66
/// Returns:
77
/// - [`Flag::DataMissing`] if the single value is missing,
8-
/// - [`Flag::Fail`] if this invariant is broken (i.e the minimum of the sequence, plus the
9-
/// adjustment, is greater than the single value),
8+
/// - [`Flag::Fail`] if this invariant is broken (i.e the single value is greater than the minimum
9+
/// of the sequence plus the adjustment),
1010
/// - [`Flag::DataMissing`] if any of the elements is missing, as we cannot be sure a missing data
1111
/// point did not violate the invariant.
1212
/// - [`Flag::Pass`] otherwise.
13-
pub fn min_greater_than_single(
13+
pub fn single_greater_than_min(
1414
single: Option<f32>,
1515
sequence: &[Option<f32>],
1616
adjustment: f32,
@@ -46,12 +46,12 @@ pub fn min_greater_than_single(
4646
}
4747
};
4848

49-
if min + adjustment > single {
49+
if single > min + adjustment {
5050
// if this condition evaluates to true, the invariant was invalidated
5151
Flag::Fail
5252
} else if missing {
5353
// if the condition was not met, but there was missing data in the sequence, we cannot say
54-
// for sure that the invariant wasn't validated
54+
// for sure that the invariant wasn't invalidated
5555
Flag::DataMissing
5656
} else {
5757
Flag::Pass
@@ -63,22 +63,22 @@ mod tests {
6363
use super::*;
6464

6565
#[test]
66-
fn test_min_greater_than_single() {
66+
fn test_single_greater_than_min() {
6767
assert_eq!(
68-
min_greater_than_single(Some(1.), &[Some(1.), Some(2.), Some(2.)], 0.2),
69-
Flag::Fail
70-
);
71-
assert_eq!(
72-
min_greater_than_single(Some(1.), &[Some(1.), Some(2.), Some(2.)], -0.2),
68+
single_greater_than_min(Some(1.), &[Some(1.), Some(2.), Some(2.)], 0.2),
7369
Flag::Pass
7470
);
7571
assert_eq!(
76-
min_greater_than_single(Some(1.), &[Some(1.), None, Some(2.)], -0.2),
77-
Flag::DataMissing
72+
single_greater_than_min(Some(1.), &[Some(1.), Some(2.), Some(2.)], -0.2),
73+
Flag::Fail
7874
);
7975
assert_eq!(
80-
min_greater_than_single(Some(1.), &[Some(1.), None, Some(2.)], 0.2),
76+
single_greater_than_min(Some(1.), &[Some(1.), None, Some(2.)], -0.2),
8177
Flag::Fail
8278
);
79+
assert_eq!(
80+
single_greater_than_min(Some(1.), &[Some(1.), None, Some(2.)], 0.2),
81+
Flag::DataMissing
82+
);
8383
}
8484
}

src/checks/consistency/max_less_than_single.rs src/checks/consistency/single_less_than_max.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use crate::Flag;
22

3-
/// Compares a single value to a higher resolution sequence, where the maximum value in the
4-
/// sequence (including an adjustment) should never be less than the single value
3+
/// Compares a single value to a higher resolution sequence, where the single value should never
4+
/// be less than the maximum value in the sequence (including an adjustment)
55
///
66
/// Returns:
77
/// - [`Flag::DataMissing`] if the single value is missing,
8-
/// - [`Flag::Fail`] if this invariant is broken (i.e the maximum of the sequence, plus the
9-
/// adjustment, is less than the single value),
8+
/// - [`Flag::Fail`] if this invariant is broken (i.e the single value is less than the maximum
9+
/// of the sequence plus the adjustment),
1010
/// - [`Flag::DataMissing`] if any of the elements is missing, as we cannot be sure a missing data
1111
/// point did not violate the invariant.
1212
/// - [`Flag::Pass`] otherwise.
13-
pub fn max_less_than_single(
13+
pub fn single_less_than_max(
1414
single: Option<f32>,
1515
sequence: &[Option<f32>],
1616
adjustment: f32,
@@ -46,12 +46,12 @@ pub fn max_less_than_single(
4646
}
4747
};
4848

49-
if max + adjustment < single {
49+
if single < max + adjustment {
5050
// if this condition evaluates to true, the invariant was invalidated
5151
Flag::Fail
5252
} else if missing {
5353
// if the condition was not met, but there was missing data in the sequence, we cannot say
54-
// for sure that the invariant wasn't validated
54+
// for sure that the invariant wasn't invalidated
5555
Flag::DataMissing
5656
} else {
5757
Flag::Pass
@@ -63,22 +63,22 @@ mod tests {
6363
use super::*;
6464

6565
#[test]
66-
fn test_max_less_than_single() {
66+
fn test_single_less_than_max() {
6767
assert_eq!(
68-
max_less_than_single(Some(1.), &[Some(1.), Some(0.), Some(0.)], 0.2),
69-
Flag::Pass
70-
);
71-
assert_eq!(
72-
max_less_than_single(Some(1.), &[Some(1.), Some(0.), Some(0.)], -0.2),
68+
single_less_than_max(Some(1.), &[Some(1.), Some(0.), Some(0.)], 0.2),
7369
Flag::Fail
7470
);
7571
assert_eq!(
76-
max_less_than_single(Some(1.), &[Some(1.), None, Some(0.)], -0.2),
77-
Flag::Fail
72+
single_less_than_max(Some(1.), &[Some(1.), Some(0.), Some(0.)], -0.2),
73+
Flag::Pass
7874
);
7975
assert_eq!(
80-
max_less_than_single(Some(1.), &[Some(1.), None, Some(0.)], 0.2),
76+
single_less_than_max(Some(1.), &[Some(1.), None, Some(0.)], -0.2),
8177
Flag::DataMissing
8278
);
79+
assert_eq!(
80+
single_less_than_max(Some(1.), &[Some(1.), None, Some(0.)], 0.2),
81+
Flag::Fail
82+
);
8383
}
8484
}

0 commit comments

Comments
 (0)