Skip to content

Commit 63b6c98

Browse files
Merge pull request #2 from onix-labs/feature/v2.1
Feature/v2.1
2 parents fa6cd71 + 76d10e0 commit 63b6c98

File tree

126 files changed

+1605
-319
lines changed

Some content is hidden

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

126 files changed

+1605
-319
lines changed

OnixLabs.Core.UnitTests/Base16Tests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base16Tests
2121
{
22+
[Fact(DisplayName = "Identical Base16 values produce identical hash codes.")]
23+
public void IdenticalBase16ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base16 a = Base16.FromString("abcdefghijklmnopqrstuvwxyz");
27+
Base16 b = Base16.FromString("abcdefghijklmnopqrstuvwxyz");
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base16_FromString should produce the expected Base-16 value.")]
2338
[InlineData("31323334353637383930", "1234567890")]
2439
[InlineData("4142434445464748494a4b4c4d4e4f505152535455565758595a", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core.UnitTests/Base32Base32HexAlphabetTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base32Base32HexAlphabetTests
2121
{
22+
[Fact(DisplayName = "Identical Base32 values produce identical hash codes.")]
23+
public void IdenticalBase32ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base32 a = Base32.FromString("abcdefghijklmnopqrstuvwxyz", Base32Alphabet.Base32Hex);
27+
Base32 b = Base32.FromString("abcdefghijklmnopqrstuvwxyz", Base32Alphabet.Base32Hex);
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base32_FromString without padding should produce the expected Base-32 value.")]
2338
[InlineData("64P36D1L6ORJGE9G", "1234567890")]
2439
[InlineData("85146H258P3KGIAA9D64QJIFA18L4KQKALB5EM2PB8======", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core.UnitTests/Base32CrockfordAlphabetTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base32CrockfordAlphabetTests
2121
{
22+
[Fact(DisplayName = "Identical Base32 values produce identical hash codes.")]
23+
public void IdenticalBase32ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base32 a = Base32.FromString("abcdefghijklmnopqrstuvwxyz", Base32Alphabet.Crockford);
27+
Base32 b = Base32.FromString("abcdefghijklmnopqrstuvwxyz", Base32Alphabet.Crockford);
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base32_FromString without padding should produce the expected Base-32 value.")]
2338
[InlineData("64S36D1N6RVKGE9G", "1234567890")]
2439
[InlineData("85146H258S3MGJAA9D64TKJFA18N4MTMANB5EP2SB8======", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core.UnitTests/Base32DefaultAlphabetTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base32DefaultAlphabetTests
2121
{
22+
[Fact(DisplayName = "Identical Base32 values produce identical hash codes.")]
23+
public void IdenticalBase32ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base32 a = Base32.FromString("abcdefghijklmnopqrstuvwxyz", Base32Alphabet.Default);
27+
Base32 b = Base32.FromString("abcdefghijklmnopqrstuvwxyz", Base32Alphabet.Default);
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base32_FromString without padding should produce the expected Base-32 value.")]
2338
[InlineData("GEZDGNBVGY3TQOJQ", "1234567890")]
2439
[InlineData("IFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLI======", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core.UnitTests/Base32ZBase32AlphabetTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base32ZBase32AlphabetTests
2121
{
22+
[Fact(DisplayName = "Identical Base32 values produce identical hash codes.")]
23+
public void IdenticalBase32ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base32 a = Base32.FromString("abcdefghijklmnopqrstuvwxyz", Base32Alphabet.ZBase32);
27+
Base32 b = Base32.FromString("abcdefghijklmnopqrstuvwxyz", Base32Alphabet.ZBase32);
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base32_FromString without padding should produce the expected Base-32 value.")]
2338
[InlineData("gr3dgpbiga5uoqjo", "1234567890")]
2439
[InlineData("efbrgtnfe3dwo1kkjpgr4u1xkbeirw4wkimfqsn3me======", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core.UnitTests/Base58DefaultAlphabetTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base58DefaultAlphabetTests
2121
{
22+
[Fact(DisplayName = "Identical Base58 values produce identical hash codes.")]
23+
public void IdenticalBase58ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base58 a = Base58.FromString("abcdefghijklmnopqrstuvwxyz", Base58Alphabet.Default);
27+
Base58 b = Base58.FromString("abcdefghijklmnopqrstuvwxyz", Base58Alphabet.Default);
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base58_FromString should produce the expected Base-58 value.")]
2338
[InlineData("3mJr7AoUCHxNqd", "1234567890")]
2439
[InlineData("2zuFXTJSTRK6ESktqhM2QDBkCnH1U46CnxaD", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core.UnitTests/Base58FlickrAlphabetTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base58FlickrAlphabetTests
2121
{
22+
[Fact(DisplayName = "Identical Base58 values produce identical hash codes.")]
23+
public void IdenticalBase58ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base58 a = Base58.FromString("abcdefghijklmnopqrstuvwxyz", Base58Alphabet.Flickr);
27+
Base58 b = Base58.FromString("abcdefghijklmnopqrstuvwxyz", Base58Alphabet.Flickr);
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base58_FromString should produce the expected Base-58 value.")]
2338
[InlineData("3LiR7aNtchXnQC", "1234567890")]
2439
[InlineData("2ZUfwsirsqj6erKTQGm2pdbKcMh1t46cMXzd", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core.UnitTests/Base58RippleAlphabetTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base58RippleAlphabetTests
2121
{
22+
[Fact(DisplayName = "Identical Base58 values produce identical hash codes.")]
23+
public void IdenticalBase58ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base58 a = Base58.FromString("abcdefghijklmnopqrstuvwxyz", Base58Alphabet.Ripple);
27+
Base58 b = Base58.FromString("abcdefghijklmnopqrstuvwxyz", Base58Alphabet.Ripple);
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base58_FromString should produce the expected Base-58 value.")]
2338
[InlineData("smJifwo7UHx4qd", "1234567890")]
2439
[InlineData("pzuEXTJSTRKaNSktq6MpQDBkU8Hr7haU8x2D", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core.UnitTests/Base64Tests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace OnixLabs.Core.UnitTests
1919
{
2020
public sealed class Base64Tests
2121
{
22+
[Fact(DisplayName = "Identical Base64 values produce identical hash codes.")]
23+
public void IdenticalBase64ValuesProduceIdenticalHashCodes()
24+
{
25+
// Arrange
26+
Base64 a = Base64.FromString("abcdefghijklmnopqrstuvwxyz");
27+
Base64 b = Base64.FromString("abcdefghijklmnopqrstuvwxyz");
28+
29+
// Act
30+
int hashCodeA = a.GetHashCode();
31+
int hashCodeB = b.GetHashCode();
32+
33+
// Assert
34+
Assert.Equal(hashCodeA, hashCodeB);
35+
}
36+
2237
[Theory(DisplayName = "Base64_FromString should produce the expected Base-64 value.")]
2338
[InlineData("MTIzNDU2Nzg5MA==", "1234567890")]
2439
[InlineData("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]

OnixLabs.Core/Enumeration.Comparable.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
namespace OnixLabs.Core
1818
{
19-
/// <summary>
20-
/// Represents the base class for implementing enumeration classes.
21-
/// </summary>
2219
public abstract partial class Enumeration<T> : IComparable, IComparable<T>
2320
{
2421
/// <summary>

OnixLabs.Core/Enumeration.Equatable.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
namespace OnixLabs.Core
1818
{
19-
/// <summary>
20-
/// Represents the base class for implementing enumeration classes.
21-
/// </summary>
2219
public abstract partial class Enumeration<T> : IEquatable<T>
2320
{
2421
/// <summary>
@@ -73,7 +70,11 @@ public override bool Equals(object? obj)
7370
/// <returns>A hash code for this instance.</returns>
7471
public override int GetHashCode()
7572
{
76-
return HashCode.Combine(GetType(), Name, Value);
73+
return new HashCode()
74+
.AddItem(GetType())
75+
.AddItem(Name)
76+
.AddItem(Value)
77+
.ToHashCode();
7778
}
7879
}
7980
}

OnixLabs.Core/Enumeration.From.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
namespace OnixLabs.Core
2121
{
22-
/// <summary>
23-
/// Represents the base class for implementing enumeration classes.
24-
/// </summary>
2522
public abstract partial class Enumeration<T>
2623
{
2724
/// <summary>

OnixLabs.Core/Enumeration.Get.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
namespace OnixLabs.Core
2121
{
22-
/// <summary>
23-
/// Represents the base class for implementing enumeration classes.
24-
/// </summary>
2522
public abstract partial class Enumeration<T>
2623
{
2724
/// <summary>

OnixLabs.Core/Enumeration.To.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
namespace OnixLabs.Core
1616
{
17-
/// <summary>
18-
/// Represents the base class for implementing enumeration classes.
19-
/// </summary>
2017
public abstract partial class Enumeration<T>
2118
{
2219
/// <summary>

OnixLabs.Core/HashCodeExtensions.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2020-2021 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.ComponentModel;
18+
using OnixLabs.Core.Linq;
19+
20+
namespace OnixLabs.Core
21+
{
22+
/// <summary>
23+
/// Provides extension methods for hash codes.
24+
/// </summary>
25+
[EditorBrowsable(EditorBrowsableState.Never)]
26+
public static class HashCodeExtensions
27+
{
28+
/// <summary>
29+
/// Adds an item to be hashed into a <see cref="HashCode"/> instance.
30+
/// </summary>
31+
/// <param name="hashCode">The <see cref="HashCode"/> which will receive the item to hash.</param>
32+
/// <param name="item">The item to hash into the <see cref="HashCode"/>.</param>
33+
/// <typeparam name="T">The underlying type of the item to hash.</typeparam>
34+
/// <returns>Returns the <see cref="HashCode"/> containing the added item.</returns>
35+
public static HashCode AddItem<T>(this HashCode hashCode, T item)
36+
{
37+
hashCode.Add(item);
38+
return hashCode;
39+
}
40+
41+
/// <summary>
42+
/// Adds the items to be hashed into a <see cref="HashCode"/> instance.
43+
/// </summary>
44+
/// <param name="hashCode">The <see cref="HashCode"/> which will receive the items to hash.</param>
45+
/// <param name="items">The items to hash into the <see cref="HashCode"/>.</param>
46+
/// <typeparam name="T">The underlying type of the items to hash.</typeparam>
47+
/// <returns>Returns the <see cref="HashCode"/> containing the added items.</returns>
48+
public static HashCode AddItems<T>(this HashCode hashCode, IEnumerable<T> items)
49+
{
50+
items.ForEach(hashCode.Add);
51+
return hashCode;
52+
}
53+
}
54+
}

OnixLabs.Core/OnixLabs.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<Title>OnixLabs.Core</Title>
99
<Authors>ONIXLabs</Authors>
1010
<Description>ONIXLabs Core API for .NET</Description>
11-
<AssemblyVersion>2.0.0</AssemblyVersion>
11+
<AssemblyVersion>2.1.0</AssemblyVersion>
1212
<NeutralLanguage>en</NeutralLanguage>
1313
<Copyright>Copyright © ONIXLabs 2020-2021</Copyright>
1414
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
15-
<PackageVersion>2.0.0</PackageVersion>
15+
<PackageVersion>2.1.0</PackageVersion>
1616
</PropertyGroup>
1717

1818
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

OnixLabs.Core/Text/Base16.Equatable.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
namespace OnixLabs.Core.Text
1919
{
20-
/// <summary>
21-
/// Represents a Base-16 (hexadecimal) value.
22-
/// </summary>
2320
public readonly partial struct Base16 : IEquatable<Base16>
2421
{
2522
/// <summary>
@@ -70,7 +67,9 @@ public override bool Equals(object? obj)
7067
/// <returns>A hash code for this instance.</returns>
7168
public override int GetHashCode()
7269
{
73-
return HashCode.Combine(Value);
70+
return new HashCode()
71+
.AddItems(Value)
72+
.ToHashCode();
7473
}
7574
}
7675
}

OnixLabs.Core/Text/Base16.From.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
namespace OnixLabs.Core.Text
2020
{
21-
/// <summary>
22-
/// Represents a Base-16 (hexadecimal) value.
23-
/// </summary>
2421
public readonly partial struct Base16
2522
{
2623
/// <summary>

OnixLabs.Core/Text/Base16.Parse.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
namespace OnixLabs.Core.Text
1818
{
19-
/// <summary>
20-
/// Represents a Base-16 (hexadecimal) value.
21-
/// </summary>
2219
public readonly partial struct Base16
2320
{
2421
/// <summary>

OnixLabs.Core/Text/Base16.To.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
namespace OnixLabs.Core.Text
1919
{
20-
/// <summary>
21-
/// Represents a Base-16 (hexadecimal) value.
22-
/// </summary>
2320
public readonly partial struct Base16
2421
{
2522
/// <summary>

OnixLabs.Core/Text/Base32.Codec.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
namespace OnixLabs.Core.Text
1919
{
20-
/// <summary>
21-
/// Represents a Base-32 value.
22-
/// </summary>
2320
public readonly partial struct Base32
2421
{
2522
/// <summary>

0 commit comments

Comments
 (0)