Add test by lines for part1
This commit is contained in:
parent
50478acd7f
commit
1137f8dc8b
|
@ -1,15 +1,5 @@
|
||||||
use regex::{Match, Regex};
|
use regex::{Match, Regex};
|
||||||
|
|
||||||
pub fn main(input: &str) -> i32 {
|
|
||||||
let bag = Contents {
|
|
||||||
red: 12,
|
|
||||||
green: 13,
|
|
||||||
blue: 14,
|
|
||||||
};
|
|
||||||
let games = Games::new(input, bag);
|
|
||||||
games.valid_sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Games {
|
struct Games {
|
||||||
games: Vec<Game>,
|
games: Vec<Game>,
|
||||||
}
|
}
|
||||||
|
@ -125,18 +115,38 @@ impl Contents {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn main(input: &str) -> i32 {
|
||||||
|
let bag = Contents {
|
||||||
|
red: 12,
|
||||||
|
green: 13,
|
||||||
|
blue: 14,
|
||||||
|
};
|
||||||
|
let games = Games::new(input, bag);
|
||||||
|
games.valid_sum()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
const BAG: Contents = Contents {
|
||||||
#[test]
|
red: 12,
|
||||||
fn example() {
|
green: 13,
|
||||||
let input = "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
blue: 14,
|
||||||
|
};
|
||||||
|
const INPUT: &str = "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
|
||||||
assert_eq!(main(input), 8);
|
|
||||||
|
#[test]
|
||||||
|
fn example() {
|
||||||
|
assert_eq!(main(INPUT), 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn by_line() {
|
||||||
|
assert_eq!(Games::new(INPUT, BAG).valid_games(), vec![1, 2, 5])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue