Skip to content

Commit 95a5fe9

Browse files
committed
Update script, adding new wc challenge
1 parent b13e1d1 commit 95a5fe9

File tree

14 files changed

+134
-7
lines changed

14 files changed

+134
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
.idea

Cargo.lock

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ version = "0.1.0"
44
edition = "2021"
55

66
[workspace]
7-
members = [ "challenges/simple-parser" ]
7+
members = [ "challenges/foo", "challenges/simple-parser" , "challenges/wc-command"]
88

99
[dependencies]

challenges/foo/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "foo"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rust-coding-challenges = { path = "../../" }

challenges/foo/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# foo
2+
3+
## Given By
4+
5+
## Topics
6+
7+
## Main Functions
8+
9+
## Example Output
10+
11+
## Usage Example
12+

challenges/foo/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub fn solve() -> Result<(), String> {
2+
// TODO: Implement the solution for foo
3+
Ok(())
4+
}

challenges/foo/src/main.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use foo::solve;
2+
use rust_coding_challenges::utils::read_text_file_from_args;
3+
4+
fn main() -> std::io::Result<()> {
5+
let content = read_text_file_from_args()?;
6+
7+
// Print results or perform other actions as needed
8+
Ok(())
9+
}

challenges/foo/tests/test.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use super::*;
4+
use foo::solve;
5+
6+
#[test]
7+
fn test_solve() {
8+
// Call the solve function and check for expected results
9+
let result = solve();
10+
assert!(result.is_ok());
11+
// Add more assertions based on expected behavior
12+
}
13+
}

challenges/wc-command/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "wc-command"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rust-coding-challenges = { path = "../../" }

challenges/wc-command/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# wc-command
2+
3+
## Given By
4+
5+
## Relevant Background Knowledge
6+
7+
## Main Functions
8+
9+
## Example Output
10+
11+
## Usage Example
12+

challenges/wc-command/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: u64, right: u64) -> u64 {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

challenges/wc-command/src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use rust_coding_challenges::utils::read_text_file_from_args;
2+
3+
fn main() -> std::io::Result<()> {
4+
Ok(())
5+
}

challenges/wc-command/tests/test.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[cfg(test)]
2+
mod tests {
3+
4+
#[test]
5+
fn test() {
6+
}
7+
}

scripts/create_challenge.sh

+28-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ if [ -z "$1" ]; then
44
echo "Usage: ./create_challenge.sh <challenge_name>"
55
exit 1
66
fi
7-
7+
ROOT_CHALLENGE_NAME=rust-coding-challenges
88
CHALLENGE_NAME=$1
99
AUTHOR_NAME=$2
1010
CHALLENGE_DIR="challenges/$CHALLENGE_NAME"
1111

1212
# Create a new Cargo project for the challenge
1313
cargo new --lib "$CHALLENGE_DIR"
1414

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+
1622
cat <<EOT > "$CHALLENGE_DIR/src/main.rs"
1723
use rust_coding_challenges::utils::read_text_file_from_args;
1824
@@ -25,26 +31,42 @@ fn main() -> std::io::Result<()> {
2531
}
2632
EOT
2733

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
2843
# Create the test file for the challenge
2944
mkdir -p "$CHALLENGE_DIR/tests/inputs"
3045

31-
cat <<EOT > "$CHALLENGE_DIR/tests/test.rs"
46+
cat <<EOL > "$CHALLENGE_DIR/tests/test.rs"
3247
#[cfg(test)]
3348
mod tests {
49+
use super::*;
50+
use $CHALLENGE_NAME::solve;
3451
3552
#[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
3758
}
3859
}
39-
EOT
60+
EOL
61+
4062

4163
# Create the README.md file
4264
README_PATH="$CHALLENGE_DIR/README.md"
4365
echo "# $CHALLENGE_NAME" > "$README_PATH"
4466
echo "" >> "$README_PATH"
4567
echo "## Given By $AUTHOR_NAME" >> "$README_PATH"
4668
echo "" >> "$README_PATH"
47-
echo "## Relevant Background Knowledge" >> "$README_PATH"
69+
echo "## Topics" >> "$README_PATH"
4870
echo "" >> "$README_PATH"
4971
echo "## Main Functions" >> "$README_PATH"
5072
echo "" >> "$README_PATH"

0 commit comments

Comments
 (0)