mirror of
https://gitlab.com/MisterBiggs/aoc_2015-rust.git
synced 2025-06-16 15:06:49 +00:00
Fixing tests for day 2
This commit is contained in:
parent
21ed9f18b2
commit
dd087b4927
74
src/day2.rs
74
src/day2.rs
@ -5,18 +5,21 @@ pub fn run() {
|
|||||||
println!("Day 2:");
|
println!("Day 2:");
|
||||||
let input = fs::read_to_string("./inputs/day2.txt").expect("Could not read file");
|
let input = fs::read_to_string("./inputs/day2.txt").expect("Could not read file");
|
||||||
|
|
||||||
// let input = "1x1x10\n1x1x10".to_string();
|
let dimensions_list = parse(input);
|
||||||
let dimensions_list = input
|
|
||||||
|
println!("\tPart 1: {}", part1(&dimensions_list));
|
||||||
|
println!("\tPart 2: {}", part2(&dimensions_list));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse(input: String) -> Vec<Vec<usize>> {
|
||||||
|
input
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
c.split('x')
|
c.split('x')
|
||||||
.map(|n| n.parse::<usize>().unwrap())
|
.map(|n| n.parse::<usize>().unwrap())
|
||||||
.collect::<Vec<usize>>()
|
.collect::<Vec<usize>>()
|
||||||
})
|
})
|
||||||
.collect::<Vec<Vec<usize>>>();
|
.collect::<Vec<Vec<usize>>>()
|
||||||
|
|
||||||
println!("\tPart 1: {}", part1(&dimensions_list));
|
|
||||||
println!("\tPart 2: {}", part2(&dimensions_list));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part1(dimensions: &Vec<Vec<usize>>) -> usize {
|
fn part1(dimensions: &Vec<Vec<usize>>) -> usize {
|
||||||
@ -46,45 +49,26 @@ fn part2(dimensions: &Vec<Vec<usize>>) -> usize {
|
|||||||
})
|
})
|
||||||
.sum::<usize>()
|
.sum::<usize>()
|
||||||
}
|
}
|
||||||
// fn part2(directions: &String) -> usize {
|
|
||||||
// let mut floor: isize = 0;
|
|
||||||
|
|
||||||
// for (num, dir) in directions.chars().enumerate() {
|
#[cfg(test)]
|
||||||
// floor += match dir {
|
mod tests {
|
||||||
// '(' => 1,
|
use super::*;
|
||||||
// ')' => -1,
|
|
||||||
// _ => 0,
|
|
||||||
// };
|
|
||||||
|
|
||||||
// if floor == -1 {
|
#[test]
|
||||||
// return num + 1;
|
fn test_part_1() {
|
||||||
// }
|
assert_eq!(part1(&parse("2x3x4".to_string())), 58);
|
||||||
// }
|
assert_eq!(part1(&parse("2x3x4\n".to_string())), 58);
|
||||||
|
assert_eq!(part1(&parse("1x1x10".to_string())), 43);
|
||||||
|
assert_eq!(part1(&parse("1x10x1".to_string())), 43);
|
||||||
|
assert_eq!(part1(&parse("10x1x1".to_string())), 43);
|
||||||
|
}
|
||||||
|
|
||||||
// return directions.len() + 1;
|
#[test]
|
||||||
// }
|
fn test_part_2() {
|
||||||
|
assert_eq!(part2(&parse("2x3x4".to_string())), 34);
|
||||||
// #[cfg(test)]
|
assert_eq!(part2(&parse("2x3x4\n".to_string())), 34);
|
||||||
// mod tests {
|
assert_eq!(part2(&parse("1x1x10".to_string())), 14);
|
||||||
// use super::*;
|
assert_eq!(part2(&parse("1x10x1".to_string())), 14);
|
||||||
|
assert_eq!(part2(&parse("10x1x1".to_string())), 14);
|
||||||
// #[test]
|
}
|
||||||
// fn test_1() {
|
}
|
||||||
// let mut input: String;
|
|
||||||
|
|
||||||
// let input = "2x3x4";
|
|
||||||
// assert_eq!(part1(&input), 0);
|
|
||||||
|
|
||||||
// input = "()()".to_string();
|
|
||||||
// assert_eq!(part1(&input), 0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // #[test]
|
|
||||||
// // fn test_2() {
|
|
||||||
// // let mut input = ")".to_string();
|
|
||||||
// // assert_eq!(part2(&input), 1);
|
|
||||||
|
|
||||||
// // input = "()())".to_string();
|
|
||||||
// // assert_eq!(part2(&input), 5);
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user