aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs6
-rw-r--r--src/partition.rs92
2 files changed, 66 insertions, 32 deletions
diff --git a/src/main.rs b/src/main.rs
index d6e6b85..dcffd70 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -43,9 +43,9 @@ fn main() {
let parts: LinkedList<LinkedList<NaiveDate>> =
partition_days(&|n| exponent(args.flag_base, n), &args.arg_day)
- .into_iter()
- .map(|l| l.into_iter().rev().collect())
- .collect();
+ .into_iter()
+ .map(|l| l.into_iter().rev().collect())
+ .collect();
if args.flag_keep {
for days in parts.iter() {
diff --git a/src/partition.rs b/src/partition.rs
index 7e2545f..8197112 100644
--- a/src/partition.rs
+++ b/src/partition.rs
@@ -2,14 +2,14 @@ extern crate chrono;
use std::collections::LinkedList;
-use chrono::NaiveDate;
use chrono::Duration;
+use chrono::NaiveDate;
#[cfg(test)]
mod tests {
- use std::collections::LinkedList;
use chrono::NaiveDate;
+ use std::collections::LinkedList;
use super::partition;
use super::partition_days;
@@ -29,9 +29,17 @@ mod tests {
#[test]
fn all_const1() {
let ins = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
- let outs = list![list![1], list![2], list![3],
- list![4], list![5], list![6],
- list![7], list![8], list![9]];
+ let outs = list![
+ list![1],
+ list![2],
+ list![3],
+ list![4],
+ list![5],
+ list![6],
+ list![7],
+ list![8],
+ list![9]
+ ];
assert_eq!(partition(&|_n| 1, &ins), outs);
}
@@ -39,8 +47,7 @@ mod tests {
#[test]
fn all_const2() {
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]];
+ let outs = list![list![1, 2], list![3, 4], list![5, 6], list![7, 8], list![9]];
assert_eq!(partition(&|_n| 2, &ins), outs);
}
@@ -48,10 +55,23 @@ mod tests {
#[test]
fn odds_const1() {
let ins = vec![1, 3, 5, 7, 9, 11, 13, 15];
- let outs = list![list![1], list![], list![3], list![],
- list![5], list![], list![7], list![],
- list![9], list![], list![11], list![],
- list![13], list![], list![15]];
+ let outs = list![
+ list![1],
+ list![],
+ list![3],
+ list![],
+ list![5],
+ list![],
+ list![7],
+ list![],
+ list![9],
+ list![],
+ list![11],
+ list![],
+ list![13],
+ list![],
+ list![15]
+ ];
assert_eq!(partition(&|_n| 1, &ins), outs);
}
@@ -59,9 +79,16 @@ mod tests {
#[test]
fn odds_const2() {
let ins = vec![1, 3, 5, 7, 9, 11, 13, 15];
- let outs = list![list![1], list![3], list![5],
- list![7], list![9], list![11],
- list![13], list![15]];
+ let outs = list![
+ list![1],
+ list![3],
+ list![5],
+ list![7],
+ list![9],
+ list![11],
+ list![13],
+ list![15]
+ ];
assert_eq!(partition(&|_n| 2, &ins), outs);
}
@@ -74,8 +101,12 @@ mod tests {
#[test]
fn all_exp2() {
let ins = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
- let outs = list![list![1], list![2, 3], list![4, 5, 6, 7],
- list![8, 9, 10, 11, 12, 13]];
+ let outs = list![
+ list![1],
+ list![2, 3],
+ list![4, 5, 6, 7],
+ list![8, 9, 10, 11, 12, 13]
+ ];
assert_eq!(partition(&exp2, &ins), outs);
}
@@ -83,18 +114,24 @@ mod tests {
#[test]
fn dates_exp2() {
let d = NaiveDate::from_ymd;
- let ins = vec![d(2019, 08, 30), d(2019, 08, 31),
- d(2019, 09, 01), d(2019, 09, 02),
- d(2019, 09, 03), d(2019, 09, 04)];
- let outs = list![list![d(2019, 09, 04)],
- list![d(2019, 09, 03), d(2019, 09, 02)],
- list![d(2019, 09, 01), d(2019, 08, 31), d(2019, 08, 30)]];
+ let ins = vec![
+ d(2019, 08, 30),
+ d(2019, 08, 31),
+ d(2019, 09, 01),
+ d(2019, 09, 02),
+ d(2019, 09, 03),
+ d(2019, 09, 04),
+ ];
+ let outs = list![
+ list![d(2019, 09, 04)],
+ list![d(2019, 09, 03), d(2019, 09, 02)],
+ list![d(2019, 09, 01), d(2019, 08, 31), d(2019, 08, 30)]
+ ];
assert_eq!(partition_days(&exp2, &ins), outs);
}
}
-
pub fn partition(f: &dyn Fn(u32) -> i64, v: &Vec<i64>) -> LinkedList<LinkedList<i64>> {
let mut term: LinkedList<i64> = LinkedList::new();
let mut res: LinkedList<LinkedList<i64>> = LinkedList::new();
@@ -134,12 +171,9 @@ pub fn partition_days(
part = partition(f, &v);
}
- let res = part.into_iter()
- .map(|l| {
- l.into_iter()
- .map(|d| day1 - Duration::days(d))
- .collect()
- })
+ let res = part
+ .into_iter()
+ .map(|l| l.into_iter().map(|d| day1 - Duration::days(d)).collect())
.collect();
res