Skip to content

Commit 907fc19

Browse files
dramforevercuviper
authored andcommitted
Add quickcheck for to_{f32,f64} consistent with cast
1 parent 5b6955b commit 907fc19

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

ci/big_quickcheck/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use num_bigint::{BigInt, BigUint};
1010
use num_integer::Integer;
11-
use num_traits::{Num, One, Signed, Zero};
11+
use num_traits::{Num, One, Signed, ToPrimitive, Zero};
1212
use quickcheck::{Gen, QuickCheck, TestResult};
1313
use quickcheck_macros::quickcheck;
1414

@@ -357,3 +357,20 @@ fn quickcheck_modpow() {
357357

358358
qc.quickcheck(test_modpow as fn(i128, u128, i128) -> TestResult);
359359
}
360+
361+
#[test]
362+
fn quickcheck_to_float_equals_i128_cast() {
363+
let gen = Gen::new(usize::max_value());
364+
let mut qc = QuickCheck::new().gen(gen).tests(1_000_000);
365+
366+
fn to_f32_equals_i128_cast(value: i128) -> bool {
367+
BigInt::from(value).to_f32() == Some(value as f32)
368+
}
369+
370+
fn to_f64_equals_i128_cast(value: i128) -> bool {
371+
BigInt::from(value).to_f64() == Some(value as f64)
372+
}
373+
374+
qc.quickcheck(to_f32_equals_i128_cast as fn(i128) -> bool);
375+
qc.quickcheck(to_f64_equals_i128_cast as fn(i128) -> bool);
376+
}

0 commit comments

Comments
 (0)