Skip to content

Commit

Permalink
Add gen.sh to create Rust stub
Browse files Browse the repository at this point in the history
  • Loading branch information
code-shoily committed Aug 17, 2024
1 parent 382668e commit 1b4c937
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions native/aoc/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/zsh

FULL_YEAR=$1
YEAR=${1:(-2)}
DAY=$(printf '%02d' $2)
SRC_FILE=./src/year_${FULL_YEAR}/day_${YEAR}_${DAY}.rs

if [[ ! -e $SRC_FILE ]]; then
touch "$SRC_FILE"
cat << EOF > "$SRC_FILE"
pub fn solve_${YEAR}_${DAY}(raw_input: String) -> (i32, i32) {
let input = process(&raw_input);
(part_1(&input), part_2(&input))
}
fn process(raw_input: &str) -> Vec<&str> {
raw_input
.trim()
.split('\n')
.collect()
}
fn part_1(input: &[&str]) -> i32 {
input.len() as i32
}
fn part_2(input: &[&str]) -> i32 {
input.len() as i32
}
#[cfg(test)]
mod tests {
use crate::util::io_helpers::read_input_from_resources;
use super::*;
const YEAR: i16 = $1;
const DAY: i8 = $2;
#[test]
fn test_process() {
let given = "hello\nthere";
let expected = vec!["hello", "there"];
assert_eq!(process(given), expected);
}
#[test]
fn test_solution() {
let given = read_input_from_resources(YEAR, DAY, false);
let expected = (3, 3);
assert_eq!(solve_${YEAR}_${DAY}(given), expected);
}
}
EOF
else
echo "Source ${SRC_FILE} already exists"
fi

0 comments on commit 1b4c937

Please sign in to comment.