Skip to content

Commit 93cc584

Browse files
Merge branch 'refs/heads/main' into release
2 parents 1778ba8 + 1bee0a6 commit 93cc584

18 files changed

+143
-12
lines changed

OnixLabs.Core.UnitTests/Text/Base16Tests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ public void Base16ShouldNotChangeWhenModifyingObtainedByteArray()
5252
Assert.Equal(expected, actual);
5353
}
5454

55+
[Fact(DisplayName = "Base16 default values should be identical")]
56+
public void Base16DefaultValuesShouldBeIdentical()
57+
{
58+
// Given
59+
Base16 a = new();
60+
Base16 b = default;
61+
62+
// Then
63+
Assert.Equal(a, b);
64+
Assert.Equal(a.GetHashCode(), b.GetHashCode());
65+
Assert.True(a.Equals(b));
66+
Assert.True(a == b);
67+
Assert.False(a != b);
68+
}
69+
5570
[Fact(DisplayName = "Base16 values should be identical")]
5671
public void Base16ValuesShouldBeIdentical()
5772
{

OnixLabs.Core.UnitTests/Text/Base32Tests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ public void Base32ShouldNotChangeWhenModifyingObtainedByteArray()
5252
Assert.Equal(expected, actual);
5353
}
5454

55+
[Fact(DisplayName = "Base32 default values should be identical")]
56+
public void Base32DefaultValuesShouldBeIdentical()
57+
{
58+
// Given
59+
Base32 a = new();
60+
Base32 b = default;
61+
62+
// Then
63+
Assert.Equal(a, b);
64+
Assert.Equal(a.GetHashCode(), b.GetHashCode());
65+
Assert.True(a.Equals(b));
66+
Assert.True(a == b);
67+
Assert.False(a != b);
68+
}
69+
5570
[Fact(DisplayName = "Base32 values should be identical")]
5671
public void Base32ValuesShouldBeIdentical()
5772
{

OnixLabs.Core.UnitTests/Text/Base58Tests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ public void Base58ShouldNotChangeWhenModifyingObtainedByteArray()
5252
Assert.Equal(expected, actual);
5353
}
5454

55+
[Fact(DisplayName = "Base58 default values should be identical")]
56+
public void Base58DefaultValuesShouldBeIdentical()
57+
{
58+
// Given
59+
Base58 a = new();
60+
Base58 b = default;
61+
62+
// Then
63+
Assert.Equal(a, b);
64+
Assert.Equal(a.GetHashCode(), b.GetHashCode());
65+
Assert.True(a.Equals(b));
66+
Assert.True(a == b);
67+
Assert.False(a != b);
68+
}
69+
5570
[Fact(DisplayName = "Base58 values should be identical")]
5671
public void Base58ValuesShouldBeIdentical()
5772
{

OnixLabs.Core.UnitTests/Text/Base64Tests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ public void Base64ShouldNotChangeWhenModifyingObtainedByteArray()
5252
Assert.Equal(expected, actual);
5353
}
5454

55+
[Fact(DisplayName = "Base64 default values should be identical")]
56+
public void Base64DefaultValuesShouldBeIdentical()
57+
{
58+
// Given
59+
Base64 a = new();
60+
Base64 b = default;
61+
62+
// Then
63+
Assert.Equal(a, b);
64+
Assert.Equal(a.GetHashCode(), b.GetHashCode());
65+
Assert.True(a.Equals(b));
66+
Assert.True(a == b);
67+
Assert.False(a != b);
68+
}
69+
5570
[Fact(DisplayName = "Base64 values should be identical")]
5671
public void Base64ValuesShouldBeIdentical()
5772
{

OnixLabs.Core/Linq/Extensions.IEnumerable.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
9090
/// <param name="enumerable">The current <see cref="IEnumerable{T}"/> from which to compute a content hash code.</param>
9191
/// <typeparam name="T">The underlying type of the <see cref="IEnumerable{T}"/>.</typeparam>
9292
/// <returns>Returns the computed content hash code of the current <see cref="IEnumerable{T}"/>.</returns>
93-
public static int GetContentHashCode<T>(this IEnumerable<T> enumerable)
93+
public static int GetContentHashCode<T>(this IEnumerable<T>? enumerable)
9494
{
95+
if (enumerable is null) return default;
96+
9597
HashCode result = new();
9698
enumerable.ForEach(element => result.Add(element));
9799
return result.ToHashCode();
@@ -173,6 +175,19 @@ public static Optional<T> LastOrNone<T>(this IEnumerable<T> enumerable, Func<T,
173175
/// <returns>Returns <see langword="true"/> if none of the elements of the current <see cref="IEnumerable{T}"/> satisfy the specified predicate condition; otherwise, <see langword="false"/>.</returns>
174176
public static bool None<T>(this IEnumerable<T> enumerable, Func<T, bool> predicate) => !enumerable.Any(predicate);
175177

178+
/// <summary>Determines whether two sequences are <see langword="null"/>, or equal by comparing their elements by using a specified <see cref="T:IEqualityComparer{T}" />.</summary>
179+
/// <param name="first">An <see cref="T:IEnumerable{T}" /> to compare to <paramref name="second" />.</param>
180+
/// <param name="second">An <see cref="T:IEnumerable{T}" /> to compare to the first sequence.</param>
181+
/// <param name="comparer">An <see cref="T:IEqualityComparer{T}" /> to use to compare elements.</param>
182+
/// <typeparam name="T">The underlying type of the <see cref="IEnumerable{T}"/>.</typeparam>
183+
/// <returns> Returns <see langword="true" /> if the two source sequences are <see langword="null"/>, or of equal length and their corresponding elements compare equal according to <paramref name="comparer" />; otherwise, <see langword="false" />.</returns>
184+
public static bool SequenceEqualOrNull<T>(this IEnumerable<T>? first, IEnumerable<T>? second, EqualityComparer<T>? comparer = null)
185+
{
186+
if (first is null && second is null) return true;
187+
if (first is null || second is null) return false;
188+
return first.SequenceEqual(second, comparer ?? EqualityComparer<T>.Default);
189+
}
190+
176191
/// <summary>
177192
/// Obtains a single element of the current <see cref="IEnumerable{T}"/> that satisfies the specified predicate;
178193
/// otherwise <see cref="Optional{T}.None"/> if no such element is found,

OnixLabs.Core/OnixLabs.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<NeutralLanguage>en</NeutralLanguage>
1212
<Copyright>Copyright © ONIXLabs 2020</Copyright>
1313
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
14-
<PackageVersion>8.4.0</PackageVersion>
14+
<PackageVersion>8.5.0</PackageVersion>
1515
<PackageLicenseUrl></PackageLicenseUrl>
1616
</PropertyGroup>
1717
<PropertyGroup>

OnixLabs.Core/Text/Base16.Equatable.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
using System.Linq;
1615
using OnixLabs.Core.Linq;
1716

1817
namespace OnixLabs.Core.Text;
@@ -24,7 +23,7 @@ public readonly partial struct Base16
2423
/// </summary>
2524
/// <param name="other">An object to compare with the current object.</param>
2625
/// <returns>Returns <see langword="true"/> if the current object is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
27-
public bool Equals(Base16 other) => other.value.SequenceEqual(value);
26+
public bool Equals(Base16 other) => other.value.SequenceEqualOrNull(value);
2827

2928
/// <summary>
3029
/// Checks for equality between the current instance and another object.

OnixLabs.Core/Text/Base32.Equatable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public readonly partial struct Base32
2424
/// </summary>
2525
/// <param name="other">An object to compare with the current object.</param>
2626
/// <returns>Returns <see langword="true"/> if the current object is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
27-
public bool Equals(Base32 other) => other.value.SequenceEqual(value);
27+
public bool Equals(Base32 other) => other.value.SequenceEqualOrNull(value);
2828

2929
/// <summary>
3030
/// Checks for equality between the current instance and another object.

OnixLabs.Core/Text/Base58.Equatable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public readonly partial struct Base58
2424
/// </summary>
2525
/// <param name="other">An object to compare with the current object.</param>
2626
/// <returns>Returns <see langword="true"/> if the current object is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
27-
public bool Equals(Base58 other) => other.value.SequenceEqual(value);
27+
public bool Equals(Base58 other) => other.value.SequenceEqualOrNull(value);
2828

2929
/// <summary>
3030
/// Checks for equality between the current instance and another object.

OnixLabs.Core/Text/Base64.Equatable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public readonly partial struct Base64
2424
/// </summary>
2525
/// <param name="other">An object to compare with the current object.</param>
2626
/// <returns>Returns <see langword="true"/> if the current object is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
27-
public bool Equals(Base64 other) => other.value.SequenceEqual(value);
27+
public bool Equals(Base64 other) => other.value.SequenceEqualOrNull(value);
2828

2929
/// <summary>
3030
/// Checks for equality between the current instance and another object.

0 commit comments

Comments
 (0)