feat(utils, templates, docs): file-based templates + stronger README
This commit is contained in:
24
templates/problem/test/SolutionTests.cs.tmpl
Normal file
24
templates/problem/test/SolutionTests.cs.tmpl
Normal file
@@ -0,0 +1,24 @@
|
||||
// LeetCode {{NUMBER}} 單元測試(xUnit)
|
||||
|
||||
using Xunit;
|
||||
|
||||
public class SolutionTests {
|
||||
private readonly Solution _s = new Solution();
|
||||
|
||||
[Fact]
|
||||
public void Example1() {
|
||||
// TODO: Arrange
|
||||
// var input = new int[] { };
|
||||
// var expected = 0;
|
||||
// Act
|
||||
// var got = _s.Solve(input);
|
||||
// Assert.Equal(expected, got);
|
||||
Assert.True(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EdgeCases() {
|
||||
Assert.True(true);
|
||||
}
|
||||
}
|
||||
|
19
templates/problem/test/TestProject.csproj.tmpl
Normal file
19
templates/problem/test/TestProject.csproj.tmpl
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../csharp/csharp.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
20
templates/problem/test/edge_cases.md.tmpl
Normal file
20
templates/problem/test/edge_cases.md.tmpl
Normal file
@@ -0,0 +1,20 @@
|
||||
# 邊界情況清單({{NUMBER}} {{NAME_TITLE}})
|
||||
|
||||
## 需要測試的邊界
|
||||
- [ ] 空輸入 / 單一元素
|
||||
- [ ] 重複元素 / 全相同
|
||||
- [ ] 極值(最小/最大)
|
||||
- [ ] 含負數 / 0 / 大數
|
||||
- [ ] 大資料量(接近上限)
|
||||
|
||||
## 額外案例
|
||||
### 案例 1
|
||||
- 輸入:
|
||||
- 預期:
|
||||
- 說明:
|
||||
|
||||
### 案例 2
|
||||
- 輸入:
|
||||
- 預期:
|
||||
- 說明:
|
||||
|
2
templates/problem/test/input1.txt.tmpl
Normal file
2
templates/problem/test/input1.txt.tmpl
Normal file
@@ -0,0 +1,2 @@
|
||||
# 測試案例 1 輸入({{NUMBER}} {{NAME_TITLE}})
|
||||
|
2
templates/problem/test/input2.txt.tmpl
Normal file
2
templates/problem/test/input2.txt.tmpl
Normal file
@@ -0,0 +1,2 @@
|
||||
# 測試案例 2 輸入({{NUMBER}} {{NAME_TITLE}})
|
||||
|
12
templates/problem/test/main_test.go.tmpl
Normal file
12
templates/problem/test/main_test.go.tmpl
Normal file
@@ -0,0 +1,12 @@
|
||||
// LeetCode {{NUMBER}} 單元測試(Go testing)
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestExample(t *testing.T) {
|
||||
// TODO: input := []int{}
|
||||
// got := solve(input)
|
||||
// want := 0
|
||||
// if got != want { t.Fatalf("want %v got %v", want, got) }
|
||||
}
|
||||
|
2
templates/problem/test/output1.txt.tmpl
Normal file
2
templates/problem/test/output1.txt.tmpl
Normal file
@@ -0,0 +1,2 @@
|
||||
# 測試案例 1 期望輸出({{NUMBER}} {{NAME_TITLE}})
|
||||
|
2
templates/problem/test/output2.txt.tmpl
Normal file
2
templates/problem/test/output2.txt.tmpl
Normal file
@@ -0,0 +1,2 @@
|
||||
# 測試案例 2 期望輸出({{NUMBER}} {{NAME_TITLE}})
|
||||
|
36
templates/problem/test/run_tests.sh.tmpl
Normal file
36
templates/problem/test/run_tests.sh.tmpl
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "🧪 執行測試: {{NUMBER_PAD}}-{{NAME_SLUG}}"
|
||||
echo "=========================="
|
||||
|
||||
pushd "$(dirname "$0")" >/dev/null
|
||||
|
||||
echo "📋 C# 測試結果:"
|
||||
if (cd ../csharp && dotnet build >/dev/null 2>&1); then
|
||||
if dotnet test --logger "console;verbosity=minimal" >/dev/null 2>&1; then
|
||||
echo "✅ C# 測試通過"
|
||||
else
|
||||
echo "❌ C# 測試失敗"
|
||||
fi
|
||||
else
|
||||
echo "❌ C# 編譯失敗"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "📋 Go 測試結果:"
|
||||
if (cd ../go && go build >/dev/null 2>&1); then
|
||||
if go test -v >/dev/null 2>&1; then
|
||||
echo "✅ Go 測試通過"
|
||||
else
|
||||
echo "❌ Go 測試失敗(顯示詳細)"
|
||||
go test -v
|
||||
fi
|
||||
else
|
||||
echo "❌ Go 編譯失敗"
|
||||
fi
|
||||
|
||||
popd >/dev/null
|
||||
echo ""
|
||||
echo "📊 測試完成!"
|
||||
|
Reference in New Issue
Block a user