From d9f9fb48ed4d766b1945f29322d43ee60fe4290f Mon Sep 17 00:00:00 2001 From: genofire Date: Mon, 7 Sep 2020 21:36:04 +0200 Subject: [PATCH] 2019 - day1 - part 2: beautily full --- 2019/day1/src/main.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/2019/day1/src/main.rs b/2019/day1/src/main.rs index 42153da..cc698de 100644 --- a/2019/day1/src/main.rs +++ b/2019/day1/src/main.rs @@ -19,25 +19,30 @@ fn main() { //all_modules.map(fuel_calc).sum() //all_modules.map(fuel_calc).sum() - println!("Part2: I need {} fuel for all modules", all_modules.iter().fold(0, |sum, x | fuel_calc_with_fuel(*x) + sum )); + println!("Part2: I need {} fuel for all modules", all_modules.iter().fold(0, |sum, x | fuel_tyranny(*x) + sum )); } fn fuel_calc(mass: i32) -> i32 { mass / 3 - 2 } -fn fuel_calc_with_fuel(mass: i32) -> i32 { +fn fuel_tyranny(mass: i32) -> i32 { let fuel = fuel_calc(mass); if fuel <= 0 { return 0; } - fuel+fuel_calc_with_fuel(fuel) + fuel+fuel_tyranny(fuel) } -#[test] -fn test_it() { - assert_eq!(fuel_calc(12), 2); - assert_eq!(fuel_calc(14), 2); - assert_eq!(fuel_calc(1969), 654); - assert_eq!(fuel_calc(100756), 33583); +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_it() { + assert_eq!(fuel_calc(12), 2); + assert_eq!(fuel_calc(14), 2); + assert_eq!(fuel_calc(1969), 654); + assert_eq!(fuel_calc(100756), 33583); + } }