diff --git a/src/extensions/sequence.rs b/src/extensions/sequence.rs index 08a7484..bbed765 100644 --- a/src/extensions/sequence.rs +++ b/src/extensions/sequence.rs @@ -852,11 +852,11 @@ pub trait Sequence { /// ``` /// use cantrip::*; /// - /// let a = vec![-1, 4, 0, 1]; + /// let a = vec![1, 2, 3]; /// /// assert_eq!( - /// a.map_while(|x| 16_i32.checked_div(*x)), - /// vec![-16, 4] + /// a.map_while(|&x| if x < 3 { Some(x + 1) } else { None }), + /// vec![2, 3] /// ); /// ``` /// @@ -868,11 +868,11 @@ pub trait Sequence { /// ``` /// use cantrip::*; /// - /// let a = vec![-1, 4, 0, 1]; + /// let a = vec![1, 2, 3]; /// /// assert_eq!( - /// a.map(|x| 16_i32.checked_div(*x)).take_while(|x| x.is_some()).map(|x| x.unwrap()), - /// vec![-16, 4] + /// a.map(|&x| if x < 3 { Some(x + 1) } else { None }).take_while(|x| x.is_some()).map(|x| x.unwrap()), + /// vec![2, 3] /// ); /// ``` fn map_while(&self, predicate: impl FnMut(&Item) -> Option) -> Self::This; @@ -887,7 +887,7 @@ pub trait Sequence { /// assert_eq!( /// a.merge(vec![0, 4, 5]), /// vec![0, 1, 2, 3, 4, 5] - /// ); + /// ); /// ``` fn merge(self, elements: impl IntoIterator) -> Self where diff --git a/tests/extensions/sequence.rs b/tests/extensions/sequence.rs index dfe78dc..b8bc1b9 100644 --- a/tests/extensions/sequence.rs +++ b/tests/extensions/sequence.rs @@ -15,6 +15,7 @@ where + Iterable = &'a i64> + Clone + Equal + + UnwindSafe + Debug + 'a, for<'c> &'c C: UnwindSafe, @@ -245,6 +246,42 @@ where // assert_seq_equal(a.intersperse_with(3, || 0), vec![1, 2, 3]); // assert_seq_equal(e.intersperse_with(1, || 0), vec![]); + // map_while - FIXME - implement test + // assert_seq_equal(a.map_while(|&x| if x < 2 { Some(x + 1) } else { None }), vec![2, 3]); + // assert_seq_equal(e.map_while(|&x| if x < 2 { Some(x + 1) } else { None }), vec![]); + + // merge + let a = a_source.clone(); + let e = e_source.clone(); + assert_seq_equal(a.merge(vec![0, 4, 5]), vec![0, 1, 2, 3, 4, 5]); + assert_seq_equal(e.merge(vec![1]), vec![1]); + let e = e_source.clone(); + assert_seq_equal(e.merge(vec![]), vec![]); + + // merge_by + let a = a_source.clone(); + let e = e_source.clone(); + assert_seq_equal(a.merge_by(vec![0, 4, 5], |l, r| l.cmp(r)), vec![0, 1, 2, 3, 4, 5]); + assert_seq_equal(e.merge_by(vec![1], |l, r| l.cmp(r)), vec![1]); + let e = e_source.clone(); + assert_seq_equal(e.merge_by(vec![], |l, r| l.cmp(r)), vec![]); + + // move_at + let a = a_source.clone(); + let e = e_source.clone(); + assert_seq_equal(a.move_at(0, 2), vec![2, 3, 1]); + let a = a_source.clone(); + assert_seq_equal(a.move_at(2, 1), vec![1, 3, 2]); + let a = a_source.clone(); + assert_seq_equal(a.move_at(1, 1), vec![1, 2, 3]); + assert!(panic::catch_unwind(|| { e.move_at(0, 0) }).is_err()); + + // pad_left - FIXME - implement test + // let a = a_source.clone(); + // let e = e_source.clone(); + // assert_seq_equal(a.pad_left(5, 4), vec![4, 4, 1, 2, 3]); + // assert_seq_equal(e.pad_left(1, 1), vec![1]); + // // rev // assert_equal(repeated.clone().rev(), vec![3, 2, 2, 1]); // assert_equal(empty.clone().rev(), vec![]); diff --git a/tests/extensions/traits.rs b/tests/extensions/traits.rs index 0495445..83bcacd 100644 --- a/tests/extensions/traits.rs +++ b/tests/extensions/traits.rs @@ -62,6 +62,7 @@ where + Extend + Clone + Equal + + UnwindSafe + Debug + 'a, >::This: FromIterator + Default + Extend + Equal + Debug, @@ -89,6 +90,7 @@ where + Extend + Clone + Equal + + UnwindSafe + Debug + 'a, >::This: FromIterator + Default + Extend + Equal + Debug,