Skip to content

Commit

Permalink
Blog (#5)
Browse files Browse the repository at this point in the history
* 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
V0ldek authored Jul 10, 2023
1 parent e000684 commit 6e535f2
Show file tree
Hide file tree
Showing 51 changed files with 6,639 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sorcery-vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test ./src/Tests/Sorcery.UnitTests/Sorcery.UnitTests.csproj --no-build --verbosity normal

publish:

Expand Down
54 changes: 54 additions & 0 deletions Sorcery.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sorcery.ModularCourse", "src\Sorcery.ModularCourse\Sorcery.ModularCourse.csproj", "{28803479-1797-4A28-960E-1590D213F3A4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sorcery.Blogging", "src\Sorcery.Blogging\Sorcery.Blogging.csproj", "{E81B228A-44D0-4730-BCB1-65542BFFCFB1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sorcery.Utilities", "src\Sorcery.Utilities\Sorcery.Utilities.csproj", "{C53C5E95-0F30-4910-AE20-0E381749C4C7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BlogPostCode", "BlogPostCode", "{BDE2456B-740C-4EA3-BBF3-2D10B064B81B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SimdCheatCodesForFreePerformance", "SimdCheatCodesForFreePerformance", "{7B0AECD3-7FD2-4BC6-B6FD-BCAC94747BC0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AlphabetDoesNotGoAToZ", "AlphabetDoesNotGoAToZ", "{16564E33-F442-4A75-BAC7-A327DB408057}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlphabetDoesNotGoAToZ", "src\BlogPostCode\AlphabetDoesNotGoAToZ\AlphabetDoesNotGoAToZ\AlphabetDoesNotGoAToZ.csproj", "{7AFC2649-2058-47D9-9E3D-FDF3011A8D2D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlphabetDoesNotGoAToZ.UnitTests", "src\BlogPostCode\AlphabetDoesNotGoAToZ\AlphabetDoesNotGoAToZ.UnitTests\AlphabetDoesNotGoAToZ.UnitTests.csproj", "{06DE166C-1D8A-499D-B768-1F1D85E76FB5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discrepancy", "src\BlogPostCode\SimdCheatCodesForFreePerformance\Discrepancy\Discrepancy.csproj", "{022A47F9-B0ED-46BC-B8F4-DBB975D47516}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discrepancy.UnitTests", "src\BlogPostCode\SimdCheatCodesForFreePerformance\Discrepancy.UnitTests\Discrepancy.UnitTests.csproj", "{32FD482F-1499-41A8-9D77-3FBA050BA0DB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sorcery.Rss", "src\Sorcery.Rss\Sorcery.Rss.csproj", "{1C6B7DFC-4800-4776-A051-D6B316BEF909}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,12 +58,46 @@ Global
{28803479-1797-4A28-960E-1590D213F3A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28803479-1797-4A28-960E-1590D213F3A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28803479-1797-4A28-960E-1590D213F3A4}.Release|Any CPU.Build.0 = Release|Any CPU
{E81B228A-44D0-4730-BCB1-65542BFFCFB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E81B228A-44D0-4730-BCB1-65542BFFCFB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E81B228A-44D0-4730-BCB1-65542BFFCFB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E81B228A-44D0-4730-BCB1-65542BFFCFB1}.Release|Any CPU.Build.0 = Release|Any CPU
{C53C5E95-0F30-4910-AE20-0E381749C4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C53C5E95-0F30-4910-AE20-0E381749C4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C53C5E95-0F30-4910-AE20-0E381749C4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C53C5E95-0F30-4910-AE20-0E381749C4C7}.Release|Any CPU.Build.0 = Release|Any CPU
{7AFC2649-2058-47D9-9E3D-FDF3011A8D2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7AFC2649-2058-47D9-9E3D-FDF3011A8D2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7AFC2649-2058-47D9-9E3D-FDF3011A8D2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7AFC2649-2058-47D9-9E3D-FDF3011A8D2D}.Release|Any CPU.Build.0 = Release|Any CPU
{06DE166C-1D8A-499D-B768-1F1D85E76FB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06DE166C-1D8A-499D-B768-1F1D85E76FB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06DE166C-1D8A-499D-B768-1F1D85E76FB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06DE166C-1D8A-499D-B768-1F1D85E76FB5}.Release|Any CPU.Build.0 = Release|Any CPU
{022A47F9-B0ED-46BC-B8F4-DBB975D47516}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{022A47F9-B0ED-46BC-B8F4-DBB975D47516}.Debug|Any CPU.Build.0 = Debug|Any CPU
{022A47F9-B0ED-46BC-B8F4-DBB975D47516}.Release|Any CPU.ActiveCfg = Release|Any CPU
{022A47F9-B0ED-46BC-B8F4-DBB975D47516}.Release|Any CPU.Build.0 = Release|Any CPU
{32FD482F-1499-41A8-9D77-3FBA050BA0DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32FD482F-1499-41A8-9D77-3FBA050BA0DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32FD482F-1499-41A8-9D77-3FBA050BA0DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32FD482F-1499-41A8-9D77-3FBA050BA0DB}.Release|Any CPU.Build.0 = Release|Any CPU
{1C6B7DFC-4800-4776-A051-D6B316BEF909}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C6B7DFC-4800-4776-A051-D6B316BEF909}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C6B7DFC-4800-4776-A051-D6B316BEF909}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C6B7DFC-4800-4776-A051-D6B316BEF909}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{80C4B5A6-AEEE-4210-87BF-28E1E4703E86} = {F650DEDE-DF98-4A9D-BD39-05C472AD1149}
{7B0AECD3-7FD2-4BC6-B6FD-BCAC94747BC0} = {BDE2456B-740C-4EA3-BBF3-2D10B064B81B}
{16564E33-F442-4A75-BAC7-A327DB408057} = {BDE2456B-740C-4EA3-BBF3-2D10B064B81B}
{7AFC2649-2058-47D9-9E3D-FDF3011A8D2D} = {16564E33-F442-4A75-BAC7-A327DB408057}
{06DE166C-1D8A-499D-B768-1F1D85E76FB5} = {16564E33-F442-4A75-BAC7-A327DB408057}
{022A47F9-B0ED-46BC-B8F4-DBB975D47516} = {7B0AECD3-7FD2-4BC6-B6FD-BCAC94747BC0}
{32FD482F-1499-41A8-9D77-3FBA050BA0DB} = {7B0AECD3-7FD2-4BC6-B6FD-BCAC94747BC0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {98C24905-353A-4F69-BED6-CAAA4C8ED64F}
Expand Down
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>
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));
}
}
}
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;
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>
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"
}
}
}
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);
}

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>
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);
}
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;
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>
Loading

0 comments on commit 6e535f2

Please sign in to comment.