add some coverage

This commit is contained in:
Trevor Spiteri 2020-04-17 22:11:57 +02:00
parent 8d8fde75c5
commit f8f9bd69ba
4 changed files with 129 additions and 11 deletions

View File

@ -47,11 +47,11 @@ x86_64-gnulinux:
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings serde"
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings std"
- cargo +beta-$TARGET check --all-targets --features fail-on-warnings
- cargo +beta-$TARGET test --features "fail-on-warnings az f16 serde"
- cargo +beta-$TARGET test --release --features "fail-on-warnings az f16 serde"
- cargo +beta-$TARGET test --features "fail-on-warnings az f16 serde std"
- cargo +beta-$TARGET test --release --features "fail-on-warnings az f16 serde std"
- cargo +beta-$TARGET fmt -- --check
- cargo +1.39.0-$TARGET test --lib --features "fail-on-warnings az f16 serde"
- cargo +1.39.0-$TARGET test --release --lib --features "fail-on-warnings az f16 serde"
- cargo +1.39.0-$TARGET test --lib --features "fail-on-warnings az f16 serde std"
- cargo +1.39.0-$TARGET test --release --lib --features "fail-on-warnings az f16 serde std"
i686-gnulinux:
image: i386/rust:1
@ -80,15 +80,15 @@ i686-gnulinux:
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings std"
- cargo +beta-$TARGET check --all-targets --features fail-on-warnings
- cargo +beta-$TARGET test --features "fail-on-warnings f16 serde"
- cargo +beta-$TARGET test --release --features "fail-on-warnings az f16 serde"
- cargo +beta-$TARGET test --release --features "fail-on-warnings az f16 serde std"
- cargo +beta-$TARGET fmt -- --check
- cargo +1.39.0-$TARGET test --lib --features "fail-on-warnings az f16 serde"
- cargo +1.39.0-$TARGET test --release --lib --features "fail-on-warnings az f16 serde"
- cargo +1.39.0-$TARGET test --lib --features "fail-on-warnings az f16 serde std"
- cargo +1.39.0-$TARGET test --release --lib --features "fail-on-warnings az f16 serde std"
x86_64-gnulinux-tarpaulin:
image: amd64/rust:1
variables:
REQ_COVERAGE: "85.5"
REQ_COVERAGE: "86.2"
cache:
key: $CI_JOB_NAME
paths:
@ -97,7 +97,7 @@ x86_64-gnulinux-tarpaulin:
- if [ -d cargo/registry/cache ]; then rm -rf $CARGO_HOME/registry/cache; mkdir -p $CARGO_HOME/registry; cp -R cargo/registry/cache $CARGO_HOME/registry/; echo Copied registry/cache; fi
- if [ -d $CARGO_HOME/registry/cache ]; then (cd $CARGO_HOME/registry; find cache -name \*.crate) fi
- cargo install --version 0.12.3 --locked cargo-tarpaulin
- stdbuf -oL cargo tarpaulin -v --ignore-tests --exclude-files build.rs | tee tarpaulin.log
- stdbuf -oL cargo tarpaulin -v --ignore-tests --exclude-files build.rs --features "az f16 serde std" | tee tarpaulin.log
- echo "Check that coverage not less than $REQ_COVERAGE%"
- tail -1 tarpaulin.log | awk '{ if ($1 < '$REQ_COVERAGE') { exit 1 } }'
- if [ -d $CARGO_HOME/registry/cache ]; then (cd $CARGO_HOME/registry; find cache -name \*.crate) fi

View File

@ -410,6 +410,7 @@ fixed_cmp! { FixedI128(i128, LeEqU128, 128) }
#[allow(clippy::cognitive_complexity, clippy::float_cmp)]
mod tests {
use crate::*;
use core::f32;
#[test]
fn cmp_signed() {
@ -431,6 +432,11 @@ mod tests {
assert_eq!(a.partial_cmp(&b), Some(Equal));
assert_eq!(b.partial_cmp(&a), Some(Equal));
assert!(a < 0.0);
assert_eq!(a.partial_cmp(&f32::INFINITY), Some(Less));
assert!(a < f32::INFINITY);
assert!(a != f32::INFINITY);
assert_eq!(a.partial_cmp(&f32::NEG_INFINITY), Some(Greater));
assert!(a > f32::NEG_INFINITY);
assert_eq!(a, -(-16f32).exp2());
assert!(a <= -(-16f32).exp2());
assert!(a >= -(-16f32).exp2());
@ -484,6 +490,11 @@ mod tests {
assert_eq!(a.partial_cmp(&b), Some(Equal));
assert_eq!(b.partial_cmp(&a), Some(Equal));
assert!(a > 0.0);
assert_eq!(a.partial_cmp(&f32::INFINITY), Some(Less));
assert!(a < f32::INFINITY);
assert!(a != f32::INFINITY);
assert_eq!(a.partial_cmp(&f32::NEG_INFINITY), Some(Greater));
assert!(a > f32::NEG_INFINITY);
assert_eq!(a, (-16f64).exp2());
assert!(a <= (-16f64).exp2());
assert!(a >= (-16f64).exp2());
@ -519,7 +530,7 @@ mod tests {
}
#[test]
fn cmp_i0_with_half() {
fn cmp_i0() {
use crate::types::*;
assert_eq!(I0F32::checked_from_num(0.5), None);
for &float in &[-0.5, -0.25, 0., 0.25, 0.49] {
@ -580,6 +591,82 @@ mod tests {
half.partial_cmp(&fixed),
fixed.partial_cmp(&half).map(Ordering::reverse)
);
let m1 = I1F31::from_num(-1.0);
assert_eq!(fixed < m1, float < -1.0, "{} < {}", fixed, m1);
assert_eq!(fixed == m1, float == -1.0, "{} == {}", fixed, m1);
assert_eq!(fixed > m1, float > -1.0, "{} > {}", fixed, m1);
assert_eq!(
fixed.partial_cmp(&m1),
float.partial_cmp(&-1.0),
"{}.partial_cmp(&{})",
fixed,
m1
);
assert_eq!(m1 < fixed, fixed > m1);
assert_eq!(m1 == fixed, fixed == m1);
assert_eq!(m1 > fixed, fixed < m1);
assert_eq!(
m1.partial_cmp(&fixed),
fixed.partial_cmp(&m1).map(Ordering::reverse)
);
let m1 = -1.0f32;
assert_eq!(fixed < m1, float < -1.0, "{} < {}", fixed, m1);
assert_eq!(fixed == m1, float == -1.0, "{} == {}", fixed, m1);
assert_eq!(fixed > m1, float > -1.0, "{} > {}", fixed, m1);
assert_eq!(
fixed.partial_cmp(&m1),
float.partial_cmp(&-1.0),
"{}.partial_cmp(&{})",
fixed,
m1
);
assert_eq!(m1 < fixed, fixed > m1);
assert_eq!(m1 == fixed, fixed == m1);
assert_eq!(m1 > fixed, fixed < m1);
assert_eq!(
m1.partial_cmp(&fixed),
fixed.partial_cmp(&m1).map(Ordering::reverse)
);
let mhalf = I1F31::from_num(-0.5);
assert_eq!(fixed < mhalf, float < -0.5, "{} < {}", fixed, mhalf);
assert_eq!(fixed == mhalf, float == -0.5, "{} == {}", fixed, mhalf);
assert_eq!(fixed > mhalf, float > -0.5, "{} > {}", fixed, mhalf);
assert_eq!(
fixed.partial_cmp(&mhalf),
float.partial_cmp(&-0.5),
"{}.partial_cmp(&{})",
fixed,
mhalf
);
assert_eq!(mhalf < fixed, fixed > mhalf);
assert_eq!(mhalf == fixed, fixed == mhalf);
assert_eq!(mhalf > fixed, fixed < mhalf);
assert_eq!(
mhalf.partial_cmp(&fixed),
fixed.partial_cmp(&mhalf).map(Ordering::reverse)
);
let mhalf = -0.5f32;
assert_eq!(fixed < mhalf, float < -0.5, "{} < {}", fixed, mhalf);
assert_eq!(fixed == mhalf, float == -0.5, "{} == {}", fixed, mhalf);
assert_eq!(fixed > mhalf, float > -0.5, "{} > {}", fixed, mhalf);
assert_eq!(
fixed.partial_cmp(&mhalf),
float.partial_cmp(&-0.5),
"{}.partial_cmp(&{})",
fixed,
mhalf
);
assert_eq!(mhalf < fixed, fixed > mhalf);
assert_eq!(mhalf == fixed, fixed == mhalf);
assert_eq!(mhalf > fixed, fixed < mhalf);
assert_eq!(
mhalf.partial_cmp(&fixed),
fixed.partial_cmp(&mhalf).map(Ordering::reverse)
);
}
}
}

View File

@ -1530,4 +1530,35 @@ mod tests {
);
assert_eq!(bf16::lossy_from((-133f32).exp2() * 0.5), bf16::from_bits(0));
}
#[test]
fn keep_nothing() {
assert_eq!(I32F0::from_num(I0F32::MIN), -1);
assert_eq!(I32F0::from_num(I0F32::MAX), 0);
assert_eq!(I32F0::from_num(U0F32::MIN), 0);
assert_eq!(I32F0::from_num(U0F32::MAX), 0);
assert_eq!(U32F0::checked_from_num(I0F32::MIN), None);
assert_eq!(U32F0::from_num(I0F32::MAX), 0);
assert_eq!(U32F0::from_num(U0F32::MIN), 0);
assert_eq!(U32F0::from_num(U0F32::MAX), 0);
assert_eq!(I0F32::from_num(I32F0::from_bits(0)), 0);
assert_eq!(I0F32::from_num(U32F0::from_bits(0)), 0);
assert_eq!(U0F32::from_num(I32F0::from_bits(0)), 0);
assert_eq!(U0F32::from_num(U32F0::from_bits(0)), 0);
assert_eq!(I128F0::from_num(I0F128::MIN), -1);
assert_eq!(I128F0::from_num(I0F128::MAX), 0);
assert_eq!(I128F0::from_num(U0F128::MIN), 0);
assert_eq!(I128F0::from_num(U0F128::MAX), 0);
assert_eq!(U128F0::checked_from_num(I0F128::MIN), None);
assert_eq!(U128F0::from_num(I0F128::MAX), 0);
assert_eq!(U128F0::from_num(U0F128::MIN), 0);
assert_eq!(U128F0::from_num(U0F128::MAX), 0);
assert_eq!(I0F128::from_num(I128F0::from_bits(0)), 0);
assert_eq!(I0F128::from_num(U128F0::from_bits(0)), 0);
assert_eq!(U0F128::from_num(I128F0::from_bits(0)), 0);
assert_eq!(U0F128::from_num(U128F0::from_bits(0)), 0);
}
}

View File

@ -124,7 +124,7 @@ macro_rules! sealed_float {
let prec = Self::PREC as i32;
let (neg, exp, mut mantissa) = self.parts();
if exp == Self::EXP_MAX {
if exp > Self::EXP_MAX {
if mantissa == 0 {
return FloatKind::Infinite { neg };
} else {