Skip to content

Commit

Permalink
Changed formatting, moved to .NET 9, and added more unit tests for co…
Browse files Browse the repository at this point in the history
…verage.
  • Loading branch information
jslicer committed Dec 20, 2024
1 parent be0a8a2 commit a5915c2
Show file tree
Hide file tree
Showing 12 changed files with 712 additions and 367 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_throw_expression = true:suggestion
csharp_indent_labels = one_less_than_current
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
dotnet_diagnostic.SA1101.severity = none

[*.{cs,vb}]
#### Naming styles ####
Expand Down Expand Up @@ -87,3 +91,7 @@ dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
28 changes: 20 additions & 8 deletions Murmur3.Tests/Murmur3.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,6 +10,18 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>9999</WarningLevel>
<NoWarn />
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<WarningLevel>9999</WarningLevel>
<NoWarn />
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<None Remove="stylecop.json" />
</ItemGroup>
Expand All @@ -19,30 +31,30 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="IDisposableAnalyzers" Version="4.0.7">
<PackageReference Include="IDisposableAnalyzers" Version="4.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ReflectionAnalyzers" Version="0.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.12.0.78982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.4.0.108396">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
68 changes: 37 additions & 31 deletions Murmur3.Tests/Murmur3ATests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,39 @@ public Murmur3ATests()
}

/// <summary>
/// Tests an empty byte array with an input seed of 0x00000000.
/// Tests an empty <see langword="byte" /> array with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void TestEmptyInputSeed0() => this.Test(
public void TestEmptyInputSeed0() => Test(
"00000000",
Array.Empty<byte>(),
[],
"with zero data and zero seed, everything becomes zero");

/// <summary>
/// Tests an empty byte array with an input seed of 0x00000001.
/// Tests an empty <see langword="byte" /> array with an input seed of 0x00000001.
/// </summary>
[TestMethod]
public void TestEmptyInputSeed1() =>
this.Test("514E28B7", Array.Empty<byte>(), "ignores nearly all the math", 0x00000001);
#pragma warning disable SA1010 // Opening square brackets should be spaced correctly
Test("514E28B7", [], "ignores nearly all the math", 0x00000001);
#pragma warning restore SA1010 // Opening square brackets should be spaced correctly

/// <summary>
/// ReSharper disable once CommentTypo
/// Tests an empty byte array with an input seed of 0xFFFFFFFF.
/// Tests an empty <see langword="byte" /> array with an input seed of 0xFFFFFFFF.
/// </summary>
[TestMethod]
//// ReSharper disable once InconsistentNaming
//// ReSharper disable IdentifierTypo
public void TestEmptyInputSeedFFFFFFFF() => this.Test(
public void TestEmptyInputSeedFFFFFFFF() => Test(
//// ReSharper restore IdentifierTypo
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable SA1114 // Parameter list should follow declaration
"81F16F39",
//// ReSharper disable once StyleCop.SA1118
#pragma warning restore SA1114 // Parameter list should follow declaration
#pragma warning restore IDE0079 // Remove unnecessary suppression
Array.Empty<byte>(),
[],
"make sure your seed uses unsigned 32-bit math",
unchecked((int)0xFFFFFFFFU));

Expand All @@ -70,7 +72,7 @@ public void TestEmptyInputSeedFFFFFFFF() => this.Test(
[TestMethod]
//// ReSharper disable once InconsistentNaming
//// ReSharper disable IdentifierTypo
public void TestFFFFFFFFInputSeed0() => this.Test(
public void TestFFFFFFFFInputSeed0() => Test(
//// ReSharper restore IdentifierTypo
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable SA1114 // Parameter list should follow declaration
Expand All @@ -79,17 +81,17 @@ public void TestFFFFFFFFInputSeed0() => this.Test(
#pragma warning restore SA1114 // Parameter list should follow declaration
#pragma warning restore IDE0079 // Remove unnecessary suppression
//// ReSharper disable once StyleCop.SA1502
new[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF },
[0xFF, 0xFF, 0xFF, 0xFF],
"make sure 4-byte chunks use unsigned math");

/// <summary>
/// Tests an array with bytes 0x87654321 with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void Test21436587InputSeed0() => this.Test(
public void Test21436587InputSeed0() => Test(
"F55B516B",
//// ReSharper disable once StyleCop.SA1502
new[] { (byte)0x21, (byte)0x43, (byte)0x65, (byte)0x87 },
[0x21, 0x43, 0x65, 0x87],
"Endian order. UInt32 should end up as 0x87654321");

/// <summary>
Expand All @@ -99,7 +101,7 @@ public void Test21436587InputSeed0() => this.Test(
[TestMethod]
//// ReSharper disable once InconsistentNaming
//// ReSharper disable IdentifierTypo
public void Test21436587InputSeed5082EDEE() => this.Test(
public void Test21436587InputSeed5082EDEE() => Test(
//// ReSharper restore IdentifierTypo
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable SA1114 // Parameter list should follow declaration
Expand All @@ -108,15 +110,15 @@ public void Test21436587InputSeed5082EDEE() => this.Test(
#pragma warning restore SA1114 // Parameter list should follow declaration
#pragma warning restore IDE0079 // Remove unnecessary suppression
//// ReSharper disable once StyleCop.SA1502
new[] { (byte)0x21, (byte)0x43, (byte)0x65, (byte)0x87 },
[0x21, 0x43, 0x65, 0x87],
"Special seed value eliminates initial key with xor",
0x5082EDEE);

/// <summary>
/// Tests an array with bytes 0x654321 with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void Test214365InputSeed0() => this.Test(
public void Test214365InputSeed0() => Test(
"7E4A8634",
//// ReSharper disable once StyleCop.SA1502
"!Ce"u8.ToArray(),
Expand All @@ -126,47 +128,47 @@ public void Test214365InputSeed0() => this.Test(
/// Tests an array with bytes 0x4321 with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void Test2143InputSeed0() => this.Test(
public void Test2143InputSeed0() => Test(
"A0F7B07A",
//// ReSharper disable once StyleCop.SA1502
"!C"u8.ToArray(),
"Only two bytes. Should end up as 0x4321");

/// <summary>
/// Tests an array with byte 0x21 with an input seed of 0x00000000.
/// Tests an array with <see langword="byte" /> 0x21 with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void Test21InputSeed0() =>
//// ReSharper disable once StyleCop.SA1502
this.Test("72661CF4", "!"u8.ToArray(), "Only one byte. Should end up as 0x21");
Test("72661CF4", "!"u8.ToArray(), "Only one byte. Should end up as 0x21");

/// <summary>
/// Tests an array with bytes 0x00000000 with an input seed of 0x00000000.
/// Tests an array with <see langword="byte" />s 0x00000000 with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void Test00000000InputSeed0() =>
this.Test("2362F9DE", new byte[4], "Make sure compiler doesn't see zero and convert to null");
Test("2362F9DE", new byte[4], "Make sure compiler doesn't see zero and convert to null");

/// <summary>
/// Tests an array with bytes 0x000000 with an input seed of 0x00000000.
/// Tests an array with <see langword="byte" />s 0x000000 with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void Test000000InputSeed0() =>
this.Test("85F0B427", new byte[3], "Make sure compiler doesn't see zero and convert to null");
Test("85F0B427", new byte[3], "Make sure compiler doesn't see zero and convert to null");

/// <summary>
/// Tests an array with bytes 0x0000 with an input seed of 0x00000000.
/// Tests an array with <see langword="byte" />s 0x0000 with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void Test0000InputSeed0() =>
this.Test("30F4C306", new byte[2], "Make sure compiler doesn't see zero and convert to null");
Test("30F4C306", new byte[2], "Make sure compiler doesn't see zero and convert to null");

/// <summary>
/// Tests an array with bytes 0x00 with an input seed of 0x00000000.
/// Tests an array with <see langword="byte" />s 0x00 with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void Test00InputSeed0() =>
this.Test("514E28B7", new byte[1], "Make sure compiler doesn't see zero and convert to null");
Test("514E28B7", new byte[1], "Make sure compiler doesn't see zero and convert to null");

/// <summary>
/// ReSharper disable CommentTypo
Expand All @@ -175,7 +177,7 @@ public void Test00InputSeed0() =>
/// </summary>
[TestMethod]
//// ReSharper disable IdentifierTypo
public void TestLoremIpsumInputSeed0() => this.Test(
public void TestLoremIpsumInputSeed0() => Test(
//// ReSharper restore IdentifierTypo
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable SA1114 // Parameter list should follow declaration
Expand All @@ -192,7 +194,7 @@ public void TestLoremIpsumInputSeed0() => this.Test(
/// Tests a common string ("The quick brown fox") with an input seed of 0x00000000.
/// </summary>
[TestMethod]
public void TestQuickBrownFoxInputSeed0() => this.Test(
public void TestQuickBrownFoxInputSeed0() => Test(
"2E4FF723",
"The quick brown fox jumps over the lazy dog",
"lengthy string interpreted as UTF-8");
Expand All @@ -202,7 +204,7 @@ public void TestQuickBrownFoxInputSeed0() => this.Test(
/// </summary>
[TestMethod]
//// ReSharper disable InconsistentNaming
public void TestQuickBrownFoxInputSeed9747b28c() => this.Test(
public void TestQuickBrownFoxInputSeed9747b28c() => Test(
//// ReSharper restore InconsistentNaming
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable SA1114 // Parameter list should follow declaration
Expand All @@ -219,7 +221,7 @@ public void TestQuickBrownFoxInputSeed9747b28c() => this.Test(
/// </summary>
[TestMethod]
//// ReSharper disable InconsistentNaming
public void TestQuickBrownFoxInputSeedC58f1a7b() => this.Test(
public void TestQuickBrownFoxInputSeedC58f1a7b() => Test(
//// ReSharper restore InconsistentNaming
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable SA1114 // Parameter list should follow declaration
Expand All @@ -236,5 +238,9 @@ public void TestQuickBrownFoxInputSeedC58f1a7b() => this.Test(
/// </summary>
/// <returns>An asynchronous <see cref="Task" />.</returns>
[TestMethod]
public async Task TestSmHasherAsync() => await this.TestSmHasherAsync("B0F57EE3").ConfigureAwait(false);
public async Task TestSmHasherAsync()
{
using CancellationTokenSource cts = new ();
await TestSmHasherAsync("B0F57EE3", cts.Token).ConfigureAwait(true);
}
}
Loading

0 comments on commit a5915c2

Please sign in to comment.