-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_problem.bash
109 lines (86 loc) · 2.42 KB
/
create_problem.bash
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Check if the problem number is passed as an argument
if [ -z "$1" ]; then
echo "Please provide a problem number and problem name (e.g., ./create_problem.sh '1. Two Sum')"
exit 1
fi
# Problem number passed as the first argument
problem_number=$(echo "$1" | cut -d'.' -f1) # "1. Two Sum" -> "1"
problem_title=$1 # "1. Two Sum"
formatted_number=$(printf "%04d" "$problem_number") # "1" -> "0001"
# Base directory where problems will be stored
base_dir="Problems"
problem_dir="${base_dir}/${formatted_number}"
# Create the directory if it doesn't exist
mkdir -p "$problem_dir"
# solution.go faylini yaratish
solution_file="$problem_dir/solution.go"
echo "package problem$formatted_number" > "$solution_file"
# solution_test.go faylini yaratish
test_file="$problem_dir/solution_test.go"
cat <<EOL > "$test_file"
package problem${formatted_number}_test
import (
"testing"
problem${formatted_number} "github.com/realtemirov/leetcode/Problems/${formatted_number}"
"github.com/stretchr/testify/require"
)
func TestSolution(t *testing.T) {
testCases := []struct {
name string
cases []int
expected int
}{
{
name: "Test 1",
cases: []int{},
expected: 0,
},
{
name: "Test 2",
cases: []int{},
expected: 0,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := problem${formatted_number}.Solution(tc.cases)
require.Equal(t, tc.expected, result, "expected: %v, result: %v", tc.expected, result)
})
}
}
EOL
# notes.md faylini yaratish
notes_file="$problem_dir/$problem_title.md"
cat <<EOL > "$notes_file"
# $problem_title
🟩 Easy | 🟧 Medium | 🟥 Hard
## Solution
My Solution
\`\`\`go
\`\`\`

Leetcode: [link]()
EOL
# Print success message
echo "Folder and files for problem $problem_number created successfully in $problem_dir"
# # Open VS Code
# cd "$problem_dir"
# code "$problem_title.md"
# code "solution.go"
# code "solution_test.go"
# cd ../
# Adding to README.md
readme_file="Problems/README.md"
cat <<EOL >> "$readme_file"
* 🟩 Easy | 🟧 Medium | 🟥 Hard - [${problem_title}](<./${formatted_number}/${problem_title}.md>)
EOL
# Print success message
echo "README.md updated successfully"
# Adding to SUMMARY.md
summary_file="SUMMARY.md"
cat <<EOL >> "$summary_file"
* [${problem_title}](<./Problems/${formatted_number}/${problem_title}.md>)
EOL
# Print success message
echo "SUMMARY.md updated successfully"