about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorKonrad Borowski <konrad@borowski.pw>2018-12-23 16:47:11 +0100
committerGitHub <noreply@github.com>2018-12-23 16:47:11 +0100
commit8ac5380ea0204dbdcbc8108d259928b67d5f8ebb (patch)
tree174d912756fc2678af50d46ff457f7504750a975 /src/libcore/tests
parentb4a306c1e648c84f289c63e984941b7faad10af1 (diff)
parentddab10a692aab2e2984b5c826ed9d78a57e94851 (diff)
downloadrust-8ac5380ea0204dbdcbc8108d259928b67d5f8ebb.tar.gz
rust-8ac5380ea0204dbdcbc8108d259928b67d5f8ebb.zip
Merge branch 'master' into copied
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/iter.rs48
-rw-r--r--src/libcore/tests/lib.rs1
-rw-r--r--src/libcore/tests/num/dec2flt/mod.rs2
-rw-r--r--src/libcore/tests/num/flt2dec/random.rs15
-rw-r--r--src/libcore/tests/num/int_macros.rs4
-rw-r--r--src/libcore/tests/num/mod.rs26
-rw-r--r--src/libcore/tests/slice.rs6
7 files changed, 79 insertions, 23 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs
index 0964aae1db5..44899c3f412 100644
--- a/src/libcore/tests/iter.rs
+++ b/src/libcore/tests/iter.rs
@@ -1001,6 +1001,10 @@ fn test_cycle() {
     let mut it = (0..).step_by(1).take(0).cycle();
     assert_eq!(it.size_hint(), (0, Some(0)));
     assert_eq!(it.next(), None);
+
+    assert_eq!(empty::<i32>().cycle().fold(0, |acc, x| acc + x), 0);
+
+    assert_eq!(once(1).cycle().skip(1).take(4).fold(0, |acc, x| acc + x), 4);
 }
 
 #[test]
@@ -1013,6 +1017,33 @@ fn test_iterator_nth() {
 }
 
 #[test]
+fn test_iterator_nth_back() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    for i in 0..v.len() {
+        assert_eq!(v.iter().nth_back(i).unwrap(), &v[v.len() - 1 - i]);
+    }
+    assert_eq!(v.iter().nth_back(v.len()), None);
+}
+
+#[test]
+fn test_iterator_rev_nth_back() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    for i in 0..v.len() {
+        assert_eq!(v.iter().rev().nth_back(i).unwrap(), &v[i]);
+    }
+    assert_eq!(v.iter().rev().nth_back(v.len()), None);
+}
+
+#[test]
+fn test_iterator_rev_nth() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    for i in 0..v.len() {
+        assert_eq!(v.iter().rev().nth(i).unwrap(), &v[v.len() - 1 - i]);
+    }
+    assert_eq!(v.iter().rev().nth(v.len()), None);
+}
+
+#[test]
 fn test_iterator_last() {
     let v: &[_] = &[0, 1, 2, 3, 4];
     assert_eq!(v.iter().last().unwrap(), &4);
@@ -1267,6 +1298,23 @@ fn test_cloned() {
 }
 
 #[test]
+fn test_cloned_side_effects() {
+    let mut count = 0;
+    {
+        let iter = [1, 2, 3]
+            .iter()
+            .map(|x| {
+                count += 1;
+                x
+            })
+            .cloned()
+            .zip(&[1]);
+        for _ in iter {}
+    }
+    assert_eq!(count, 2);
+}
+
+#[test]
 fn test_double_ended_map() {
     let xs = [1, 2, 3, 4, 5, 6];
     let mut it = xs.iter().map(|&x| x * -1);
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs
index 1f7a8b774d7..400a86d2ffe 100644
--- a/src/libcore/tests/lib.rs
+++ b/src/libcore/tests/lib.rs
@@ -21,6 +21,7 @@
 #![feature(fmt_internals)]
 #![feature(hashmap_internals)]
 #![feature(iter_copied)]
+#![feature(iter_nth_back)]
 #![feature(iter_unfold)]
 #![feature(pattern)]
 #![feature(range_is_empty)]
diff --git a/src/libcore/tests/num/dec2flt/mod.rs b/src/libcore/tests/num/dec2flt/mod.rs
index 17b2f59cd4d..879a41b4b77 100644
--- a/src/libcore/tests/num/dec2flt/mod.rs
+++ b/src/libcore/tests/num/dec2flt/mod.rs
@@ -17,7 +17,7 @@ mod rawfp;
 
 // Take a float literal, turn it into a string in various ways (that are all trusted
 // to be correct) and see if those strings are parsed back to the value of the literal.
-// Requires a *polymorphic literal*, i.e. one that can serve as f64 as well as f32.
+// Requires a *polymorphic literal*, i.e., one that can serve as f64 as well as f32.
 macro_rules! test_literal {
     ($x: expr) => ({
         let x32: f32 = $x;
diff --git a/src/libcore/tests/num/flt2dec/random.rs b/src/libcore/tests/num/flt2dec/random.rs
index ab619093d9d..21a7c9fc6b3 100644
--- a/src/libcore/tests/num/flt2dec/random.rs
+++ b/src/libcore/tests/num/flt2dec/random.rs
@@ -18,7 +18,8 @@ use core::num::flt2dec::strategy::grisu::format_exact_opt;
 use core::num::flt2dec::strategy::grisu::format_shortest_opt;
 use core::num::flt2dec::{decode, DecodableFloat, FullDecoded, Decoded};
 
-use rand::{FromEntropy, XorShiftRng};
+use rand::FromEntropy;
+use rand::rngs::SmallRng;
 use rand::distributions::{Distribution, Uniform};
 
 pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
@@ -71,7 +72,10 @@ fn iterate<F, G, V>(func: &str, k: usize, n: usize, mut f: F, mut g: G, mut v: V
 pub fn f32_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
         where F: FnMut(&Decoded, &mut [u8]) -> Option<(usize, i16)>,
               G: FnMut(&Decoded, &mut [u8]) -> (usize, i16) {
-    let mut rng = XorShiftRng::from_entropy();
+    if cfg!(target_os = "emscripten") {
+        return // using rng pulls in i128 support, which doesn't work
+    }
+    let mut rng = SmallRng::from_entropy();
     let f32_range = Uniform::new(0x0000_0001u32, 0x7f80_0000);
     iterate("f32_random_equivalence_test", k, n, f, g, |_| {
         let x = f32::from_bits(f32_range.sample(&mut rng));
@@ -82,7 +86,10 @@ pub fn f32_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
 pub fn f64_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
         where F: FnMut(&Decoded, &mut [u8]) -> Option<(usize, i16)>,
               G: FnMut(&Decoded, &mut [u8]) -> (usize, i16) {
-    let mut rng = XorShiftRng::from_entropy();
+    if cfg!(target_os = "emscripten") {
+        return // using rng pulls in i128 support, which doesn't work
+    }
+    let mut rng = SmallRng::from_entropy();
     let f64_range = Uniform::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
     iterate("f64_random_equivalence_test", k, n, f, g, |_| {
         let x = f64::from_bits(f64_range.sample(&mut rng));
@@ -99,7 +106,7 @@ pub fn f32_exhaustive_equivalence_test<F, G>(f: F, g: G, k: usize)
     // this is of course very stressful (and thus should be behind an `#[ignore]` attribute),
     // but with `-C opt-level=3 -C lto` this only takes about an hour or so.
 
-    // iterate from 0x0000_0001 to 0x7f7f_ffff, i.e. all finite ranges
+    // iterate from 0x0000_0001 to 0x7f7f_ffff, i.e., all finite ranges
     let (npassed, nignored) = iterate("f32_exhaustive_equivalence_test",
                                       k, 0x7f7f_ffff, f, g, |i: usize| {
 
diff --git a/src/libcore/tests/num/int_macros.rs b/src/libcore/tests/num/int_macros.rs
index 71d2e794538..8b04f84007f 100644
--- a/src/libcore/tests/num/int_macros.rs
+++ b/src/libcore/tests/num/int_macros.rs
@@ -31,8 +31,8 @@ mod tests {
     }
 
     #[test]
-    fn test_mod_euc() {
-        assert!((-1 as $T).mod_euc(MIN) == MAX);
+    fn test_rem_euclid() {
+        assert!((-1 as $T).rem_euclid(MIN) == MAX);
     }
 
     #[test]
diff --git a/src/libcore/tests/num/mod.rs b/src/libcore/tests/num/mod.rs
index 0928f7560e1..e1648db5e8e 100644
--- a/src/libcore/tests/num/mod.rs
+++ b/src/libcore/tests/num/mod.rs
@@ -694,23 +694,23 @@ macro_rules! test_float {
             assert!(($nan as $fty).max($nan).is_nan());
         }
         #[test]
-        fn mod_euc() {
+        fn rem_euclid() {
             let a: $fty = 42.0;
-            assert!($inf.mod_euc(a).is_nan());
-            assert_eq!(a.mod_euc($inf), a);
-            assert!(a.mod_euc($nan).is_nan());
-            assert!($inf.mod_euc($inf).is_nan());
-            assert!($inf.mod_euc($nan).is_nan());
-            assert!($nan.mod_euc($inf).is_nan());
+            assert!($inf.rem_euclid(a).is_nan());
+            assert_eq!(a.rem_euclid($inf), a);
+            assert!(a.rem_euclid($nan).is_nan());
+            assert!($inf.rem_euclid($inf).is_nan());
+            assert!($inf.rem_euclid($nan).is_nan());
+            assert!($nan.rem_euclid($inf).is_nan());
         }
         #[test]
-        fn div_euc() {
+        fn div_euclid() {
             let a: $fty = 42.0;
-            assert_eq!(a.div_euc($inf), 0.0);
-            assert!(a.div_euc($nan).is_nan());
-            assert!($inf.div_euc($inf).is_nan());
-            assert!($inf.div_euc($nan).is_nan());
-            assert!($nan.div_euc($inf).is_nan());
+            assert_eq!(a.div_euclid($inf), 0.0);
+            assert!(a.div_euclid($nan).is_nan());
+            assert!($inf.div_euclid($inf).is_nan());
+            assert!($inf.div_euclid($nan).is_nan());
+            assert!($nan.div_euclid($inf).is_nan());
         }
     } }
 }
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs
index dba5a43eb21..4f00ebee1d2 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -1024,11 +1024,11 @@ fn test_rotate_right() {
 fn sort_unstable() {
     use core::cmp::Ordering::{Equal, Greater, Less};
     use core::slice::heapsort;
-    use rand::{FromEntropy, Rng, XorShiftRng};
+    use rand::{FromEntropy, Rng, rngs::SmallRng, seq::SliceRandom};
 
     let mut v = [0; 600];
     let mut tmp = [0; 600];
-    let mut rng = XorShiftRng::from_entropy();
+    let mut rng = SmallRng::from_entropy();
 
     for len in (2..25).chain(500..510) {
         let v = &mut v[0..len];
@@ -1073,7 +1073,7 @@ fn sort_unstable() {
     for i in 0..v.len() {
         v[i] = i as i32;
     }
-    v.sort_unstable_by(|_, _| *rng.choose(&[Less, Equal, Greater]).unwrap());
+    v.sort_unstable_by(|_, _| *[Less, Equal, Greater].choose(&mut rng).unwrap());
     v.sort_unstable();
     for i in 0..v.len() {
         assert_eq!(v[i], i as i32);