-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_leetcode_structure.sh
More file actions
executable file
·62 lines (52 loc) · 2.12 KB
/
create_leetcode_structure.sh
File metadata and controls
executable file
·62 lines (52 loc) · 2.12 KB
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
59
60
61
62
#!/bin/bash
# Check if exactly three arguments are passed
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <question number> <QuestionTitle> <Topic>"
exit 1
fi
# Assign input parameters to variables
question_number=$1
question_title=$2
question_topic=$3
# Remove spaces and special characters from the question title
cleaned_title=$(echo "$question_title" | sed 's/[^a-zA-Z0-9]//g')
# Define the directory paths
leetcode_dir="src/main/java/leetcode/${question_topic}/q${question_number}"
tests_dir="src/test/java/leetcode/${question_topic}/q${question_number}"
# Define the file paths
leetcode_file="${leetcode_dir}/${cleaned_title}.java"
tests_file="${tests_dir}/${cleaned_title}Tests.java"
readme_file="${leetcode_dir}/README.md"
# Create the directories if they don't exist
mkdir -p "$leetcode_dir"
mkdir -p "$tests_dir"
# Create the main.java.leetcode file if it doesn't exist and add default content
if [ ! -f "$leetcode_file" ]; then
echo "package leetcode.${question_topic}.q${question_number};" > "$leetcode_file"
echo "public class ${cleaned_title} {" >> "$leetcode_file"
echo "}" >> "$leetcode_file"
fi
# Create the test file if it doesn't exist and add default content
if [ ! -f "$tests_file" ]; then
echo "package leetcode.${question_topic}.q${question_number};" > "$tests_file"
echo "" >> "$tests_file"
echo "import static org.junit.jupiter.api.Assertions.*;" >> "$tests_file"
echo "import org.junit.jupiter.api.Test;" >> "$tests_file"
echo "import leetcode.${question_topic}.q${question_number}.${cleaned_title};" >> "$tests_file"
echo "" >> "$tests_file"
echo "public class ${cleaned_title}Tests {" >> "$tests_file"
echo " @Test" >> "$tests_file"
echo " public void testFoo() {" >> "$tests_file"
echo " ${cleaned_title} ob = new ${cleaned_title}();" >> "$tests_file"
echo " assertEquals(1 + 1, 2);" >> "$tests_file"
echo " }" >> "$tests_file"
echo "}" >> "$tests_file"
fi
# Create the README.md file if it doesn't exist
if [ ! -f "$readme_file" ]; then
touch "$readme_file"
fi
# Print the created file paths
echo "Created: $leetcode_file"
echo "Created: $tests_file"
echo "Created: $readme_file"