Skip to content

Commit e4fed19

Browse files
authored
Merge pull request #12 from dogaaydinn/claude/code-review-production-01SeMvjDN2zKeLYEeWcf512L
Code review and production readiness audit
2 parents 6f2f61a + 8bdcc26 commit e4fed19

File tree

24 files changed

+4069
-250
lines changed

24 files changed

+4069
-250
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup .NET
1919
uses: actions/setup-dotnet@v4
2020
with:
21-
dotnet-version: '6.0.x'
21+
dotnet-version: '8.0.x'
2222

2323
- name: Restore dependencies
2424
run: dotnet restore AdvancedCsharpConcepts.sln
@@ -48,7 +48,7 @@ jobs:
4848
- name: Setup .NET
4949
uses: actions/setup-dotnet@v4
5050
with:
51-
dotnet-version: '6.0.x'
51+
dotnet-version: '8.0.x'
5252

5353
- name: Run Benchmarks
5454
run: |
@@ -72,7 +72,7 @@ jobs:
7272
- name: Setup .NET
7373
uses: actions/setup-dotnet@v4
7474
with:
75-
dotnet-version: '6.0.x'
75+
dotnet-version: '8.0.x'
7676

7777
- name: Restore dependencies
7878
run: dotnet restore AdvancedCsharpConcepts.sln
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
<IsTestProject>true</IsTestProject>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="FluentAssertions" Version="8.8.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
14+
<PackageReference Include="xunit" Version="2.9.2" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
<PrivateAssets>all</PrivateAssets>
18+
</PackageReference>
19+
<PackageReference Include="coverlet.collector" Version="6.0.4">
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
<PrivateAssets>all</PrivateAssets>
22+
</PackageReference>
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<ProjectReference Include="..\AdvancedCsharpConcepts\AdvancedCsharpConcepts.csproj" />
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using AdvancedCsharpConcepts.Advanced.HighPerformance;
2+
using System.Diagnostics;
3+
4+
namespace AdvancedCsharpConcepts.IntegrationTests;
5+
6+
/// <summary>
7+
/// Integration tests for high-performance patterns.
8+
/// Tests real-world scenarios combining multiple components.
9+
/// </summary>
10+
public class PerformanceIntegrationTests
11+
{
12+
[Fact]
13+
public void ParallelProcessing_LargeDataset_ShouldBeFasterThanSequential()
14+
{
15+
// Arrange
16+
const int dataSize = 1_000_000;
17+
var sw = Stopwatch.StartNew();
18+
19+
// Act - Sequential
20+
sw.Restart();
21+
var seqResult = ParallelProcessingExamples.SequentialSum(dataSize);
22+
var seqTime = sw.ElapsedMilliseconds;
23+
24+
// Act - Parallel
25+
sw.Restart();
26+
var parResult = ParallelProcessingExamples.ParallelForSum(dataSize);
27+
var parTime = sw.ElapsedMilliseconds;
28+
29+
// Assert
30+
parResult.Should().Be(seqResult);
31+
parTime.Should().BeLessThan(seqTime); // Parallel should be faster
32+
}
33+
34+
[Fact]
35+
public void SpanMemory_ParsingLargeCSV_ShouldBeMoreEfficientThanTraditional()
36+
{
37+
// Arrange
38+
var numbers = string.Join(",", Enumerable.Range(1, 1000));
39+
40+
// Act
41+
var traditional = SpanMemoryExamples.ParseNumbersTraditional(numbers);
42+
var modern = SpanMemoryExamples.ParseNumbersModern(numbers);
43+
44+
// Assert
45+
traditional.Should().Equal(modern);
46+
traditional.Should().HaveCount(1000);
47+
traditional.Should().Equal(Enumerable.Range(1, 1000));
48+
}
49+
50+
[Fact]
51+
public async Task AsyncMemoryOperations_ShouldWorkCorrectly()
52+
{
53+
// Act
54+
var result = await SpanMemoryExamples.AsyncMemoryExample();
55+
56+
// Assert
57+
result.Should().Be(499500); // Sum of 0..999
58+
}
59+
60+
[Fact]
61+
public void MatrixMultiplication_Parallel_ShouldProduceCorrectResults()
62+
{
63+
// Arrange
64+
var matrixA = new double[10, 10];
65+
var matrixB = new double[10, 10];
66+
67+
for (int i = 0; i < 10; i++)
68+
{
69+
for (int j = 0; j < 10; j++)
70+
{
71+
matrixA[i, j] = i + j;
72+
matrixB[i, j] = i * j;
73+
}
74+
}
75+
76+
// Act
77+
var result = ParallelProcessingExamples.ParallelMatrixMultiply(matrixA, matrixB);
78+
79+
// Assert
80+
result.Should().NotBeNull();
81+
result.GetLength(0).Should().Be(10);
82+
result.GetLength(1).Should().Be(10);
83+
}
84+
85+
[Theory]
86+
[InlineData(100)]
87+
[InlineData(1000)]
88+
[InlineData(10000)]
89+
public void ParallelPipeline_DifferentSizes_ShouldProduceCorrectResults(int size)
90+
{
91+
// Arrange
92+
var input = Enumerable.Range(1, size);
93+
94+
// Act
95+
var result = ParallelProcessingExamples.ParallelPipeline(input);
96+
97+
// Assert - Should contain only even squares
98+
result.Should().AllSatisfy(x => (x % 2).Should().Be(0));
99+
result.Should().AllSatisfy(x => Math.Sqrt(x).Should().BeGreaterThan(0));
100+
}
101+
102+
[Fact]
103+
public void CombinedPatterns_SpanWithParallel_ShouldWorkTogether()
104+
{
105+
// Arrange
106+
var data = Enumerable.Range(0, 100).ToArray();
107+
108+
// Act - Use Span for zero-allocation access
109+
var span = data.AsSpan();
110+
111+
// Process chunks in parallel
112+
var sum = 0;
113+
System.Threading.Tasks.Parallel.For(0, 4, i =>
114+
{
115+
var chunkSize = span.Length / 4;
116+
var chunk = span.Slice(i * chunkSize, chunkSize);
117+
var localSum = 0;
118+
foreach (var val in chunk)
119+
{
120+
localSum += val;
121+
}
122+
System.Threading.Interlocked.Add(ref sum, localSum);
123+
});
124+
125+
// Assert
126+
sum.Should().Be(Enumerable.Range(0, 100).Sum());
127+
}
128+
129+
[Fact]
130+
public void RealWorldScenario_DataProcessingPipeline()
131+
{
132+
// Arrange - Simulate real-world data processing
133+
var csvData = string.Join(",", Enumerable.Range(1, 10000).Select(x => x.ToString()));
134+
135+
// Act - Parse, transform, and aggregate
136+
var numbers = SpanMemoryExamples.ParseNumbersModern(csvData);
137+
var transformed = numbers.AsParallel()
138+
.Select(x => x * 2)
139+
.Where(x => x % 10 == 0)
140+
.ToArray();
141+
142+
// Assert
143+
transformed.Should().NotBeEmpty();
144+
transformed.Should().AllSatisfy(x => (x % 10).Should().Be(0));
145+
}
146+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global using Xunit;
2+
global using FluentAssertions;

AdvancedCsharpConcepts.Tests/AdvancedCsharpConcepts.Tests.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

88
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
910
</PropertyGroup>
1011

1112
<ItemGroup>
1213
<PackageReference Include="FluentAssertions" Version="8.8.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
14-
<PackageReference Include="xunit" Version="2.4.1" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
15+
<PackageReference Include="xunit" Version="2.9.2" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
1617
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1718
<PrivateAssets>all</PrivateAssets>
1819
</PackageReference>

0 commit comments

Comments
 (0)