-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: Blogging. * Progress on SIMD post. * Start new post. * WIP on A-Z. * Added tags, footers, intralinks. * Blog fixes + RSS. * I'm going through changes. * Change for publishing. * Only run tests for main Sorcery.
- Loading branch information
Showing
51 changed files
with
6,639 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...habetDoesNotGoAToZ/AlphabetDoesNotGoAToZ.UnitTests/AlphabetDoesNotGoAToZ.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AlphabetDoesNotGoAToZ\AlphabetDoesNotGoAToZ.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
66 changes: 66 additions & 0 deletions
66
src/BlogPostCode/AlphabetDoesNotGoAToZ/AlphabetDoesNotGoAToZ.UnitTests/SolutionUnitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Licensed under MIT, copyright Mateusz Gienieczko, all rights reserved. | ||
|
||
namespace AlphabetDoesNotGoAToZ.UnitTests | ||
{ | ||
public class SolutionUnitTests | ||
{ | ||
private static readonly IReadOnlyList<string> BasicAlphaStrings = new[] | ||
{ | ||
"helloworld", "HELLOWORLD", "HelloWorld", "" | ||
}; | ||
|
||
private static readonly IReadOnlyList<string> BasicNonAlphaStrings = new[] | ||
{ | ||
"Hello, World!", "h3110w0r1d", "hello_world", "hello::world" | ||
}; | ||
|
||
private static readonly IReadOnlyList<string> NonLatinAlphaStrings = new[] | ||
{ | ||
"Witajświecie", "Привiтсвiте", "سلامدنیا", "你好世界", "OhHowNaïveIWas" | ||
}; | ||
|
||
private static IReadOnlyList<ISolution> CreateSolutions() => new ISolution[] | ||
{ | ||
new IncorrectSolution(), | ||
new IncorrectRegexSolution(), | ||
new CorrectSolution(), | ||
new CorrectRegexSolution(), | ||
}; | ||
|
||
private static TheoryData<ISolution, string> CreateTestData(IEnumerable<string> strings) | ||
{ | ||
var data = new TheoryData<ISolution, string>(); | ||
|
||
foreach (var implementation in CreateSolutions()) | ||
{ | ||
foreach (var text in strings) | ||
{ | ||
data.Add(implementation, text); | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
|
||
public static TheoryData<ISolution, string> BasicAlphaTestData => CreateTestData(BasicAlphaStrings); | ||
|
||
public static TheoryData<ISolution, string> BasicNonAlphaTestData => CreateTestData(BasicNonAlphaStrings); | ||
|
||
public static TheoryData<ISolution, string> NonLatinAlphaTestData => CreateTestData(NonLatinAlphaStrings); | ||
|
||
[Theory] | ||
[MemberData(nameof(BasicAlphaTestData))] | ||
[MemberData(nameof(NonLatinAlphaTestData))] | ||
public void IsAllLetters_WithAlphaStrings_ShouldBeTrue(ISolution solution, string text) | ||
{ | ||
Assert.True(solution.IsAllLetters(text)); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(BasicNonAlphaTestData))] | ||
public void IsAllLetters_WithNonAlphaStrings_ShouldBeFalse(ISolution solution, string text) | ||
{ | ||
Assert.False(solution.IsAllLetters(text)); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/BlogPostCode/AlphabetDoesNotGoAToZ/AlphabetDoesNotGoAToZ.UnitTests/Usings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Licensed under MIT, copyright Mateusz Gienieczko, all rights reserved. | ||
|
||
global using Xunit; |
9 changes: 9 additions & 0 deletions
9
src/BlogPostCode/AlphabetDoesNotGoAToZ/AlphabetDoesNotGoAToZ/AlphabetDoesNotGoAToZ.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
12 changes: 12 additions & 0 deletions
12
src/BlogPostCode/AlphabetDoesNotGoAToZ/AlphabetDoesNotGoAToZ/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"profiles": { | ||
"AlphabetDoesNotGoAToZ": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:52833;http://localhost:52834" | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/BlogPostCode/AlphabetDoesNotGoAToZ/AlphabetDoesNotGoAToZ/Solution.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed under MIT, copyright Mateusz Gienieczko, all rights reserved. | ||
|
||
using System.Text.RegularExpressions; | ||
|
||
namespace AlphabetDoesNotGoAToZ; | ||
|
||
public interface ISolution | ||
{ | ||
bool IsAllLetters(string text); | ||
} | ||
|
||
public sealed class IncorrectSolution : ISolution | ||
{ | ||
public bool IsAllLetters(string text) => | ||
text.All(c => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); | ||
} | ||
|
||
public sealed class IncorrectRegexSolution : ISolution | ||
{ | ||
// If you're not regex-savvy, this matches a full string that consists | ||
// of an arbitrary number of characters either in a-z or A-Z. | ||
private static readonly Regex AllLettersRegex = new("^[a-zA-Z]*$"); | ||
|
||
public bool IsAllLetters(string text) => AllLettersRegex.IsMatch(text); | ||
} | ||
|
||
public sealed class CorrectSolution : ISolution | ||
{ | ||
public bool IsAllLetters(string text) => text.All(c => char.IsLetter(c)); | ||
} | ||
|
||
public sealed class CorrectRegexSolution : ISolution | ||
{ | ||
private static readonly Regex AllLettersRegex = new(@"^\p{L}*$"); | ||
|
||
public bool IsAllLetters(string text) => AllLettersRegex.IsMatch(text); | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
...tCode/SimdCheatCodesForFreePerformance/Discrepancy.UnitTests/Discrepancy.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Discrepancy\Discrepancy.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
52 changes: 52 additions & 0 deletions
52
src/BlogPostCode/SimdCheatCodesForFreePerformance/Discrepancy.UnitTests/UnitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed under MIT, copyright Mateusz Gienieczko, all rights reserved. | ||
|
||
using System.Reflection; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Discrepancy.UnitTests; | ||
|
||
public class UnitTests | ||
{ | ||
public static TheoryData<Implementation, int?> AllImplementations | ||
{ | ||
get | ||
{ | ||
const int Size = 100_000; | ||
var benchmark = typeof(Benches); | ||
|
||
var implementations = | ||
from m in benchmark.GetMethods() | ||
where m.GetCustomAttribute<BenchmarkAttribute>() is not null | ||
let name = m.Name | ||
let del = m.CreateDelegate<Func<Benches, int?>>() | ||
let f = (Func<int?>)(() => | ||
{ | ||
var benches = new Benches(); | ||
benches.Length = 100_000; | ||
benches.Setup(); | ||
return del(benches); | ||
}) | ||
select new Implementation(name, f); | ||
|
||
var theoryData = new TheoryData<Implementation, int?>(); | ||
|
||
foreach (var x in implementations) | ||
{ | ||
theoryData.Add(x, Size - 1); | ||
} | ||
|
||
return theoryData; | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AllImplementations))] | ||
public void TestAllImplementations(Implementation implementation, int? expected) | ||
{ | ||
var actual = implementation.Function(); | ||
|
||
Assert.Equal(expected, actual); | ||
} | ||
|
||
public readonly record struct Implementation(string Name, Func<int?> Function); | ||
} |
3 changes: 3 additions & 0 deletions
3
src/BlogPostCode/SimdCheatCodesForFreePerformance/Discrepancy.UnitTests/Usings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Licensed under MIT, copyright Mateusz Gienieczko, all rights reserved. | ||
|
||
global using Xunit; |
15 changes: 15 additions & 0 deletions
15
src/BlogPostCode/SimdCheatCodesForFreePerformance/Discrepancy/Discrepancy.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.