feat(utils): add global test runner and helper help

This commit is contained in:
2025-09-12 10:19:47 +08:00
parent 9ff736e11c
commit 6d9993cd9f
14 changed files with 199 additions and 325 deletions

View File

@@ -47,6 +47,34 @@ render_template() {
"$src" > "$dest"
}
# 顯示說明
show_help() {
cat << EOF
LeetCode Practice Helper
用法:
$0 problem <題號> <題目名稱-kebab> <難度>
$0 log [YYYY-MM]
$0 readme
$0 -h | --help
說明:
problem 建立新題目(會建立 C#/Go 骨架、測試模板與 README
log 建立月度學習日誌(預設為本月,或指定 YYYY-MM
readme 顯示題目數量統計(可擴充為寫回 README
範例:
$0 problem 1 two-sum Easy
$0 problem 3025 find-the-number-of-ways-to-place-people-i Medium
$0 log 2025-09
$0 readme
測試:
建議使用 utils/run_tests.sh 執行,例:
utils/run_tests.sh 3025 [all|csharp|go]
EOF
}
# 建立測試檔案(來自 templates/problem/test/*
create_test_files() {
local problem_dir="$1"; local number="$2"; local name_slug="$3"; local difficulty="$4"
@@ -71,10 +99,7 @@ create_test_files() {
"$problem_dir/test/edge_cases.md" \
"$number" "$number_pad" "$name_slug" "$name_title" "$difficulty" "$today" "$year_month"
render_template "$TEMPLATES_DIR/problem/test/run_tests.sh.tmpl" \
"$problem_dir/test/run_tests.sh" \
"$number" "$number_pad" "$name_slug" "$name_title" "$difficulty" "$today" "$year_month"
chmod +x "$problem_dir/test/run_tests.sh"
# 不再產生每題的 run_tests.sh請改用 utils/run_tests.sh
}
# 建立新題目
@@ -118,7 +143,7 @@ create_problem() {
echo "✅ 已建立題目: $problem_dir"
echo "C#: cd problems/${folder_name}/csharp && dotnet run"
echo "Go: cd problems/${folder_name}/go && go run main.go"
echo "測試: cd problems/${folder_name}/test && ./run_tests.sh"
echo "測試: utils/run_tests.sh ${number_pad}-${name_slug} [all|csharp|go]"
}
# 更新主 README目前僅統計列印
@@ -143,6 +168,13 @@ create_monthly_log() {
}
# 入口
# --help
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
show_help
exit 0
fi
case "${1:-}" in
problem)
create_problem "${2:-}" "${3:-}" "${4:-}" ;;
@@ -151,10 +183,6 @@ case "${1:-}" in
log)
create_monthly_log "${2:-}" ;;
*)
echo "LeetCode Practice Helper"
echo "使用:"
echo " $0 problem <題號> <題目名稱-kebab> <難度>"
echo " $0 readme"
echo " $0 log [YYYY-MM]"
show_help
;;
esac