diff --git a/src/extensions/collections/btree_map.rs b/src/extensions/collections/btree_map.rs index ad1c8ac..d6d14e4 100644 --- a/src/extensions/collections/btree_map.rs +++ b/src/extensions/collections/btree_map.rs @@ -85,7 +85,7 @@ impl Map for BTreeMap { } #[inline] - fn fold(self, initial_value: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B { + fn fold(&self, initial_value: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B { self.iter().fold(initial_value, function) } diff --git a/src/extensions/collections/hash_map.rs b/src/extensions/collections/hash_map.rs index 41e8b90..378c092 100644 --- a/src/extensions/collections/hash_map.rs +++ b/src/extensions/collections/hash_map.rs @@ -107,7 +107,7 @@ impl Map for HashMap { } #[inline] - fn fold(self, initial_value: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B { + fn fold(&self, initial_value: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B { self.iter().fold(initial_value, function) } diff --git a/src/extensions/map.rs b/src/extensions/map.rs index 89753e9..09929bd 100644 --- a/src/extensions/map.rs +++ b/src/extensions/map.rs @@ -459,15 +459,15 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (1, "1"), - /// (2, "two"), - /// (3, "NaN"), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// /// assert_eq!( - /// a.filter_map(|(&k, &v)| v.parse::().ok().map(|v| (k, v))), + /// a.filter_map(|(&k, &v)| if k < 2 { Some((k, v + 1)) } else { None }), /// HashMap::from([ - /// (1, 1), + /// (1, 2), /// ])); /// ``` /// @@ -478,18 +478,18 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (1, "1"), - /// (2, "two"), - /// (3, "NaN"), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// /// let filter_mapped = a - /// .map(|(&k, &v)| (k, v.parse::())) - /// .filter(|(_, s)| s.is_ok()) + /// .map(|(&k, &v)| (k, if k < 2 { Some(v + 1) } else { None })) + /// .filter(|(_, s)| s.is_some()) /// .map(|(&k, v)| (k, v.clone().unwrap())); /// /// assert_eq!(filter_mapped, HashMap::from([ - /// (1, 1), + /// (1, 2), /// ])); /// ``` fn filter_map(&self, function: impl FnMut((&Key, &Value)) -> Option<(L, W)>) -> Self::This @@ -520,15 +520,15 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (1, "1"), - /// (2, "two"), - /// (3, "NaN"), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// /// assert_eq!( - /// a.filter_map_to(|(k, v)| v.parse::().ok().map(|v| (k, v))), + /// a.filter_map_to(|(k, v)| if k < 2 { Some((k, v + 1)) } else { None }), /// HashMap::from([ - /// (1, 1), + /// (1, 2), /// ])); /// ``` /// @@ -539,18 +539,18 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (1, "1"), - /// (2, "two"), - /// (3, "NaN"), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// /// let filter_mapped = a - /// .map_to(|(k, v)| (k, v.parse::())) - /// .filter(|(_, s)| s.is_ok()) + /// .map_to(|(k, v)|(k, if k < 2 { Some(v + 1) } else { None })) + /// .filter(|(_, s)| s.is_some()) /// .map(|(&k, v)| (k, v.clone().unwrap())); /// /// assert_eq!(filter_mapped, HashMap::from([ - /// (1, 1), + /// (1, 2), /// ])); /// ``` #[inline] @@ -613,13 +613,13 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (1, "one"), - /// (2, "2"), - /// (3, "NaN"), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// /// assert_eq!( - /// a.find_map(|(_, &v)| v.parse().ok()), + /// a.find_map(|(&k, &v)| if k == 2 { Some(v) } else { None }), /// Some(2) /// ); /// ``` @@ -645,13 +645,13 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (1, "one"), - /// (2, "2"), - /// (3, "NaN"), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// /// assert_eq!( - /// a.find_map_to(|(_, v)| v.parse().ok()), + /// a.find_map_to(|(k, v)| if k == 2 { Some(v) } else { None }), /// Some(2) /// ); /// ``` @@ -748,7 +748,7 @@ pub trait Map { /// /// // Vec is iterable because it implements IntoIterator /// assert_eq!( - /// a.flat_map(|(&k, &v)| vec![(-k, v), (k, v)]), + /// a.flat_map_to(|(k, v)| vec![(-k, v), (k, v)]), /// HashMap::from([ /// (-1, 1), /// (-2, 2), @@ -828,7 +828,7 @@ pub trait Map { /// | 3 | 5 | 3 | c | 9 | /// /// And so, our final result, `9`. - fn fold(self, initial_value: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B; + fn fold(&self, initial_value: B, function: impl FnMut(B, (&Key, &Value)) -> B) -> B; /// Folds every entry into an accumulator by applying an operation, /// returning the final result. @@ -912,15 +912,19 @@ pub trait Map { /// /// ``` /// use crate::cantrip::*; - /// use std::sync::mpsc::channel; + /// use std::collections::HashMap; /// - /// let (tx, rx) = channel(); - /// (0..3).for_each(move |x| tx.send(x).unwrap()); + /// let a = HashMap::from([ + /// (1, 1), + /// (2, 2), + /// (3, 3), + /// ]); /// - /// assert_eq!( - /// rx.iter().collect::>(), - /// vec![0, 1, 2] - /// ); + /// let mut acc = 0; + /// + /// a.for_each(|(&k, &v)| acc += k + v); + /// + /// assert_eq!(acc, 12); /// ``` /// /// For such a small example, a `for` loop may be cleaner, but `for_each` @@ -1195,13 +1199,13 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0, 1), - /// (3, 2), - /// (-3, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.max_by(|x, y| x.0.cmp(y.0)), Some((&3, &2))); + /// assert_eq!(a.max_by(|x, y| x.0.cmp(y.0)), Some((&3, &3))); /// /// assert_eq!(e.max_by(|x, y| x.0.cmp(y.0)), None); /// ``` @@ -1220,15 +1224,15 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0_i32, 1), - /// (3, 2), - /// (-5, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.max_by_key(|(k, _)| k.abs()), Some((&-5, &3))); + /// assert_eq!(a.max_by_key(|(k, _)| -k), Some((&1, &1))); /// - /// assert_eq!(e.max_by_key(|(k, _)| k.abs()), None); + /// assert_eq!(e.max_by_key(|(k, _)| -k), None); /// ``` fn max_by_key(&self, to_key: impl FnMut((&Key, &Value)) -> K) -> Option<(&Key, &Value)> where @@ -1246,18 +1250,18 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0, 1), - /// (1, 2), - /// (2, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.max_item(), Some((&2, &3))); + /// assert_eq!(a.max_of(), Some((&3, &3))); /// - /// assert_eq!(e.max_item(), None); + /// assert_eq!(e.max_of(), None); /// ``` #[inline] - fn max_item(&self) -> Option<(&Key, &Value)> + fn max_of(&self) -> Option<(&Key, &Value)> where Key: Ord, Value: Ord, @@ -1278,13 +1282,13 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0, 1), - /// (3, 2), - /// (-5, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.min_by(|x, y| x.0.cmp(y.0)), Some((&-5, &3))); + /// assert_eq!(a.min_by(|x, y| x.0.cmp(y.0)), Some((&1, &1))); /// /// assert_eq!(e.min_by(|x, y| x.0.cmp(y.0)), None); /// ``` @@ -1303,15 +1307,15 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0_i32, 1), - /// (3, 2), - /// (-5, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.min_by_key(|(k, _)| k.abs()), Some((&0, &1))); + /// assert_eq!(a.min_by_key(|(k, _)| -k), Some((&3, &3))); /// - /// assert_eq!(e.min_by_key(|(k, _)| k.abs()), None); + /// assert_eq!(e.min_by_key(|(k, _)| -k), None); /// ``` fn min_by_key(&self, to_key: impl FnMut((&Key, &Value)) -> K) -> Option<(&Key, &Value)> where @@ -1329,18 +1333,18 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0, 1), - /// (1, 2), - /// (2, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.min_item(), Some((&0, &1))); + /// assert_eq!(a.min_of(), Some((&1, &1))); /// - /// assert_eq!(e.min_item(), None); + /// assert_eq!(e.min_of(), None); /// ``` #[inline] - fn min_item(&self) -> Option<(&Key, &Value)> + fn min_of(&self) -> Option<(&Key, &Value)> where Key: Ord, Value: Ord, @@ -1362,13 +1366,13 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0, 1), - /// (3, 2), - /// (-5, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.minmax_by(|x, y| x.0.cmp(y.0)), Some(((&-5, &3), (&3, &2)))); + /// assert_eq!(a.minmax_by(|x, y| x.0.cmp(y.0)), Some(((&1, &1), (&3, &3)))); /// /// assert_eq!(e.minmax_by(|x, y| x.0.cmp(y.0)), None); /// ``` @@ -1390,14 +1394,15 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0_i32, 1), - /// (3, 2), - /// (-5, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.minmax_by_key(|(k, _)| k.abs()), Some(((&0, &1), (&-5, &3)))); - /// assert_eq!(e.minmax_by_key(|(k, _)| k.abs()), None); + /// assert_eq!(a.minmax_by_key(|(k, _)| -k), Some(((&3, &3), (&1, &1)))); + /// + /// assert_eq!(e.minmax_by_key(|(k, _)| -k), None); /// ``` fn minmax_by_key(&self, to_key: impl FnMut((&Key, &Value)) -> K) -> Option<((&Key, &Value), (&Key, &Value))> where @@ -1416,18 +1421,18 @@ pub trait Map { /// use std::collections::HashMap; /// /// let a = HashMap::from([ - /// (0, 1), - /// (1, 2), - /// (2, 3), + /// (1, 1), + /// (2, 2), + /// (3, 3), /// ]); /// let e = HashMap::::new(); /// - /// assert_eq!(a.minmax_item(), Some(((&0, &1), (&2, &3)))); + /// assert_eq!(a.minmax_of(), Some(((&1, &1), (&3, &3)))); /// - /// assert_eq!(e.minmax_item(), None); + /// assert_eq!(e.minmax_of(), None); /// ``` #[inline] - fn minmax_item(&self) -> Option<((&Key, &Value), (&Key, &Value))> + fn minmax_of(&self) -> Option<((&Key, &Value), (&Key, &Value))> where Key: Ord, Value: Ord, diff --git a/src/extensions/traversable.rs b/src/extensions/traversable.rs index 86ddc22..cf4e787 100644 --- a/src/extensions/traversable.rs +++ b/src/extensions/traversable.rs @@ -225,7 +225,7 @@ pub trait Traversable { /// ``` /// use cantrip::*; /// - /// let a = vec![1, 2, 3, 4, 5]; + /// let a = vec![1, 2, 3]; /// /// let zero = "0".to_string(); /// @@ -233,7 +233,7 @@ pub trait Traversable { /// format!("({acc} + {x})") /// }); /// - /// assert_eq!(folded, "(((((0 + 1) + 2) + 3) + 4) + 5)"); + /// assert_eq!(folded, "(((0 + 1) + 2) + 3)"); /// ``` /// It's common for people who haven't used collections a lot to /// use a `for` loop with a list of things to build up a result. Those @@ -244,7 +244,7 @@ pub trait Traversable { /// ``` /// use cantrip::*; /// - /// let a = vec![1, 2, 3, 4, 5]; + /// let a = vec![1, 2, 3]; /// /// let mut result = 0; /// @@ -276,15 +276,14 @@ pub trait Traversable { /// /// ``` /// use crate::cantrip::*; - /// use std::sync::mpsc::channel; /// - /// let (tx, rx) = channel(); - /// (0..3).for_each(move |x| tx.send(x).unwrap()); + /// let a = vec![1, 2, 3]; + /// + /// let mut acc = 0; + /// + /// a.for_each(|&x| acc += x); /// - /// assert_eq!( - /// rx.iter().collect::>(), - /// vec![0, 1, 2] - /// ); + /// assert_eq!(acc, 6); /// ``` /// /// For such a small example, a `for` loop may be cleaner, but `for_each` diff --git a/tests/extensions/map.rs b/tests/extensions/map.rs index 98d1139..1e4bfa6 100644 --- a/tests/extensions/map.rs +++ b/tests/extensions/map.rs @@ -11,6 +11,8 @@ where + FromIterator<(i64, i64)> + IntoIterator + Iterable = (&'a i64, &'a i64)> + + Default + + Extend<(i64, i64)> + Clone + Equal + Debug @@ -86,6 +88,170 @@ where assert_map_equal(HashMap::fill_with(|| (1, 1), 1), HashMap::from([(1, 1)])); assert_map_equal(HashMap::fill_with(|| (1, 1), 0), HashMap::new()); + // filter + let a = a_source.clone(); + let e = e_source.clone(); + assert_map_equal(a.filter(|(&k, &v)| k != 2 && v != 2), HashMap::from([(1, 1), (3, 3)])); + assert_map_equal(e.filter(|(&k, &v)| k != 2 && v != 2), HashMap::new()); + + // filter_keys + let a = a_source.clone(); + let e = e_source.clone(); + assert_map_equal(a.filter_keys(|&k| k != 2), HashMap::from([(1, 1), (3, 3)])); + assert_map_equal(e.filter_keys(|&k| k != 2), HashMap::new()); + + // filter_Values + let a = a_source.clone(); + let e = e_source.clone(); + assert_map_equal(a.filter_values(|&v| v != 2), HashMap::from([(1, 1), (3, 3)])); + assert_map_equal(e.filter_values(|&v| v != 2), HashMap::new()); + + // filter_map - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_map_equal(a.filter_map(|(&k, &v)| if k < 2 { Some((k, v + 1)) } else { None }), HashMap::from([(1, 2)])); + // assert_map_equal(e.filter_map(|(&k, &v)| if k < 2 { Some((k, v + 1)) } else { None }), HashMap::new()); + + // filter_map_to - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_map_to_equal(a.filter_map_to(|(k, v)| if k < 2 { Some((k, v + 1)) } else { None }), HashMap::from([(1, 2)])); + // assert_map_to_equal(e.filter_map_to(|(k, v)| if k < 2 { Some((k, v + 1)) } else { None }), HashMap::new()); + + // find + let a = a_source.clone(); + let e = e_source.clone(); + assert_eq!(a.find(|(&k, &v)| k == 2 && v == 2), Some((&2, &2))); + assert_eq!(a.find(|(&k, _)| k == 5), None); + assert_eq!(e.find(|(&k, _)| k == 5), None); + + // find_map + let a = a_source.clone(); + let e = e_source.clone(); + assert_eq!(a.find_map(|(&k, &v)| if k == 2 { Some(v) } else { None }), Some(2)); + assert_eq!(e.find_map(|(&k, &v)| if k == 2 { Some(v) } else { None }), None); + + // find_map_to + let a = a_source.clone(); + let e = e_source.clone(); + assert_eq!(a.find_map_to(|(k, v)| if k == 2 { Some(v) } else { None }), Some(2)); + assert_eq!(e.find_map_to(|(k, v)| if k == 2 { Some(v) } else { None }), None); + + // flat_map - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_map_equal( + // a.flat_map(|(&k, &v)| vec![(-k, v), (k, v)]), + // HashMap::from([(-1, 1), (-2, 2), (-3, 3), (1, 1), (2, 2), (3, 3)]), + // ); + // assert_map_equal(e.flat_map(|(&k, &v)| vec![(-k, v), (k, v)]), HashMap::new()); + + // flat_map_to - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_map_equal( + // a.flat_map(|(k, v)| vec![(-k, v), (k, v)]), + // HashMap::from([(-1, 1), (-2, 2), (-3, 3), (1, 1), (2, 2), (3, 3)]), + // ); + // assert_map_equal(e.flat_map(|(k, v)| vec![(-k, v), (k, v)]), HashMap::new()); + + // fold + let a = a_source.clone(); + let e = e_source.clone(); + assert_eq!(a.fold(0, |acc, (&k, &v)| acc + k + v), 12); + assert_eq!(e.fold(0, |acc, (&k, &v)| acc + k + v), 0); + + // fold_to + assert_eq!(a.fold_to(0, |acc, (k, v)| acc + k + v), 12); + assert_eq!(e.fold_to(0, |acc, (k, v)| acc + k + v), 0); + + // for_each + let a = a_source.clone(); + let e = e_source.clone(); + let mut acc = 0; + a.for_each(|(&k, &v)| acc += k + v); + assert_eq!(acc, 12); + e.for_each(|(&k, &v)| acc += k + v); + assert_eq!(acc, 12); + + // intersect + let a = a_source.clone(); + let e = e_source.clone(); + assert_map_equal(a.intersect(&vec![(4, 4), (2, 2), (3, 4), (4, 5)]), HashMap::from([(2, 2)])); + assert_map_equal(e.intersect(&vec![(1, 1)]), HashMap::new()); + + // map - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_map_equal(a.map(|(&k, &v)| (k, k + v)), HashMap::from([(1, 2), (2, 4), (3, 6)])); + // assert_map_equal(e.map(|(&k, &v)| (k, k + v)), HashMap::new()); + + // map_to - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_map_equal(a.map_to(|(k, v)| (k, k + v)), HashMap::from([(1, 2), (2, 4), (3, 6)])); + // assert_map_equal(e.map_to(|(k, v)| (k, k + v)), HashMap::new()); + + // map_keys - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_map_equal(a.map_keys(|&k| k + 1), HashMap::from([(2, 1), (3, 2), (4, 3),])); + // assert_map_equal(e.map_keys(|&k| k + 1), HashMap::new()); + + // map_values - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_map_equal(a.map_values(|&v| v + 1), HashMap::from([(1, 2), (2, 3), (3, 4),])); + // assert_map_equal(e.map_values(|&v| v + 1), HashMap::new()); + + // max_by + let a = a_source.clone(); + let e = e_source.clone(); + assert_eq!(a.max_by(|x, y| x.0.cmp(y.0)), Some((&3, &3))); + assert_eq!(e.max_by(|x, y| x.0.cmp(y.0)), None); + + // max_by_key + assert_eq!(a.max_by_key(|(k, _)| -k), Some((&1, &1))); + assert_eq!(e.max_by_key(|(k, _)| -k), None); + + // max_of + assert_eq!(a.max_of(), Some((&3, &3))); + assert_eq!(e.max_of(), None); + + // min_by + assert_eq!(a.min_by(|x, y| x.0.cmp(y.0)), Some((&1, &1))); + assert_eq!(e.min_by(|x, y| x.0.cmp(y.0)), None); + + // min_by_key + assert_eq!(a.min_by_key(|(k, _)| -k), Some((&3, &3))); + assert_eq!(e.min_by_key(|(k, _)| -k), None); + + // min_of + assert_eq!(a.min_of(), Some((&1, &1))); + assert_eq!(e.min_of(), None); + + // minmax_by + assert_eq!(a.minmax_by(|x, y| x.0.cmp(y.0)), Some(((&1, &1), (&3, &3)))); + assert_eq!(e.minmax_by(|x, y| x.0.cmp(y.0)), None); + + // minmax_by_key + assert_eq!(a.minmax_by_key(|(k, _)| -k), Some(((&3, &3), (&1, &1)))); + assert_eq!(e.minmax_by_key(|(k, _)| -k), None); + + // minmax_of + assert_eq!(a.minmax_of(), Some(((&1, &1), (&3, &3)))); + assert_eq!(e.minmax_of(), None); + + // partition + let a = a_source.clone(); + let e = e_source.clone(); + let (a_even, a_odd) = a.partition(|(&k, _)| k % 2 == 0); + assert_map_equal(a_even, HashMap::from([(2, 2)])); + assert_map_equal(a_odd, HashMap::from([(1, 1), (3, 3)])); + let (e_even, e_odd) = e.partition(|(&k, _)| k % 2 == 0); + assert_map_equal(e_even, HashMap::new()); + assert_map_equal(e_odd, HashMap::new()); + // // replace // assert_map_equal(distinct.clone().substitute(&0, 0, 1), vec![(0, 1), (1, 1), (2, 2)]); // // assert_map_equal(distinct.clone().replace(&0, 1, 2), vec![(1, 2), (2, 2)]); diff --git a/tests/extensions/sequence.rs b/tests/extensions/sequence.rs index ba65bb0..7e08072 100644 --- a/tests/extensions/sequence.rs +++ b/tests/extensions/sequence.rs @@ -477,10 +477,12 @@ where // unzip - FIXME - implement test // let a = a_source.clone(); // let e = e_source.clone(); - // let (left, right) = a.unzip(); - // assert_seq_equal(left, vec![1, 3, 5]); - // assert_seq_equal(right, vec![2, 4, 6]); - // assert_seq_equal(e.unzip().0, vec![]); + // let (a_left, a_right) = a.unzip(); + // assert_seq_equal(a_left, vec![1, 3, 5]); + // assert_seq_equal(a_right, vec![2, 4, 6]); + // let (e_left, e_right) = e.unzip(); + // assert_seq_equal(e_left, vec![]); + // assert_seq_equal(e_right, vec![]); // variations let a = a_source.clone(); diff --git a/tests/extensions/traits.rs b/tests/extensions/traits.rs index 43e2ed1..d2a6f0c 100644 --- a/tests/extensions/traits.rs +++ b/tests/extensions/traits.rs @@ -110,6 +110,8 @@ where + FromIterator<(i64, i64)> + IntoIterator + Iterable = (&'a i64, &'a i64)> + + Default + + Extend<(i64, i64)> + Clone + Equal + Debug diff --git a/tests/extensions/traversable.rs b/tests/extensions/traversable.rs index 3e53c96..c86e863 100644 --- a/tests/extensions/traversable.rs +++ b/tests/extensions/traversable.rs @@ -48,9 +48,9 @@ where // for_each let mut acc = 0; - a.for_each(|x| acc += x); + a.for_each(|&x| acc += x); assert_eq!(acc, 6); - e.for_each(|x| acc += x); + e.for_each(|&x| acc += x); assert_eq!(acc, 6); // group_fold diff --git a/tests/main.rs b/tests/main.rs index ec201b9..e49947f 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -19,9 +19,9 @@ fn sequences() { let linked_list: LinkedList = LinkedList::new(); let slice = &vec[..]; let _ = (slice.len(), vec.len(), linked_list.len(), vec_deque.len()); - if false {test_sequence_traits(vec)}; - if false {test_list_traits(linked_list)}; - if true {test_list_traits(vec_deque)}; + test_sequence_traits(vec); + if false { test_list_traits(linked_list) }; + test_list_traits(vec_deque); } #[test]