@@ -4,15 +4,21 @@ if [ -z "$1" ]; then
4
4
echo " Usage: ./create_challenge.sh <challenge_name>"
5
5
exit 1
6
6
fi
7
-
7
+ ROOT_CHALLENGE_NAME=rust-coding-challenges
8
8
CHALLENGE_NAME=$1
9
9
AUTHOR_NAME=$2
10
10
CHALLENGE_DIR=" challenges/$CHALLENGE_NAME "
11
11
12
12
# Create a new Cargo project for the challenge
13
13
cargo new --lib " $CHALLENGE_DIR "
14
14
15
- # Create the main.rs file in the challenge directory
15
+ # Add the rust-coding-challenges dependency
16
+
17
+ CHALLENGE_CARGO_TOML=$CHALLENGE_DIR /Cargo.toml
18
+ echo " Adding root project dependency to $CHALLENGE_CARGO_TOML "
19
+ sed -i ' ' ' /\[dependencies\]/a \
20
+ rust-coding-challenges = { path = "../../" }' " $CHALLENGE_CARGO_TOML "
21
+
16
22
cat << EOT > "$CHALLENGE_DIR /src/main.rs"
17
23
use rust_coding_challenges::utils::read_text_file_from_args;
18
24
@@ -25,26 +31,42 @@ fn main() -> std::io::Result<()> {
25
31
}
26
32
EOT
27
33
34
+ # Create the lib.rs file with a sample solve function
35
+ cat << EOL > "$CHALLENGE_DIR /src/lib.rs"
36
+ pub fn solve() -> Result<(), String> {
37
+ // TODO: Implement the solution for $CHALLENGE_NAME
38
+ Ok(())
39
+ }
40
+ EOL
41
+
42
+ # Create the tests directory and test.rs file with a sample test case
28
43
# Create the test file for the challenge
29
44
mkdir -p " $CHALLENGE_DIR /tests/inputs"
30
45
31
- cat << EOT > "$CHALLENGE_DIR /tests/test.rs"
46
+ cat << EOL > "$CHALLENGE_DIR /tests/test.rs"
32
47
#[cfg(test)]
33
48
mod tests {
49
+ use super::*;
50
+ use $CHALLENGE_NAME ::solve;
34
51
35
52
#[test]
36
- fn test() {
53
+ fn test_solve() {
54
+ // Call the solve function and check for expected results
55
+ let result = solve();
56
+ assert!(result.is_ok());
57
+ // Add more assertions based on expected behavior
37
58
}
38
59
}
39
- EOT
60
+ EOL
61
+
40
62
41
63
# Create the README.md file
42
64
README_PATH=" $CHALLENGE_DIR /README.md"
43
65
echo " # $CHALLENGE_NAME " > " $README_PATH "
44
66
echo " " >> " $README_PATH "
45
67
echo " ## Given By $AUTHOR_NAME " >> " $README_PATH "
46
68
echo " " >> " $README_PATH "
47
- echo " ## Relevant Background Knowledge " >> " $README_PATH "
69
+ echo " ## Topics " >> " $README_PATH "
48
70
echo " " >> " $README_PATH "
49
71
echo " ## Main Functions" >> " $README_PATH "
50
72
echo " " >> " $README_PATH "
0 commit comments