test: get to 100% coverage, clean up cargo features
- eliminated `f64` feature because Cargo doesn’t understand mutually exclusive features. So, we default to `f64`, and leave the `f32` feature there if people want to change to that. - integrated tarpaulin for coverage - added tests to get to 100% coverage - fixed NetworkCoordinate Div impl safety checks (now acts like Add and Sub) - update README to explain cargo feature change - cleanup build script with the new simpler features model Signed-off-by: Stephen Waits <steve@waits.net>
This commit is contained in:
8 files changed
+79
-32
No files matched your search
+41
-8
@@ -58,7 +58,7 @@ use crate::vector::{self, Vector};
|
||||
type FloatType = f32;
|
||||
|
||||
/// `FloatType` is a type alias for either `f32` or `f64` depending on cargo features
|
||||
#[cfg(feature = "f64")]
|
||||
#[cfg(not(feature = "f32"))]
|
||||
type FloatType = f64;
|
||||
|
||||
//
|
||||
@@ -122,15 +122,16 @@ impl<const N: usize> HeightVector<N> {
|
||||
/// by the inveerse of its length.
|
||||
pub(crate) fn normalized(&self) -> Self {
|
||||
let len = self.len();
|
||||
if len < FloatType::EPSILON {
|
||||
// scale it by the inverse of its magnitude like any normal vector
|
||||
let ret = Self {
|
||||
position: self.position / len,
|
||||
height: self.height / len,
|
||||
};
|
||||
if ret.is_valid() {
|
||||
ret
|
||||
} else {
|
||||
// if we have a bad vector, generate a new random vector
|
||||
Self::new()
|
||||
} else {
|
||||
// otherwise scale it by the inverse of its magnitude like any normal vector
|
||||
Self {
|
||||
position: self.position / len,
|
||||
height: self.height / len,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,4 +378,36 @@ mod tests {
|
||||
let t = serde_json::to_string(&a);
|
||||
assert_eq!(t.as_ref().unwrap(), s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sub_invalid() {
|
||||
let valid = HeightVector::<2>::from(([1.0, 2.0], 3.0));
|
||||
let mut invalid = HeightVector::<2>::from(([1.0, 2.0], 3.0));
|
||||
// force invalidity here - because `::from()` actually also catches this
|
||||
invalid.height = 1.0 / 0.0;
|
||||
let result = valid - invalid;
|
||||
assert_approx_eq!(result.len(), 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_invalid() {
|
||||
let valid = HeightVector::<2>::from(([1.0, 2.0], 3.0));
|
||||
let mut invalid = HeightVector::<2>::from(([1.0 / 0.0, 2.0], 3.0));
|
||||
|
||||
// make sure `from()` caught and replaced the invalid vec
|
||||
assert_approx_eq!(invalid.len(), 1.0);
|
||||
|
||||
// force invalidity here - because `::from()` actually also catches this
|
||||
invalid.height = 1.0 / 0.0;
|
||||
let result = valid + invalid;
|
||||
assert_approx_eq!(result.len(), 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_norm() {
|
||||
let a = HeightVector::<2>::from(([0.0, 0.0], 0.0));
|
||||
let b = a.normalized();
|
||||
let len = b.len();
|
||||
assert_approx_eq!(len, 1.0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user