Skip to content

Commit

Permalink
Merge pull request #8 from pfpack/release/v1.0.2
Browse files Browse the repository at this point in the history
release/v1.0.2
  • Loading branch information
andreise authored Jan 2, 2025
2 parents 1bb18db + a2202e9 commit 9c7470e
Show file tree
Hide file tree
Showing 29 changed files with 573 additions and 350 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022-2024 Andrei Sergeev, Pavel Moskovoy
Copyright (c) 2022-2025 Andrei Sergeev, Pavel Moskovoy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public static void Test_GetHashCode_InputsAreEqual_ExpectHashCodesAreEqual(CaseP
Assert.StrictEqual(hashCode1, hashCode2);
}

[Theory]
[MemberData(nameof(GetHashCode_InputsAreNotEqualCases))]
public static void Test_GetHashCode_InputsAreNotEqual_ExpectHashCodesAreNotEqual(CaseParamOfArray<T> input1, CaseParamOfArray<T> input2)
{
var comparer = BuildComparer();
var hashCode1 = comparer.GetHashCode(input1.Items);
var hashCode2 = comparer.GetHashCode(input2.Items);
Assert.NotStrictEqual(hashCode1, hashCode2);
}

[Theory]
[MemberData(nameof(InputsAreEqualCases))]
public static void Test_Equals_InputsAreEqual_ExpectTrue(CaseParamOfArray<T> input1, CaseParamOfArray<T> input2)
Expand All @@ -40,8 +50,8 @@ public static void Test_Equals_InputsAreEqual_ExpectTrue(CaseParamOfArray<T> inp
}

[Theory]
[MemberData(nameof(InputsAreNotEqualCases))]
public static void Test_Equals_InputsAreNotEqual_ExpectTrue(CaseParamOfArray<T> input1, CaseParamOfArray<T> input2)
[MemberData(nameof(Equals_InputsAreNotEqualCases))]
public static void Test_Equals_InputsAreNotEqual_ExpectFalse(CaseParamOfArray<T> input1, CaseParamOfArray<T> input2)
{
var comparer = BuildComparer();
var actualEquals = comparer.Equals(input1.Items, input2.Items);
Expand Down Expand Up @@ -74,11 +84,15 @@ public static void Test_Equals_InputsAreNotEqual_ExpectTrue(CaseParamOfArray<T>

public static TheoryData<CaseParamOfArray<T>, CaseParamOfArray<T>> InputsAreEqualCases()
=>
MapEqualsCases(CaseSources.EqualArrays<T>());
MapEqualsCases(EqualCaseSource.EqualArrays<T>());

public static TheoryData<CaseParamOfArray<T>, CaseParamOfArray<T>> Equals_InputsAreNotEqualCases()
=>
MapEqualsCases(NotEqualCaseSource_Equals.NotEqualArrays<T>());

public static TheoryData<CaseParamOfArray<T>, CaseParamOfArray<T>> InputsAreNotEqualCases()
public static TheoryData<CaseParamOfArray<T>, CaseParamOfArray<T>> GetHashCode_InputsAreNotEqualCases()
=>
MapEqualsCases(CaseSources.NotEqualArrays<T>());
MapEqualsCases(NotEqualCaseSource_GetHashCode.NotEqualArrays<T>());

private static ArrayEqualityComparer<T> BuildComparer()
=>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma warning disable IDE0300 // Simplify collection initialization

using System.Collections.Generic;

namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;

partial class EqualCaseSource
{
private static IEnumerable<(int?[]? X, int?[]? Y)> InnerEqualArraysOfInt32Nullable()
{
// Equal by reference

yield return (
null,
null
);
yield return (
EmptyArray<int?>.Value,
EmptyArray<int?>.Value
);
var array1 = new int?[] { 1 };
var array2 = new int?[] { 1, 2 };
var array3 = new int?[] { 1, 2, 3 };
var array4 = new int?[] { 1, 2, 3, 4 };
yield return (
array1,
array1
);
yield return (
array2,
array2
);
yield return (
array3,
array3
);
yield return (
array4,
array4
);

// Equal by value

yield return (
new int?[] { null },
new int?[] { null }
);
yield return (
EmptyArray<int?>.Create(),
EmptyArray<int?>.Create()
);
yield return (
new int?[] { 1 },
new int?[] { 1 }
);
yield return (
new int?[] { 1, 2 },
new int?[] { 1, 2 }
);
yield return (
new int?[] { 1, 2, 3 },
new int?[] { 1, 2, 3 }
);
yield return (
new int?[] { 1, 2, 3, 4 },
new int?[] { 1, 2, 3, 4 }
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma warning disable IDE0300 // Simplify collection initialization

using System.Collections.Generic;

namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;

partial class EqualCaseSource
{
private static IEnumerable<(string?[]? X, string?[]? Y)> InnerEqualArraysOfString()
{
// Equal by reference

yield return (
null,
null
);
yield return (
EmptyArray<string>.Value,
EmptyArray<string>.Value
);
var array1 = new[] { "1" };
var array2 = new[] { "1", "2" };
var array3 = new[] { "1", "2", "3" };
var array4 = new[] { "1", "2", "3", "4" };
yield return (
array1,
array1
);
yield return (
array2,
array2
);
yield return (
array3,
array3
);
yield return (
array4,
array4
);

// Equal by value

yield return (
new[] { (string?)null },
new[] { (string?)null }
);
yield return (
EmptyArray<string>.Create(),
EmptyArray<string>.Create()
);
yield return (
new[] { "1" },
new[] { "1" }
);
yield return (
new[] { "1", "2" },
new[] { "1", "2" }
);
yield return (
new[] { "1", "2", "3" },
new[] { "1", "2", "3" }
);
yield return (
new[] { "1", "2", "3", "4" },
new[] { "1", "2", "3", "4" }
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;

namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;

internal static partial class EqualCaseSource
{
internal static IEnumerable<(T[]? X, T[]? Y)> EqualArrays<T>()
{
if (typeof(T) == typeof(string))
{
return (IEnumerable<(T[]? X, T[]? Y)>)InnerEqualArraysOfString();
}

if (typeof(T) == typeof(int?))
{
return (IEnumerable<(T[]? X, T[]? Y)>)InnerEqualArraysOfInt32Nullable();
}

throw new ArgumentException($"An unexpected type ({typeof(T).Name}).", nameof(T));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma warning disable IDE0300 // Simplify collection initialization

using System.Collections.Generic;

namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;

partial class NotEqualCaseSource_Equals
{
private static IEnumerable<(int?[]? X, int?[]? Y)> InnerNotEqualArraysOfInt32Nullable()
{
yield return (
null,
EmptyArray<int?>.Value);
yield return (
null,
new int?[] { 1 }
);
yield return (
EmptyArray<int?>.Value,
new int?[] { 1 }
);
yield return (
new int?[] { 1 },
new int?[] { 1, 2 }
);
yield return (
new int?[] { 1, 2 },
new int?[] { 1, 2, 3 }
);
yield return (
new int?[] { 1, 2, 3 },
new int?[] { 1, 2, 3, 4 }
);
yield return (
new int?[] { null },
new int?[] { 0 }
);
yield return (
new int?[] { null },
new int?[] { 1 }
);
yield return (
new int?[] { 1 },
new int?[] { 2 }
);
yield return (
new int?[] { 1, 2 },
new int?[] { 1, 1 }
);
yield return (
new int?[] { 1, 2, 3 },
new int?[] { 1, 0, 3 }
);
yield return (
new int?[] { 1, 2, 3, 4 },
new int?[] { 0, 2, 3, 4 }
);
yield return (
new int?[] { 1, 2, 3, 4 },
new int?[] { 1, 1, 3, 4 }
);
yield return (
new int?[] { 1, 2, 3, 4 },
new int?[] { 1, 2, 2, 4 }
);
yield return (
new int?[] { 1, 2, 3, 4 },
new int?[] { 1, 2, 3, 3 }
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma warning disable IDE0300 // Simplify collection initialization

using System.Collections.Generic;

namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;

partial class NotEqualCaseSource_Equals
{
private static IEnumerable<(string?[]? X, string?[]? Y)> InnerNotEqualArraysOfString()
{
yield return (
null,
EmptyArray<string>.Value);
yield return (
null,
new[] { "1" }
);
yield return (
EmptyArray<string>.Value,
new[] { "1" }
);
yield return (
new[] { "1" },
new[] { "1", "2" }
);
yield return (
new[] { "1", "2" },
new[] { "1", "2", "3" }
);
yield return (
new[] { "1", "2", "3" },
new[] { "1", "2", "3", "4" }
);
yield return (
new[] { (string?)null },
new[] { "" }
);
yield return (
new[] { (string?)null },
new[] { "1" }
);
yield return (
new[] { "1" },
new[] { "2" }
);
yield return (
new[] { "1", "2" },
new[] { "1", "1" }
);
yield return (
new[] { "1", "2", "3" },
new[] { "1", "0", "3" }
);
yield return (
new[] { "1", "2", "3", "4" },
new[] { "0", "2", "3", "4" }
);
yield return (
new[] { "1", "2", "3", "4" },
new[] { "1", "1", "3", "4" }
);
yield return (
new[] { "1", "2", "3", "4" },
new[] { "1", "2", "2", "4" }
);
yield return (
new[] { "1", "2", "3", "4" },
new[] { "1", "2", "3", "3" }
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;

internal static partial class NotEqualCaseSource_Equals
{
internal static IEnumerable<(T[]? X, T[]? Y)> NotEqualArrays<T>()
=>
InnerNotEqualArrays<T>().ToArray() switch
{
var pairs => pairs.Concat(pairs.Select(pair => (pair.Y, pair.X)))
};

private static IEnumerable<(T[]? X, T[]? Y)> InnerNotEqualArrays<T>()
{
if (typeof(T) == typeof(string))
{
return (IEnumerable<(T[]? X, T[]? Y)>)InnerNotEqualArraysOfString();
}

if (typeof(T) == typeof(int?))
{
return (IEnumerable<(T[]? X, T[]? Y)>)InnerNotEqualArraysOfInt32Nullable();
}

throw new ArgumentException($"An unexpected type ({typeof(T).Name}).", nameof(T));
}
}
Loading

0 comments on commit 9c7470e

Please sign in to comment.