Skip to content

Commit cb6f198

Browse files
committed
test(07/2025): add more tests with examples
1 parent 697b489 commit cb6f198

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

src/solutions/year2025/day07.rs

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub struct Day07;
1313

1414
impl Solution for Day07 {
1515
fn part_one(&self, input: &str) -> String {
16-
let grid: Grid<char> = Grid::from(input);
17-
let column_range = grid.columns_range();
16+
let grid = self.parse(input);
17+
let rows_range = grid.rows_range();
1818
let start = grid.get_first_position(&START).unwrap();
1919

2020
let splitters: HashSet<Point> = grid.get_all_positions(&SPLITTER).into_iter().collect();
@@ -45,15 +45,15 @@ impl Solution for Day07 {
4545
continue;
4646
}
4747

48-
if !column_range.contains(down.current().y) {
49-
finished_beams.push(down);
48+
if !rows_range.contains(down.current().y) {
49+
finished_beams.push(current_beam);
5050
continue;
5151
}
5252

5353
current_beams.push_front(down);
5454
}
5555

56-
// print(&grid, &finished_beams);
56+
print(&grid, &finished_beams);
5757

5858
splits.to_string()
5959
}
@@ -63,6 +63,15 @@ impl Solution for Day07 {
6363
}
6464
}
6565

66+
impl Day07 {
67+
fn parse(&self, input: &str) -> Grid<char> {
68+
let without_redundant_lines = input.lines().step_by(2).collect::<Vec<_>>().join("\n");
69+
let input = without_redundant_lines.as_str();
70+
71+
Grid::from(input)
72+
}
73+
}
74+
6675
#[allow(dead_code)]
6776
fn print(grid: &Grid<char>, beams: &[Beam]) {
6877
let mut new = grid.clone();
@@ -195,4 +204,48 @@ mod tests {
195204
assert!(!beam.collides(&Beam::from(Point::new(4, 3))));
196205
assert!(!beam.collides(&Beam::from(Point::new(4, 4))));
197206
}
207+
208+
const EXAMPLE_FROM_REDDIT: &str = r#"..S..
209+
.....
210+
..^..
211+
.....
212+
...^.
213+
.....
214+
.^...
215+
....."#;
216+
217+
#[test]
218+
fn part_one_example_from_reddit() {
219+
assert_eq!("3", Day07.part_one(EXAMPLE_FROM_REDDIT));
220+
}
221+
222+
const MY_EXAMPLE: &str = r#"..S..
223+
.....
224+
..^..
225+
.....
226+
.^.^.
227+
.....
228+
.^.^.
229+
....."#;
230+
231+
#[test]
232+
fn part_one_my_example() {
233+
assert_eq!("3", Day07.part_one(MY_EXAMPLE));
234+
}
235+
236+
const MY_EXAMPLE2: &str = r#"..S..
237+
.....
238+
..^..
239+
.....
240+
.^.^.
241+
.....
242+
..^..
243+
.....
244+
.^.^.
245+
....."#;
246+
247+
#[test]
248+
fn part_one_my_example2() {
249+
assert_eq!("6", Day07.part_one(MY_EXAMPLE2));
250+
}
198251
}

0 commit comments

Comments
 (0)