File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/zsh
2+
3+ FULL_YEAR=$1
4+ YEAR=${1: (-2)}
5+ DAY=$( printf ' %02d' $2 )
6+ SRC_FILE=./src/year_${FULL_YEAR} /day_${YEAR} _${DAY} .rs
7+
8+ if [[ ! -e $SRC_FILE ]]; then
9+ touch " $SRC_FILE "
10+ cat << EOF > "$SRC_FILE "
11+ pub fn solve_${YEAR} _${DAY} (raw_input: String) -> (i32, i32) {
12+ let input = process(&raw_input);
13+ (part_1(&input), part_2(&input))
14+ }
15+
16+ fn process(raw_input: &str) -> Vec<&str> {
17+ raw_input
18+ .trim()
19+ .split('\n')
20+ .collect()
21+ }
22+
23+ fn part_1(input: &[&str]) -> i32 {
24+ input.len() as i32
25+ }
26+
27+ fn part_2(input: &[&str]) -> i32 {
28+ input.len() as i32
29+ }
30+
31+ #[cfg(test)]
32+ mod tests {
33+ use crate::util::io_helpers::read_input_from_resources;
34+ use super::*;
35+
36+ const YEAR: i16 = $1 ;
37+ const DAY: i8 = $2 ;
38+
39+ #[test]
40+ fn test_process() {
41+ let given = "hello\nthere";
42+ let expected = vec!["hello", "there"];
43+
44+ assert_eq!(process(given), expected);
45+ }
46+
47+ #[test]
48+ fn test_solution() {
49+ let given = read_input_from_resources(YEAR, DAY, false);
50+ let expected = (3, 3);
51+
52+ assert_eq!(solve_${YEAR} _${DAY} (given), expected);
53+ }
54+ }
55+ EOF
56+ else
57+ echo " Source ${SRC_FILE} already exists"
58+ fi
You can’t perform that action at this time.
0 commit comments