about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-04-23 19:48:35 +0200
committerRalf Jung <post@ralfj.de>2020-04-23 19:50:24 +0200
commitf1c30519f30e4c245e2b319fbb257ba2c59e8092 (patch)
tree59de5bff85c6e1e9a70229045bb34f722384cdaa /src
parent66f7a5d92f5adb9053bf66e0bf8f6d31d404870d (diff)
downloadrust-f1c30519f30e4c245e2b319fbb257ba2c59e8092.tar.gz
rust-f1c30519f30e4c245e2b319fbb257ba2c59e8092.zip
libcore: more compact way to adjust test sizes for Miri
Diffstat (limited to 'src')
-rw-r--r--src/libcore/tests/num/flt2dec/estimator.rs8
-rw-r--r--src/libcore/tests/num/flt2dec/random.rs26
-rw-r--r--src/libcore/tests/slice.rs12
3 files changed, 16 insertions, 30 deletions
diff --git a/src/libcore/tests/num/flt2dec/estimator.rs b/src/libcore/tests/num/flt2dec/estimator.rs
index 8ee06d895ca..da203b5f362 100644
--- a/src/libcore/tests/num/flt2dec/estimator.rs
+++ b/src/libcore/tests/num/flt2dec/estimator.rs
@@ -52,12 +52,10 @@ fn test_estimate_scaling_factor() {
     assert_almost_eq!(estimate_scaling_factor(1, -1074), -323);
     assert_almost_eq!(estimate_scaling_factor(0x1fffffffffffff, 971), 309);
 
-    #[cfg(not(miri))] // Miri is too slow
-    let iter = -1074..972;
-    #[cfg(miri)]
-    let iter = (-1074..972).step_by(37);
+    // Miri is too slow
+    let step = if cfg!(miri) { 37 } else { 1 };
 
-    for i in iter {
+    for i in (-1074..972).step_by(step) {
         let expected = super::ldexp_f64(1.0, i).log10().ceil();
         assert_almost_eq!(estimate_scaling_factor(1, i as i16), expected as i16);
     }
diff --git a/src/libcore/tests/num/flt2dec/random.rs b/src/libcore/tests/num/flt2dec/random.rs
index 5b050a2c356..0ebc0881f52 100644
--- a/src/libcore/tests/num/flt2dec/random.rs
+++ b/src/libcore/tests/num/flt2dec/random.rs
@@ -138,13 +138,11 @@ where
 #[test]
 fn shortest_random_equivalence_test() {
     use core::num::flt2dec::strategy::dragon::format_shortest as fallback;
-    #[cfg(not(miri))] // Miri is too slow
-    const N: usize = 10_000;
-    #[cfg(miri)]
-    const N: usize = 10;
+    // Miri is too slow
+    let n = if cfg!(miri) { 10 } else { 10_000 };
 
-    f64_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, N);
-    f32_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, N);
+    f64_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, n);
+    f32_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, n);
 }
 
 #[test]
@@ -173,17 +171,15 @@ fn shortest_f64_hard_random_equivalence_test() {
 #[test]
 fn exact_f32_random_equivalence_test() {
     use core::num::flt2dec::strategy::dragon::format_exact as fallback;
-    #[cfg(not(miri))] // Miri is too slow
-    const N: usize = 1_000;
-    #[cfg(miri)]
-    const N: usize = 3;
+    // Miri is too slow
+    let n = if cfg!(miri) { 3 } else { 1_000 };
 
     for k in 1..21 {
         f32_random_equivalence_test(
             |d, buf| format_exact_opt(d, buf, i16::MIN),
             |d, buf| fallback(d, buf, i16::MIN),
             k,
-            N,
+            n,
         );
     }
 }
@@ -191,17 +187,15 @@ fn exact_f32_random_equivalence_test() {
 #[test]
 fn exact_f64_random_equivalence_test() {
     use core::num::flt2dec::strategy::dragon::format_exact as fallback;
-    #[cfg(not(miri))] // Miri is too slow
-    const N: usize = 1_000;
-    #[cfg(miri)]
-    const N: usize = 3;
+    // Miri is too slow
+    let n = if cfg!(miri) { 3 } else { 1_000 };
 
     for k in 1..21 {
         f64_random_equivalence_test(
             |d, buf| format_exact_opt(d, buf, i16::MIN),
             |d, buf| fallback(d, buf, i16::MIN),
             k,
-            N,
+            n,
         );
     }
 }
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs
index 9b9420cc13f..54a585415bc 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -1227,15 +1227,9 @@ fn sort_unstable() {
     use core::slice::heapsort;
     use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng};
 
-    #[cfg(not(miri))] // Miri is too slow
-    let large_range = 500..510;
-    #[cfg(not(miri))] // Miri is too slow
-    let rounds = 100;
-
-    #[cfg(miri)]
-    let large_range = 0..0; // empty range
-    #[cfg(miri)]
-    let rounds = 1;
+    // Miri is too slow
+    let large_range = if cfg!(miri) { 0..0 } else { 500..510 };
+    let rounds = if cfg!(miri) { 1 } else { 100 };
 
     let mut v = [0; 600];
     let mut tmp = [0; 600];