From c62e7a9706ef666128a6fc484512fbe632f61ea3 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sun, 18 Feb 2024 14:47:25 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LeetCodeSharp.Tests.csproj | 27 +++++++++++++++++++ LeetCodeSharp.Tests/P589Tests.cs | 22 +++++++++++++++ LeetCodeSharp.sln | 10 +++++-- LeetCodeSharp/Utils/Node.cs | 1 + 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 LeetCodeSharp.Tests/LeetCodeSharp.Tests.csproj create mode 100644 LeetCodeSharp.Tests/P589Tests.cs diff --git a/LeetCodeSharp.Tests/LeetCodeSharp.Tests.csproj b/LeetCodeSharp.Tests/LeetCodeSharp.Tests.csproj new file mode 100644 index 0000000..a65736f --- /dev/null +++ b/LeetCodeSharp.Tests/LeetCodeSharp.Tests.csproj @@ -0,0 +1,27 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + diff --git a/LeetCodeSharp.Tests/P589Tests.cs b/LeetCodeSharp.Tests/P589Tests.cs new file mode 100644 index 0000000..1ba123e --- /dev/null +++ b/LeetCodeSharp.Tests/P589Tests.cs @@ -0,0 +1,22 @@ +using LeetCodeSharp.Problems; +using LeetCodeSharp.Utils; + +namespace LeetCodeSharp.Tests; + +public class P589Tests +{ + [Fact] + public void Test1() + { + Node root = new Node(1, [ + new Node(3), + new Node(2), + new Node(4), + ]); + + IList except = [1, 3, 2, 4]; + + var solution = new Solution(); + Assert.Equal(except, solution.Preorder(root)); + } +} \ No newline at end of file diff --git a/LeetCodeSharp.sln b/LeetCodeSharp.sln index b503798..bd911ad 100644 --- a/LeetCodeSharp.sln +++ b/LeetCodeSharp.sln @@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34607.119 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeetCodeSharp", "LeetCodeSharp\LeetCodeSharp.csproj", "{EB1DDDC1-A2FC-4AAB-A21A-59FAAFF656DD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeetCodeSharp", "LeetCodeSharp\LeetCodeSharp.csproj", "{EB1DDDC1-A2FC-4AAB-A21A-59FAAFF656DD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeetCodeSharp.Fetcher", "LeetCodeSharp.Fetcher\LeetCodeSharp.Fetcher.csproj", "{5D45BB2A-E512-4353-8746-6F0B79282C76}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeetCodeSharp.Fetcher", "LeetCodeSharp.Fetcher\LeetCodeSharp.Fetcher.csproj", "{5D45BB2A-E512-4353-8746-6F0B79282C76}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeetCodeSharp.Tests", "LeetCodeSharp.Tests\LeetCodeSharp.Tests.csproj", "{97E271FD-7244-4DD2-982C-103DF1E92B7C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +23,10 @@ Global {5D45BB2A-E512-4353-8746-6F0B79282C76}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D45BB2A-E512-4353-8746-6F0B79282C76}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D45BB2A-E512-4353-8746-6F0B79282C76}.Release|Any CPU.Build.0 = Release|Any CPU + {97E271FD-7244-4DD2-982C-103DF1E92B7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {97E271FD-7244-4DD2-982C-103DF1E92B7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {97E271FD-7244-4DD2-982C-103DF1E92B7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {97E271FD-7244-4DD2-982C-103DF1E92B7C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LeetCodeSharp/Utils/Node.cs b/LeetCodeSharp/Utils/Node.cs index 443df9f..09ef5fd 100644 --- a/LeetCodeSharp/Utils/Node.cs +++ b/LeetCodeSharp/Utils/Node.cs @@ -12,6 +12,7 @@ namespace LeetCodeSharp.Utils public Node(int _val) { val = _val; + children = new List(); } public Node(int _val, IList _children)