Skip to content

Commit 0615abd

Browse files
authored
Update to net9.0, bump packages, tidy up (#135)
1 parent bb7beb2 commit 0615abd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+295
-316
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ indent_size = 4
1313
# CA1822: Mark members as static
1414
dotnet_diagnostic.ca1822.severity = silent
1515

16+
csharp_style_expression_bodied_methods = true:suggestion
1617
csharp_style_namespace_declarations = file_scoped
1718

1819
# Microsoft .NET properties

.github/workflows/workflow.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
DOTNET_NOLOGO: true
1111
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
1212
DOTNET_CLI_TELEMETRY_OPTOUT: true
13-
DOTNET_VERSION: 8.0.x
13+
DOTNET_VERSION: 9.0.x
1414

1515
jobs:
1616
build:
@@ -38,6 +38,7 @@ jobs:
3838

3939
benchmark:
4040
needs: [ build ]
41+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
4142
runs-on: ubuntu-latest
4243
steps:
4344
- name: Checkout

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ bin
33
obj
44
*.DotSettings.user
55
BenchmarkDotNet.Artifacts
6+
/.idea/.idea.LeetCode/.idea/material_theme_project_new.xml

Directory.Build.props

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<Project>
2-
32
<Import Project="Directory.Build.user.props" Condition="Exists('Directory.Build.user.props')"/>
43

54
<PropertyGroup>
6-
<TargetFramework>net8.0</TargetFramework>
75
<Authors>Simon McKenna</Authors>
8-
<Nullable>enable</Nullable>
9-
<ImplicitUsings>enable</ImplicitUsings>
6+
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
107
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<LangVersion>latest</LangVersion>
10+
<Nullable>enable</Nullable>
11+
<TargetFramework>net9.0</TargetFramework>
1112
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1213
</PropertyGroup>
1314

15+
<ItemGroup>
16+
<PackageReference Include="Nerdbank.GitVersioning" />
17+
</ItemGroup>
1418
</Project>

Directory.Packages.props

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88
<PrivateAssets>all</PrivateAssets>
99
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1010
</PackageVersion>
11-
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
12-
<PackageVersion Include="FsUnit.xUnit" Version="6.0.0" />
13-
<PackageVersion Include="FSharp.Core" Version="8.0.400" />
11+
<PackageVersion Include="FluentAssertions" Version="6.12.1" />
12+
<PackageVersion Include="FsUnit.xUnit" Version="6.0.1" />
13+
<PackageVersion Include="FSharp.Core" Version="8.0.100" />
1414
<PackageVersion Include="lolcat" Version="1.1.64" />
1515
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
16+
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.143">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageVersion>
1620
<PackageVersion Include="Spectre.Console" Version="0.49.1" />
17-
<PackageVersion Include="Spectre.Console.Analyzer" Version="1.0.0" />
21+
<PackageVersion Include="Spectre.Console.Analyzer" Version="1.0.0">
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
</PackageVersion>
1825
<PackageVersion Include="Spectre.Console.Cli" Version="0.49.1" />
19-
<PackageVersion Include="xunit" Version="2.9.0" />
26+
<PackageVersion Include="xunit" Version="2.9.2" />
2027
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2">
2128
<PrivateAssets>all</PrivateAssets>
2229
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

LeetCode.CSharp/Benchmark.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
[Config(typeof(BenchmarkConfig))]
44
public abstract class Benchmark
55
{
6-
protected char[][] CharArrayMulti { get; set; } = { new[] { char.MinValue } };
6+
protected char[][] CharArrayMulti { get; set; } = [[char.MinValue]];
77

88
protected int Int1 { get; set; }
99
protected int Int2 { get; set; }
1010

11-
protected int[] IntArray1 { get; set; } = Array.Empty<int>();
12-
protected int[] IntArray2 { get; set; } = Array.Empty<int>();
13-
protected int[][] IntArrayMulti1 { get; set; } = Array.Empty<int[]>();
14-
protected int?[] IntArrayNullable { get; set; } = Array.Empty<int?>();
11+
protected int[] IntArray1 { get; set; } = [];
12+
protected int[] IntArray2 { get; set; } = [];
13+
protected int[][] IntArrayMulti1 { get; set; } = [];
14+
protected int?[] IntArrayNullable { get; set; } = [];
1515

16-
protected List<Interval> Intervals1 { get; } = new();
16+
protected List<Interval> Intervals1 { get; } = [];
1717

1818
protected ListNode ListNode1 { get; set; } = new();
1919
protected ListNode ListNode2 { get; set; } = new();
2020

2121
protected string String1 { get; set; } = string.Empty;
2222
protected string String2 { get; set; } = string.Empty;
23-
protected string[] StringArray1 { get; set; } = Array.Empty<string>();
23+
protected string[] StringArray1 { get; set; } = [];
2424

2525
protected TreeNode TreeNode1 { get; set; } = new();
2626
protected TreeNode TreeNode2 { get; set; } = new();

LeetCode.CSharp/Benchmarks/AddTwoNumbersBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public void AddTwoNumbersSetup()
1919
[GlobalCleanup(Target = nameof(AddTwoNumbers))]
2020
public void AddTwoNumbersCleanup()
2121
{
22-
IntArray1 = Array.Empty<int>();
23-
IntArray2 = Array.Empty<int>();
22+
IntArray1 = [];
23+
IntArray2 = [];
2424
ListNode1 = new ListNode(IntArray1);
2525
ListNode2 = new ListNode(IntArray2);
2626
}

LeetCode.CSharp/Benchmarks/BinarySearchBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ public class BinarySearchBenchmark : Benchmark
99
public int BinarySearch() => Problem.BinarySearch(IntArray1, 1_000);
1010

1111
[GlobalCleanup(Target = nameof(BinarySearch))]
12-
public void BinarySearchCleanup() => IntArray1 = Array.Empty<int>();
12+
public void BinarySearchCleanup() => IntArray1 = [];
1313
}

LeetCode.CSharp/Problems/AddTwoNumbers.cs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,24 @@ public static ListNode AddTwoNumbers(ListNode l1, ListNode l2)
4646
return result.next!;
4747
}
4848

49-
[Fact]
50-
public void AddTwoNumbersTest()
49+
[Theory]
50+
[InlineData(new[] { 2, 4, 3 }, new[] { 5, 6, 4 }, new[] { 7, 0, 8 })]
51+
[InlineData(new int[] { }, new int[] { }, new int[] { })]
52+
[InlineData(
53+
new[] { 9, 9, 9, 9, 9, 9, 9 },
54+
new[] { 9, 9, 9, 9 },
55+
new[] { 8, 9, 9, 9, 0, 0, 0, 1 })]
56+
public void AddTwoNumbersTest(int[] list1, int[] list2, int[] expectedList)
5157
{
52-
var ex11 = new ListNode(new[] { 2, 4, 3 });
53-
var ex12 = new ListNode(new[] { 5, 6, 4 });
54-
var ex1Expected = new ListNode(new[] { 7, 0, 8 });
55-
var ex21 = new ListNode();
56-
var ex22 = new ListNode();
57-
var ex2Expected = new ListNode();
58-
var ex31 = new ListNode(new[] { 9, 9, 9, 9, 9, 9, 9 });
59-
var ex32 = new ListNode(new[] { 9, 9, 9, 9 });
60-
var ex3Expected = new ListNode(new[] { 8, 9, 9, 9, 0, 0, 0, 1 });
58+
var listNode1 = new ListNode(list1);
59+
var listNode2 = new ListNode(list2);
60+
var expectedNode = new ListNode(expectedList);
61+
var result = AddTwoNumbers(listNode1, listNode2);
62+
result.Should().NotBeNull();
63+
AssertEqual(result, expectedNode);
6164

62-
var ex1Result = AddTwoNumbers(ex11, ex12);
63-
var ex2Result = AddTwoNumbers(ex21, ex22);
64-
var ex3Result = AddTwoNumbers(ex31, ex32);
65+
return;
6566

66-
ex1Result.Should().NotBeNull();
67-
ex2Result.Should().NotBeNull();
68-
ex3Result.Should().NotBeNull();
6967
static void AssertEqual(ListNode? l1, ListNode? l2)
7068
{
7169
while (true)
@@ -84,8 +82,5 @@ static void AssertEqual(ListNode? l1, ListNode? l2)
8482
l2 = l2.next;
8583
}
8684
}
87-
AssertEqual(ex1Result, ex1Expected);
88-
AssertEqual(ex2Result, ex2Expected);
89-
AssertEqual(ex3Result, ex3Expected);
9085
}
9186
}

LeetCode.CSharp/Problems/BinarySearch.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ public static int BinarySearch(int[] nums, int target)
3535
return -1;
3636
}
3737

38-
[Fact]
39-
public void BinarySearchTest()
40-
{
41-
var nums = new[] { -1, 0, 3, 5, 9, 12 };
42-
43-
BinarySearch(nums, 9).Should().Be(4);
44-
BinarySearch(nums, 2).Should().Be(-1);
45-
BinarySearch(Array.Empty<int>(), 0).Should().Be(-1);
46-
}
38+
[Theory]
39+
[InlineData(new[] { -1, 0, 3, 5, 9, 12 }, 9, 4)]
40+
[InlineData(new[] { -1, 0, 3, 5, 9, 12 }, 2, -1)]
41+
[InlineData(new int[] { }, 0, -1)]
42+
public void BinarySearchTest(int[] nums, int target, int expected) =>
43+
BinarySearch(nums, target).Should().Be(expected);
4744
}

0 commit comments

Comments
 (0)