diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 391f970..75cfdda 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -18,6 +18,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@main + with: + fetch-depth: 0 - name: Setup dotnet uses: actions/setup-dotnet@v4 @@ -43,6 +45,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@main + with: + fetch-depth: 0 - name: Setup dotnet uses: actions/setup-dotnet@v4 diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..60635ae --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,66 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Best Practices + +When working with this codebase, always follow modern .NET and C# best practices: + +- Use latest C# language features (records, pattern matching, nullable reference types, file-scoped namespaces) +- Follow .NET naming conventions and coding standards +- Leverage modern async/await patterns where applicable +- Use `System.Text.Json` for JSON serialization +- Prefer `Span` and `Memory` for performance-critical code +- Use collection expressions and LINQ for data manipulation +- Apply proper error handling with exceptions and Result patterns +- Write clean, readable code with meaningful variable names +- Use nullable reference types and enable all relevant compiler warnings + +## Commands + +### Build +```bash +dotnet build +``` + +### Test +```bash +dotnet test --no-restore +``` + +### Run a single test +```bash +dotnet test --filter "FullyQualifiedName~TwoSumTest" +``` + +### Run console application +```bash +cd ./LeetCode +dotnet run + +# Run specific commands +dotnet run benchmark LRUCache --csharp +dotnet run info MergeTwoLists +dotnet run list +``` + +## Architecture + +This is a LeetCode problem solutions repository with benchmarking capabilities, structured as follows: + +### Three main projects: +1. **LeetCode.CSharp** - C# implementations of LeetCode problems with xUnit tests and BenchmarkDotNet benchmarks +2. **LeetCode.FSharp** - F# implementations of selected problems +3. **LeetCode** - Console application for running benchmarks and viewing problem information + +### Key architectural patterns: + +**Problem Organization**: All C# problems are implemented as static methods in the `Problem` partial class, decorated with `[LeetCode]` attributes containing metadata (description, difficulty, category, NeetCode video link). Each problem includes inline xUnit tests using `[Fact]` attributes. + +**Benchmark Structure**: Each problem has a corresponding benchmark class in the Benchmarks folder that inherits from a base `Benchmark` class. Benchmarks use BenchmarkDotNet with GlobalSetup/GlobalCleanup for test data preparation. + +**Console Application**: Built with Spectre.Console, provides an interactive menu system and CLI commands (app, benchmark, info, list, workflow) for running benchmarks and viewing problem information. + +**Testing**: Uses xUnit with FluentAssertions for test assertions. Tests are co-located with problem implementations for easy access. + +**Package Management**: Uses Directory.Packages.props for centralized NuGet package version management across all projects. \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 2cbe1bc..49542ca 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,26 +3,26 @@ true - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all diff --git a/LeetCode.FSharp/LeetCode.FSharp.fsproj b/LeetCode.FSharp/LeetCode.FSharp.fsproj index 767d97a..9cefbe0 100644 --- a/LeetCode.FSharp/LeetCode.FSharp.fsproj +++ b/LeetCode.FSharp/LeetCode.FSharp.fsproj @@ -2,8 +2,9 @@ false - true + false LeetCode.FSharp + false @@ -13,17 +14,17 @@ + - - + diff --git a/LeetCode.FSharp/Program.fs b/LeetCode.FSharp/Program.fs new file mode 100644 index 0000000..88c89df --- /dev/null +++ b/LeetCode.FSharp/Program.fs @@ -0,0 +1,4 @@ +// Entry point for F# test project +[] +let main argv = + 0 \ No newline at end of file diff --git a/LeetCode.sln b/LeetCode.sln deleted file mode 100644 index 722afc7..0000000 --- a/LeetCode.sln +++ /dev/null @@ -1,52 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.1.32319.34 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeetCode.CSharp", "LeetCode.CSharp\LeetCode.CSharp.csproj", "{27AD5CF0-9D7E-4358-808D-1737F7C3C0F1}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A54809E0-DF67-495C-BE99-0294DED27DC6}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - .github\dependabot.yml = .github\dependabot.yml - .github\workflows\workflow.yml = .github\workflows\workflow.yml - .gitignore = .gitignore - Directory.Build.props = Directory.Build.props - Directory.Packages.props = Directory.Packages.props - docker-compose.yml = docker-compose.yml - nuget.config = nuget.config - README.md = README.md - Run.ps1 = Run.ps1 - global.json = global.json - EndProjectSection -EndProject -Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "LeetCode.FSharp", "LeetCode.FSharp\LeetCode.FSharp.fsproj", "{B8401765-DECF-4417-985E-A090E67A2BE8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeetCode", "LeetCode\LeetCode.csproj", "{D9C4E00E-57FB-46B4-B038-7EDC254DCF46}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {27AD5CF0-9D7E-4358-808D-1737F7C3C0F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {27AD5CF0-9D7E-4358-808D-1737F7C3C0F1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {27AD5CF0-9D7E-4358-808D-1737F7C3C0F1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {27AD5CF0-9D7E-4358-808D-1737F7C3C0F1}.Release|Any CPU.Build.0 = Release|Any CPU - {B8401765-DECF-4417-985E-A090E67A2BE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B8401765-DECF-4417-985E-A090E67A2BE8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B8401765-DECF-4417-985E-A090E67A2BE8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B8401765-DECF-4417-985E-A090E67A2BE8}.Release|Any CPU.Build.0 = Release|Any CPU - {D9C4E00E-57FB-46B4-B038-7EDC254DCF46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D9C4E00E-57FB-46B4-B038-7EDC254DCF46}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D9C4E00E-57FB-46B4-B038-7EDC254DCF46}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D9C4E00E-57FB-46B4-B038-7EDC254DCF46}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {30ECA4F5-174F-42B7-A042-C374838DC8BF} - EndGlobalSection -EndGlobal diff --git a/LeetCode/LeetCode.csproj b/LeetCode/LeetCode.csproj index 3cbfb7e..5b1def2 100644 --- a/LeetCode/LeetCode.csproj +++ b/LeetCode/LeetCode.csproj @@ -18,7 +18,10 @@ - + + compile;build + runtime + diff --git a/global.json b/global.json index f4fd385..1738d16 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { - "version": "9.0.0", + "version": "9.0.301", "rollForward": "latestMajor", "allowPrerelease": true } -} \ No newline at end of file +} diff --git a/version.json b/version.json new file mode 100644 index 0000000..69a6f8b --- /dev/null +++ b/version.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", + "version": "0.0", + "publicReleaseRefSpec": [ + "^refs/heads/main$" + ], + "versionHeightOffset": -1 +} \ No newline at end of file