1
0
mirror of https://gitlab.com/MisterBiggs/aoc_2015-rust.git synced 2025-06-15 22:46:43 +00:00

Fixing tests for day 2

This commit is contained in:
Anson 2022-11-04 10:22:42 -06:00
parent 21ed9f18b2
commit dd087b4927

View File

@ -5,18 +5,21 @@ pub fn run() {
println!("Day 2:");
let input = fs::read_to_string("./inputs/day2.txt").expect("Could not read file");
// let input = "1x1x10\n1x1x10".to_string();
let dimensions_list = input
let dimensions_list = parse(input);
println!("\tPart 1: {}", part1(&dimensions_list));
println!("\tPart 2: {}", part2(&dimensions_list));
}
fn parse(input: String) -> Vec<Vec<usize>> {
input
.split_whitespace()
.map(|c| {
c.split('x')
.map(|n| n.parse::<usize>().unwrap())
.collect::<Vec<usize>>()
})
.collect::<Vec<Vec<usize>>>();
println!("\tPart 1: {}", part1(&dimensions_list));
println!("\tPart 2: {}", part2(&dimensions_list));
.collect::<Vec<Vec<usize>>>()
}
fn part1(dimensions: &Vec<Vec<usize>>) -> usize {
@ -46,45 +49,26 @@ fn part2(dimensions: &Vec<Vec<usize>>) -> usize {
})
.sum::<usize>()
}
// fn part2(directions: &String) -> usize {
// let mut floor: isize = 0;
// for (num, dir) in directions.chars().enumerate() {
// floor += match dir {
// '(' => 1,
// ')' => -1,
// _ => 0,
// };
#[cfg(test)]
mod tests {
use super::*;
// if floor == -1 {
// return num + 1;
// }
// }
#[test]
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;
// }
// #[cfg(test)]
// mod tests {
// use super::*;
// #[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);
// // }
// }
#[test]
fn test_part_2() {
assert_eq!(part2(&parse("2x3x4".to_string())), 34);
assert_eq!(part2(&parse("2x3x4\n".to_string())), 34);
assert_eq!(part2(&parse("1x1x10".to_string())), 14);
assert_eq!(part2(&parse("1x10x1".to_string())), 14);
assert_eq!(part2(&parse("10x1x1".to_string())), 14);
}
}