Skip to content

Commit a74a919

Browse files
committed
fix auto.ps1
1 parent 7da0891 commit a74a919

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

1.81 KB
Binary file not shown.
1.24 KB
Binary file not shown.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ LeetCode
112112
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [C#](./Algorithms/SymmetricTree.cs)|Easy|
113113
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/description/) | [C#](./Algorithms/BinaryTreeLevelOrderTraversal.cs)|Medium|
114114
|103|[Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/description/) | [C#](./Algorithms/BinaryTreeZigzagLevelOrderTraversal.cs)|Medium|
115+
|104|[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/description/) | [C#](./Algorithms/MaximumDepthofBinaryTree.cs)|Easy|

Scripts/auto.ps1

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ else{
3737
}
3838
$JSONSTART = $JSON.IndexOf("=") + 1
3939
$JSONLENGTH = $JSON.LastIndexOf(";") - $JSONSTART
40-
$JSON = $JSON.Substring($JSONSTART,$JSONLENGTH).Trim().Replace("\u003D","=").Replace("\u003B",";").Replace("\u003C","<").Replace("\u003E",">").Replace("\u000A","`n").Replace("\u000D","`n").Replace("\u000D\u000A","`n").Replace("\u0022","""")
40+
$JSON = $JSON.Substring($JSONSTART,$JSONLENGTH).Trim().Replace("\u003D","=").Replace("\u003B",";").Replace("\u003C","<").Replace("\u003E",">").Replace("\u000A","`n").Replace("\u000D","`n").Replace("\u000D\u000A","`n").Replace("\u0022","""").Replace("\u002D","-")
4141
$AUTHOR = $command
4242
$CURRENT_DATE = Get-Date -format F
4343
$NUM = $QuestionTitle.Split(".")[0].Trim().PadLeft(3).Replace(" ", "0")
@@ -46,10 +46,10 @@ $FILE = $TITLE.Replace(" ", "") + ".cs"
4646
$TESTFILE = $TITLE.Replace(" ", "") + "Test.cs"
4747
if ($IsWindows)
4848
{
49-
$START = $JSON.IndexOf("[{")
49+
$START = $JSON.IndexOf("codeDefinition: [{")
5050
$END = $JSON.IndexOf("},],")
5151
$JSON = $JSON.Remove($END).Trim() + "}]"
52-
$CODE = $JSON.Substring($START)
52+
$CODE = $JSON.Substring($START + 16)
5353
}
5454
else {
5555
$pattern = "(?s)\[\{'.*\},\]"
@@ -66,7 +66,7 @@ $FunName = $FuncInfo.Trim().Split(' ')[2].Substring(0,$FuncInfo.Trim().Split(' '
6666
$Params = $FuncInfo.Trim().Substring($FuncInfo.Trim().IndexOf('(')).Replace("(","").Replace(")","")
6767
$CLASS = $CLASS.Insert($CLASS.IndexOf("Solution") + 8, $NUM)
6868
$CLASS = $CLASS.Insert($CLASS.LastIndexOf("public") + 7, "static ")
69-
$CLASS = $CLASS.Insert($CLASS.IndexOf(") {") + 4, "throw new NotImplementedException(`"TODO`");")
69+
$CLASS = $CLASS.Insert($CLASS.LastIndexOf(") {") + 12, "throw new NotImplementedException(`"TODO`");")
7070
$COMMENT += "$COMMENT_TAG Source : $URL `n"
7171
$COMMENT += "$COMMENT_TAG Author : $AUTHOR `n"
7272
$COMMENT += "$COMMENT_TAG Date : $CURRENT_DATE `n"
@@ -88,16 +88,27 @@ $COMMENT += $CLASS
8888
$COMMENT += "}`n"
8989
$COMMENT > ../Algorithms/$FILE
9090

91+
$Argument = ($Params.Split(',') | foreach{$_.Trim().Split(' ')[1]}) -join ", "
9192
$TESTCLASSNAME = $TITLE.Replace(" ", "") + "Test"
9293
$TESTCLASS = "using System;`nusing System.Collections.Generic;`nusing Algorithms;`nusing Algorithms.Utils;`nusing Xunit;`nnamespace AlgorithmsTest`n{`n"
9394
$TESTCLASS += " public class $TESTCLASSNAME`n"
9495
$TESTCLASS += " {`n"
9596
$TESTCLASS += " [Theory]`n"
9697
$TESTCLASS += " [InlineData()]`n"
98+
$TESTCLASS += " [MemberData(nameof(InlineData))]`n"
9799
$TESTCLASS += " public void TestMethod($Params, $ReturnType output)`n"
98100
$TESTCLASS += " {`n"
99-
$TESTCLASS += " Assert.Equal(output, Solution$NUM.$FunName());`n"
101+
$TESTCLASS += " Assert.Equal(output, Solution$NUM.$FunName($Argument));`n"
100102
$TESTCLASS += " }`n"
103+
$TESTCLASS += " `n"
104+
$TESTCLASS += " public static IEnumerable<object[]> InlineData`n"
105+
$TESTCLASS += " {`n"
106+
$TESTCLASS += " get`n"
107+
$TESTCLASS += " {`n"
108+
$TESTCLASS += " var driverData = new List<object[]>();`n"
109+
$TESTCLASS += " return driverData;`n"
110+
$TESTCLASS += " }`n"
111+
$TESTCLASS += " }`n"
101112
$TESTCLASS += " }`n"
102113
$TESTCLASS += "}`n"
103114
$TESTCLASS > ../AlgorithmsTest/$TESTFILE

0 commit comments

Comments
 (0)