From b488d946cf1a1572000ab3e7137946c3d2e9cb32 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Mon, 23 Nov 2020 13:26:20 +0200 Subject: Use explicit starting point --- src/partition.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/partition.rs b/src/partition.rs index 46efeac..3f2837d 100644 --- a/src/partition.rs +++ b/src/partition.rs @@ -41,7 +41,7 @@ mod tests { list![9] ]; - assert_eq!(partition(&|_n| 1, &ins), outs); + assert_eq!(partition(&|_n| 1, ins[0], &ins), outs); } #[test] @@ -49,7 +49,7 @@ mod tests { let ins = vec![1, 2, 3, 4, 5, 6, 7, 8, 9]; let outs = list![list![1, 2], list![3, 4], list![5, 6], list![7, 8], list![9]]; - assert_eq!(partition(&|_n| 2, &ins), outs); + assert_eq!(partition(&|_n| 2, ins[0], &ins), outs); } #[test] @@ -73,7 +73,7 @@ mod tests { list![15] ]; - assert_eq!(partition(&|_n| 1, &ins), outs); + assert_eq!(partition(&|_n| 1, ins[0], &ins), outs); } #[test] @@ -90,7 +90,7 @@ mod tests { list![15] ]; - assert_eq!(partition(&|_n| 2, &ins), outs); + assert_eq!(partition(&|_n| 2, ins[0], &ins), outs); } fn exp2(n: u32) -> i64 { @@ -108,7 +108,7 @@ mod tests { list![8, 9, 10, 11, 12, 13] ]; - assert_eq!(partition(&exp2, &ins), outs); + assert_eq!(partition(&exp2, ins[0], &ins), outs); } #[test] @@ -132,11 +132,11 @@ mod tests { } } -pub fn partition(f: &dyn Fn(u32) -> i64, v: &[i64]) -> LinkedList> { +pub fn partition(f: &dyn Fn(u32) -> i64, v0: i64, v: &[i64]) -> LinkedList> { let mut term: LinkedList = LinkedList::new(); let mut res: LinkedList> = LinkedList::new(); let mut n: u32 = 1; - let mut a: i64 = v[0]; + let mut a: i64 = v0; for &i in v.iter() { while i >= a + f(n) { @@ -168,7 +168,7 @@ pub fn partition_days( v.sort_unstable(); v.dedup(); - part = partition(f, &v); + part = partition(f, v[0], &v); } part.into_iter() -- cgit v1.2.3