Skip to content

Commit b0a9770

Browse files
committed
Big clean-up and refactor
Makes most files a little bit shorter, because I removed the test module around it. It was never really needed. Also removed a bunch of the nightly dependencies, could run on stable if we would remove the benchmark stuff (which is still nightly)
1 parent f013084 commit b0a9770

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+348
-783
lines changed

.github/cargo-test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
execute_test() {
4+
for day in "$@"; do
5+
echo "Testing $day"
6+
echo "# Test results for $day" >> $GITHUB_STEP_SUMMARY
7+
cargo test --bin $day --no-fail-fast >> $GITHUB_STEP_SUMMARY
8+
done
9+
}
10+
11+
while IFS= read -r day; do
12+
execute_test "$day";
13+
done < <(
14+
(for filename in src/bin/*.rs; do
15+
filename=${filename#*/*/} # Remove the directory prefix
16+
filename=${filename%.rs} # Remove the extension suffix
17+
echo ${filename:3} $filename
18+
done) | sort -n | cut -d' ' -f 2
19+
)

.github/workflows/rust.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
projects: ["2022", "2023", "2024", "shared"]
13+
projects: ["2022", "2023", "2024"]
1414

1515
steps:
1616
- uses: actions/checkout@v4
@@ -20,4 +20,16 @@ jobs:
2020
uses: Swatinem/rust-cache@v2
2121
- name: Run tests
2222
working-directory: ./${{ matrix.projects }}
23+
run: ../.github/cargo-test.sh
24+
25+
test-shared:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Update Rust to nightly
30+
run: rustup update nightly && rustup default nightly
31+
- name: Setup Rust Cache
32+
uses: Swatinem/rust-cache@v2
33+
- name: Run tests
34+
working-directory: ./shared
2335
run: cargo test --tests --no-fail-fast

2022/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ rayon = "1.10.0"
1717
strip = true
1818
lto = true
1919
panic = "abort"
20-
debug = "none"
20+
debug = "none"

2022/src/bin/day1.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(test)]
22

3-
use advent_lib::day_main;
43
use advent_lib::parsing::double_line_ending;
4+
use advent_lib::*;
55
use nom_parse_macros::parse_from;
66
use std::collections::BinaryHeap;
77

@@ -24,11 +24,5 @@ fn calculate_part1(input: &Input) -> i32 { sums(input).iter().rev().take(1).sum(
2424
fn calculate_part2(input: &Input) -> i32 { sums(input).iter().rev().take(3).sum() }
2525

2626
day_main!();
27-
28-
#[cfg(test)]
29-
mod tests {
30-
use advent_lib::day_test;
31-
32-
day_test!( 1, example => 24000, 45000 );
33-
day_test!( 1 => 68292, 203203);
34-
}
27+
day_test!( 1, example => 24000, 45000 );
28+
day_test!( 1 => 68292, 203203 );

2022/src/bin/day10.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(test)]
2+
#![allow(clippy::ptr_arg)]
23

3-
use advent_lib::day_main;
4+
use advent_lib::*;
45
use nom_parse_macros::parse_from;
56

67
#[parse_from]
@@ -49,23 +50,17 @@ fn calculate_part2(additions: &Vec<i32>) -> String {
4950
}
5051

5152
day_main!( additions => calculate_part1, calculate_part2 );
52-
53-
#[cfg(test)]
54-
mod tests {
55-
use advent_lib::day_test;
56-
57-
day_test!( 10, example => "13140".to_owned(), "
53+
day_test!( 10, example => "13140".to_owned(), "
5854
##..##..##..##..##..##..##..##..##..##..
5955
###...###...###...###...###...###...###.
6056
####....####....####....####....####....
6157
#####.....#####.....#####.....#####.....
6258
######......######......######......####
63-
#######.......#######.......#######.....".to_owned() ; additions );
64-
day_test!( 10 => "15260".to_owned(), "
59+
#######.......#######.......#######.....".to_owned() ; crate::additions );
60+
day_test!( 10 => "15260".to_owned(), "
6561
###...##..#..#.####..##..#....#..#..##..
6662
#..#.#..#.#..#.#....#..#.#....#..#.#..#.
6763
#..#.#....####.###..#....#....#..#.#....
6864
###..#.##.#..#.#....#.##.#....#..#.#.##.
6965
#....#..#.#..#.#....#..#.#....#..#.#..#.
70-
#.....###.#..#.#.....###.####..##...###.".to_owned() ; additions );
71-
}
66+
#.....###.#..#.#.....###.####..##...###.".to_owned() ; crate::additions );

2022/src/bin/day11.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![feature(test)]
22
#![allow(clippy::ptr_arg)]
33

4-
use advent_lib::day_main;
54
use advent_lib::iter_utils::IteratorUtils;
5+
use advent_lib::*;
66
use nom_parse_macros::parse_from;
77
use std::cell::RefCell;
88

@@ -122,11 +122,5 @@ fn calculate(monkeys: &[Monkey], rounds: u32, div: u64) -> u64 {
122122
}
123123

124124
day_main!();
125-
126-
#[cfg(test)]
127-
mod tests {
128-
use advent_lib::day_test;
129-
130-
day_test!( 11, example => 10605, 2713310158 );
131-
day_test!( 11 => 108240, 25712998901 );
132-
}
125+
day_test!( 11, example => 10605, 2713310158 );
126+
day_test!( 11 => 108240, 25712998901 );

2022/src/bin/day12.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![feature(test)]
22

3-
use advent_lib::day_main;
43
use advent_lib::direction::ALL_DIRECTIONS;
54
use advent_lib::grid::{Grid, Location};
65
use advent_lib::parsing::single_match;
76
use advent_lib::search::{a_star_search, SearchGraph, SearchGraphWithGoal};
7+
use advent_lib::*;
88
use nom_parse_macros::parse_from;
99

1010
#[parse_from(map(single_match(AsChar::is_alpha), |value: u8| (value, match value {
@@ -110,11 +110,5 @@ fn calculate_part2(grid: &Grid<Node>) -> usize {
110110
}
111111

112112
day_main!();
113-
114-
#[cfg(test)]
115-
mod tests {
116-
use advent_lib::day_test;
117-
118-
day_test!( 12, example => 31, 29 );
119-
day_test!( 12 => 383, 377 );
120-
}
113+
day_test!( 12, example => 31, 29 );
114+
day_test!( 12 => 383, 377 );

2022/src/bin/day13.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(test)]
22

3-
use advent_lib::day_main;
43
use advent_lib::parsing::single;
4+
use advent_lib::*;
55
use nom::combinator::map;
66
use nom::error::ParseError;
77
use nom::multi::separated_list0;
@@ -125,11 +125,5 @@ impl Ord for Packet {
125125
}
126126

127127
day_main!();
128-
129-
#[cfg(test)]
130-
mod tests {
131-
use advent_lib::day_test;
132-
133-
day_test!( 13, example => 13, 140 );
134-
day_test!( 13 => 5843, 26289 );
135-
}
128+
day_test!( 13, example => 13, 140 );
129+
day_test!( 13 => 5843, 26289 );

2022/src/bin/day14.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#![feature(test)]
22

3-
use advent_lib::day_main;
43
use advent_lib::direction::Direction;
54
use advent_lib::geometry::point2;
65
use advent_lib::grid::Grid;
76
use advent_lib::iter_utils::IteratorUtils;
87
use advent_lib::lines::LineSegment;
8+
use advent_lib::*;
99
use advent_macros::FromRepr;
1010
use nom_parse_macros::parse_from;
1111
use std::ops::Add;
@@ -55,10 +55,10 @@ fn draw_line(grid: &mut Grid<Place>, line: Line, value: Place) {
5555
}
5656
}
5757

58-
fn calculate_part1(grid: &Grid<Place>) -> usize { SandDroppingGrid::new(&grid).count() }
58+
fn calculate_part1(grid: &Grid<Place>) -> usize { SandDroppingGrid::new(grid).count() }
5959

6060
fn calculate_part2(grid: &Grid<Place>) -> usize {
61-
let mut grid = SandDroppingGrid::new(&grid);
61+
let mut grid = SandDroppingGrid::new(grid);
6262
let y = grid.grid.height() - 1;
6363
for x in grid.grid.x_range() {
6464
let place = grid.grid.get_mut(point2(x, y)).unwrap();
@@ -125,11 +125,5 @@ enum Place {
125125
}
126126

127127
day_main!( generate_grid => calculate_part1, calculate_part2 );
128-
129-
#[cfg(test)]
130-
mod tests {
131-
use advent_lib::day_test;
132-
133-
day_test!( 14, example => 24, 93 ; generate_grid );
134-
day_test!( 14 => 843, 27625 ; generate_grid );
135-
}
128+
day_test!( 14, example => 24, 93 ; crate::generate_grid );
129+
day_test!( 14 => 843, 27625 ; crate::generate_grid );

2022/src/bin/day15.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![feature(test)]
22
#![allow(clippy::ptr_arg)]
33

4-
use advent_lib::day_main;
54
use advent_lib::geometry::point2;
5+
use advent_lib::*;
66
use nom_parse_macros::parse_from;
77
use std::ops::RangeInclusive;
88

@@ -77,11 +77,5 @@ fn calculate_part2(sensors: &Vec<Sensor>) -> i64 {
7777
}
7878

7979
day_main!();
80-
81-
#[cfg(test)]
82-
mod tests {
83-
use advent_lib::day_test;
84-
85-
day_test!( 15, example => 26, 56000011 );
86-
day_test!( 15 => 4725496, 12051287042458 );
87-
}
80+
day_test!( 15, example => 26, 56000011 );
81+
day_test!( 15 => 4725496, 12051287042458 );

0 commit comments

Comments
 (0)