Skip to content

Migrate from .sln to .slnx and update NuGet packages #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v4
Expand All @@ -43,6 +45,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v4
Expand Down
66 changes: 66 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -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<T>` and `Memory<T>` 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.
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2">
<PackageVersion Include="BenchmarkDotNet" Version="0.15.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="FluentAssertions" Version="6.12.1" />
<PackageVersion Include="FluentAssertions" Version="7.2.0" />
<PackageVersion Include="FsUnit.xUnit" Version="6.0.1" />
<PackageVersion Include="FSharp.Core" Version="8.0.400" />
<PackageVersion Include="lolcat" Version="1.1.64" />
<PackageVersion Include="lolcat" Version="1.1.120" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.143">
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Spectre.Console" Version="0.49.1" />
<PackageVersion Include="Spectre.Console" Version="0.50.0" />
<PackageVersion Include="Spectre.Console.Analyzer" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.50.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
Expand Down
7 changes: 4 additions & 3 deletions LeetCode.FSharp/LeetCode.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<GenerateProgramFile>true</GenerateProgramFile>
<GenerateProgramFile>false</GenerateProgramFile>
<RootNamespace>LeetCode.FSharp</RootNamespace>
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,17 +14,17 @@
<Compile Include="ListNode.fs" />
<Compile Include="Benchmarks\ContainsDuplicateBenchmark.fs" />
<Compile Include="Benchmarks\FizzBuzzBenchmark.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="FSharp.Core" />
<PackageReference Include="FsUnit.xUnit" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Remove="FSharp.Core" />
<PackageReference Remove="Nerdbank.GitVersioning" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions LeetCode.FSharp/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Entry point for F# test project
[<EntryPoint>]
let main argv =
0
52 changes: 0 additions & 52 deletions LeetCode.sln

This file was deleted.

5 changes: 4 additions & 1 deletion LeetCode/LeetCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\LeetCode.CSharp\LeetCode.CSharp.csproj" />
<ProjectReference Include="..\LeetCode.CSharp\LeetCode.CSharp.csproj">
<IncludeAssets>compile;build</IncludeAssets>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\LeetCode.FSharp\LeetCode.FSharp.fsproj" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "9.0.0",
"version": "9.0.301",
"rollForward": "latestMajor",
"allowPrerelease": true
}
}
}
8 changes: 8 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -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
}