Skip to content

Commit 9c7470e

Browse files
authored
Merge pull request #8 from pfpack/release/v1.0.2
release/v1.0.2
2 parents 1bb18db + a2202e9 commit 9c7470e

29 files changed

+573
-350
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

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

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/collections-generic-equalitycomparers/Collections.Generic.EqualityComparers.Tests/Array/ArrayEqualityComparer_TestsBase.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public static void Test_GetHashCode_InputsAreEqual_ExpectHashCodesAreEqual(CaseP
3030
Assert.StrictEqual(hashCode1, hashCode2);
3131
}
3232

33+
[Theory]
34+
[MemberData(nameof(GetHashCode_InputsAreNotEqualCases))]
35+
public static void Test_GetHashCode_InputsAreNotEqual_ExpectHashCodesAreNotEqual(CaseParamOfArray<T> input1, CaseParamOfArray<T> input2)
36+
{
37+
var comparer = BuildComparer();
38+
var hashCode1 = comparer.GetHashCode(input1.Items);
39+
var hashCode2 = comparer.GetHashCode(input2.Items);
40+
Assert.NotStrictEqual(hashCode1, hashCode2);
41+
}
42+
3343
[Theory]
3444
[MemberData(nameof(InputsAreEqualCases))]
3545
public static void Test_Equals_InputsAreEqual_ExpectTrue(CaseParamOfArray<T> input1, CaseParamOfArray<T> input2)
@@ -40,8 +50,8 @@ public static void Test_Equals_InputsAreEqual_ExpectTrue(CaseParamOfArray<T> inp
4050
}
4151

4252
[Theory]
43-
[MemberData(nameof(InputsAreNotEqualCases))]
44-
public static void Test_Equals_InputsAreNotEqual_ExpectTrue(CaseParamOfArray<T> input1, CaseParamOfArray<T> input2)
53+
[MemberData(nameof(Equals_InputsAreNotEqualCases))]
54+
public static void Test_Equals_InputsAreNotEqual_ExpectFalse(CaseParamOfArray<T> input1, CaseParamOfArray<T> input2)
4555
{
4656
var comparer = BuildComparer();
4757
var actualEquals = comparer.Equals(input1.Items, input2.Items);
@@ -74,11 +84,15 @@ public static void Test_Equals_InputsAreNotEqual_ExpectTrue(CaseParamOfArray<T>
7484

7585
public static TheoryData<CaseParamOfArray<T>, CaseParamOfArray<T>> InputsAreEqualCases()
7686
=>
77-
MapEqualsCases(CaseSources.EqualArrays<T>());
87+
MapEqualsCases(EqualCaseSource.EqualArrays<T>());
88+
89+
public static TheoryData<CaseParamOfArray<T>, CaseParamOfArray<T>> Equals_InputsAreNotEqualCases()
90+
=>
91+
MapEqualsCases(NotEqualCaseSource_Equals.NotEqualArrays<T>());
7892

79-
public static TheoryData<CaseParamOfArray<T>, CaseParamOfArray<T>> InputsAreNotEqualCases()
93+
public static TheoryData<CaseParamOfArray<T>, CaseParamOfArray<T>> GetHashCode_InputsAreNotEqualCases()
8094
=>
81-
MapEqualsCases(CaseSources.NotEqualArrays<T>());
95+
MapEqualsCases(NotEqualCaseSource_GetHashCode.NotEqualArrays<T>());
8296

8397
private static ArrayEqualityComparer<T> BuildComparer()
8498
=>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#pragma warning disable IDE0300 // Simplify collection initialization
2+
3+
using System.Collections.Generic;
4+
5+
namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;
6+
7+
partial class EqualCaseSource
8+
{
9+
private static IEnumerable<(int?[]? X, int?[]? Y)> InnerEqualArraysOfInt32Nullable()
10+
{
11+
// Equal by reference
12+
13+
yield return (
14+
null,
15+
null
16+
);
17+
yield return (
18+
EmptyArray<int?>.Value,
19+
EmptyArray<int?>.Value
20+
);
21+
var array1 = new int?[] { 1 };
22+
var array2 = new int?[] { 1, 2 };
23+
var array3 = new int?[] { 1, 2, 3 };
24+
var array4 = new int?[] { 1, 2, 3, 4 };
25+
yield return (
26+
array1,
27+
array1
28+
);
29+
yield return (
30+
array2,
31+
array2
32+
);
33+
yield return (
34+
array3,
35+
array3
36+
);
37+
yield return (
38+
array4,
39+
array4
40+
);
41+
42+
// Equal by value
43+
44+
yield return (
45+
new int?[] { null },
46+
new int?[] { null }
47+
);
48+
yield return (
49+
EmptyArray<int?>.Create(),
50+
EmptyArray<int?>.Create()
51+
);
52+
yield return (
53+
new int?[] { 1 },
54+
new int?[] { 1 }
55+
);
56+
yield return (
57+
new int?[] { 1, 2 },
58+
new int?[] { 1, 2 }
59+
);
60+
yield return (
61+
new int?[] { 1, 2, 3 },
62+
new int?[] { 1, 2, 3 }
63+
);
64+
yield return (
65+
new int?[] { 1, 2, 3, 4 },
66+
new int?[] { 1, 2, 3, 4 }
67+
);
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#pragma warning disable IDE0300 // Simplify collection initialization
2+
3+
using System.Collections.Generic;
4+
5+
namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;
6+
7+
partial class EqualCaseSource
8+
{
9+
private static IEnumerable<(string?[]? X, string?[]? Y)> InnerEqualArraysOfString()
10+
{
11+
// Equal by reference
12+
13+
yield return (
14+
null,
15+
null
16+
);
17+
yield return (
18+
EmptyArray<string>.Value,
19+
EmptyArray<string>.Value
20+
);
21+
var array1 = new[] { "1" };
22+
var array2 = new[] { "1", "2" };
23+
var array3 = new[] { "1", "2", "3" };
24+
var array4 = new[] { "1", "2", "3", "4" };
25+
yield return (
26+
array1,
27+
array1
28+
);
29+
yield return (
30+
array2,
31+
array2
32+
);
33+
yield return (
34+
array3,
35+
array3
36+
);
37+
yield return (
38+
array4,
39+
array4
40+
);
41+
42+
// Equal by value
43+
44+
yield return (
45+
new[] { (string?)null },
46+
new[] { (string?)null }
47+
);
48+
yield return (
49+
EmptyArray<string>.Create(),
50+
EmptyArray<string>.Create()
51+
);
52+
yield return (
53+
new[] { "1" },
54+
new[] { "1" }
55+
);
56+
yield return (
57+
new[] { "1", "2" },
58+
new[] { "1", "2" }
59+
);
60+
yield return (
61+
new[] { "1", "2", "3" },
62+
new[] { "1", "2", "3" }
63+
);
64+
yield return (
65+
new[] { "1", "2", "3", "4" },
66+
new[] { "1", "2", "3", "4" }
67+
);
68+
}
69+
70+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;
5+
6+
internal static partial class EqualCaseSource
7+
{
8+
internal static IEnumerable<(T[]? X, T[]? Y)> EqualArrays<T>()
9+
{
10+
if (typeof(T) == typeof(string))
11+
{
12+
return (IEnumerable<(T[]? X, T[]? Y)>)InnerEqualArraysOfString();
13+
}
14+
15+
if (typeof(T) == typeof(int?))
16+
{
17+
return (IEnumerable<(T[]? X, T[]? Y)>)InnerEqualArraysOfInt32Nullable();
18+
}
19+
20+
throw new ArgumentException($"An unexpected type ({typeof(T).Name}).", nameof(T));
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma warning disable IDE0300 // Simplify collection initialization
2+
3+
using System.Collections.Generic;
4+
5+
namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;
6+
7+
partial class NotEqualCaseSource_Equals
8+
{
9+
private static IEnumerable<(int?[]? X, int?[]? Y)> InnerNotEqualArraysOfInt32Nullable()
10+
{
11+
yield return (
12+
null,
13+
EmptyArray<int?>.Value);
14+
yield return (
15+
null,
16+
new int?[] { 1 }
17+
);
18+
yield return (
19+
EmptyArray<int?>.Value,
20+
new int?[] { 1 }
21+
);
22+
yield return (
23+
new int?[] { 1 },
24+
new int?[] { 1, 2 }
25+
);
26+
yield return (
27+
new int?[] { 1, 2 },
28+
new int?[] { 1, 2, 3 }
29+
);
30+
yield return (
31+
new int?[] { 1, 2, 3 },
32+
new int?[] { 1, 2, 3, 4 }
33+
);
34+
yield return (
35+
new int?[] { null },
36+
new int?[] { 0 }
37+
);
38+
yield return (
39+
new int?[] { null },
40+
new int?[] { 1 }
41+
);
42+
yield return (
43+
new int?[] { 1 },
44+
new int?[] { 2 }
45+
);
46+
yield return (
47+
new int?[] { 1, 2 },
48+
new int?[] { 1, 1 }
49+
);
50+
yield return (
51+
new int?[] { 1, 2, 3 },
52+
new int?[] { 1, 0, 3 }
53+
);
54+
yield return (
55+
new int?[] { 1, 2, 3, 4 },
56+
new int?[] { 0, 2, 3, 4 }
57+
);
58+
yield return (
59+
new int?[] { 1, 2, 3, 4 },
60+
new int?[] { 1, 1, 3, 4 }
61+
);
62+
yield return (
63+
new int?[] { 1, 2, 3, 4 },
64+
new int?[] { 1, 2, 2, 4 }
65+
);
66+
yield return (
67+
new int?[] { 1, 2, 3, 4 },
68+
new int?[] { 1, 2, 3, 3 }
69+
);
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma warning disable IDE0300 // Simplify collection initialization
2+
3+
using System.Collections.Generic;
4+
5+
namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;
6+
7+
partial class NotEqualCaseSource_Equals
8+
{
9+
private static IEnumerable<(string?[]? X, string?[]? Y)> InnerNotEqualArraysOfString()
10+
{
11+
yield return (
12+
null,
13+
EmptyArray<string>.Value);
14+
yield return (
15+
null,
16+
new[] { "1" }
17+
);
18+
yield return (
19+
EmptyArray<string>.Value,
20+
new[] { "1" }
21+
);
22+
yield return (
23+
new[] { "1" },
24+
new[] { "1", "2" }
25+
);
26+
yield return (
27+
new[] { "1", "2" },
28+
new[] { "1", "2", "3" }
29+
);
30+
yield return (
31+
new[] { "1", "2", "3" },
32+
new[] { "1", "2", "3", "4" }
33+
);
34+
yield return (
35+
new[] { (string?)null },
36+
new[] { "" }
37+
);
38+
yield return (
39+
new[] { (string?)null },
40+
new[] { "1" }
41+
);
42+
yield return (
43+
new[] { "1" },
44+
new[] { "2" }
45+
);
46+
yield return (
47+
new[] { "1", "2" },
48+
new[] { "1", "1" }
49+
);
50+
yield return (
51+
new[] { "1", "2", "3" },
52+
new[] { "1", "0", "3" }
53+
);
54+
yield return (
55+
new[] { "1", "2", "3", "4" },
56+
new[] { "0", "2", "3", "4" }
57+
);
58+
yield return (
59+
new[] { "1", "2", "3", "4" },
60+
new[] { "1", "1", "3", "4" }
61+
);
62+
yield return (
63+
new[] { "1", "2", "3", "4" },
64+
new[] { "1", "2", "2", "4" }
65+
);
66+
yield return (
67+
new[] { "1", "2", "3", "4" },
68+
new[] { "1", "2", "3", "3" }
69+
);
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace PrimeFuncPack.Collections.Generic.EqualityComparers.Tests;
6+
7+
internal static partial class NotEqualCaseSource_Equals
8+
{
9+
internal static IEnumerable<(T[]? X, T[]? Y)> NotEqualArrays<T>()
10+
=>
11+
InnerNotEqualArrays<T>().ToArray() switch
12+
{
13+
var pairs => pairs.Concat(pairs.Select(pair => (pair.Y, pair.X)))
14+
};
15+
16+
private static IEnumerable<(T[]? X, T[]? Y)> InnerNotEqualArrays<T>()
17+
{
18+
if (typeof(T) == typeof(string))
19+
{
20+
return (IEnumerable<(T[]? X, T[]? Y)>)InnerNotEqualArraysOfString();
21+
}
22+
23+
if (typeof(T) == typeof(int?))
24+
{
25+
return (IEnumerable<(T[]? X, T[]? Y)>)InnerNotEqualArraysOfInt32Nullable();
26+
}
27+
28+
throw new ArgumentException($"An unexpected type ({typeof(T).Name}).", nameof(T));
29+
}
30+
}

0 commit comments

Comments
 (0)