-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgen.sh
58 lines (47 loc) · 1.14 KB
/
gen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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