1
1
mirror of https://github.com/theoludwig/advent_of_code_2023.git synced 2024-07-17 07:20:11 +02:00

ci: add automated tests/linting/format

This commit is contained in:
Théo LUDWIG 2023-12-01 17:26:01 +01:00
parent 0c6ebb6ad4
commit 760686db4c
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
12 changed files with 106 additions and 16 deletions

15
.editorconfig Normal file
View File

@ -0,0 +1,15 @@
# https://editorconfig.org/
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.txt]
trim_trailing_whitespace = unset
insert_final_newline = unset

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text=auto eol=lf

24
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: "ci"
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
CARGO_TERM_COLOR: "always"
jobs:
ci:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- run: "rustc --version"
- run: "cargo build --verbose"
- run: "cargo test --verbose"
- run: "cargo clippy --verbose -- -D warnings"
- run: "cargo fmt -- --check"

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

View File

@ -5,3 +5,7 @@ version = 3
[[package]]
name = "day_1"
version = "1.0.0"
[[package]]
name = "day_2"
version = "1.0.0"

6
Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[workspace]
members = [
"day_1",
"day_2",
]
resolver = "2"

View File

@ -2,16 +2,15 @@
## About
This repository contains my solutions to the [Advent of Code 2023](https://adventofcode.com/2023) challenges using the [Rust Programming Language](https://www.rust-lang.org/) v1.74.0.
To run a solution (e.g. Day 1):
This repository contains my solutions for the [Advent of Code 2023](https://adventofcode.com/2023) challenges implemented in the [Rust Programming Language](https://www.rust-lang.org/) v1.74.0.
```sh
cd day_1
cargo run
```
# Run the tests (input examples)
cargo test
**Note:** The solutions are not necessarily optimized for performance or readability, but rather for completing the challenge successfully.
# Run a specific day's challenge (e.g. Day 1)
cargo run --package day_1
```
## License

View File

@ -10,7 +10,7 @@ fn part_1(input: &str) -> i32 {
let first_digit = characters_digits.first().unwrap_or(&'0').to_owned();
let last_digit = characters_digits.last().unwrap_or(&'0').to_owned();
let number = format!("{}{}", first_digit, last_digit);
let number: i32 = number.parse().expect("Should parse as a number.");
let number: i32 = number.parse().expect("Should parse as a i32.");
number
})
.sum()
@ -64,15 +64,23 @@ fn part_2(input: &str) -> i32 {
}
fn main() {
let input_example1 = include_str!("../input_example_1.txt");
let input_example2 = include_str!("../input_example_2.txt");
let input = include_str!("../input.txt");
println!("Answer Part 1 (example1): {}", part_1(input_example1));
println!("Answer Part 1 (example2): {}", part_1(input_example2));
println!("- Day 1: Trebuchet?! -");
println!("Answer Part 1: {}", part_1(input));
println!("Answer Part 2 (example1): {}", part_2(input_example1));
println!("Answer Part 2 (example2): {}", part_2(input_example2));
println!("Answer Part 2: {}", part_2(input));
}
#[cfg(test)]
mod day_1_tests {
use super::*;
#[test]
fn test_part_1_example() {
assert_eq!(142, part_1(include_str!("../input_example_1.txt")));
}
#[test]
fn test_part_2_example() {
assert_eq!(281, part_2(include_str!("../input_example_2.txt")));
}
}

1
day_2/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

6
day_2/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "day_2"
version = "1.0.0"
edition = "2021"
[dependencies]

7
day_2/README.md Normal file
View File

@ -0,0 +1,7 @@
# - Day 2 -
Source: <https://adventofcode.com/2023/day/2>
## Instructions - Part 1
## Instructions - Part 2

18
day_2/src/main.rs Normal file
View File

@ -0,0 +1,18 @@
fn part_1() -> i32 {
142
}
fn main() {
println!("- Day 2: Title -");
println!("Answer Part 1: {}", part_1());
}
#[cfg(test)]
mod day_2_tests {
use super::*;
#[test]
fn test_part_1_example() {
assert_eq!(142, part_1());
}
}