Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more equatable array tests #147

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/StronglyTypedIds/EquatableArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public bool Equals(EquatableArray<T> array)
/// <sinheritdoc/>
public override bool Equals(object? obj)
{
return obj is EquatableArray<T> array && Equals(array);
return obj is EquatableArray<T> array && this.Equals(array);
}

/// <sinheritdoc/>
Expand Down
59 changes: 55 additions & 4 deletions test/StronglyTypedIds.Tests/EqualityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,61 @@ public void ResultWithDiagnosticHasExpectedEqualityBehaviour()
}

[Fact]
public void EquatableArrayOverridenEqualsComparesAsExpected() {
var instance = new EquatableArray<string>(["A"]);
object comparand = new EquatableArray<string>(["A"]);
public void EquatableArray_PrimitiveComparison()
{
int[] val1 = [1, 2, 3, 4, 5];
int[] val2 = [1, 2, 3, 4, 5];

var arr1 = new EquatableArray<int>(val1);
var arr2 = new EquatableArray<int>(val2);

Assert.True(arr1.Equals(arr2));
}

[Fact]
public void EquatableArray_RecordComparison()
{
Record[] val1 = [new(1), new(2), new(3), new(4), new(5)];
Record[] val2 = [new(1), new(2), new(3), new(4), new(5)];

var arr1 = new EquatableArray<Record>(val1);
var arr2 = new EquatableArray<Record>(val2);

Assert.True(arr1.Equals(arr2));
}

[Fact]
public void EquatableArray_NestedEquatableArrayComparison()
{
EquatableArray<int>[] val1 = [new([1]), new([2]), new([3]), new([4]), new([5])];
EquatableArray<int>[] val2 = [new([1]), new([2]), new([3]), new([4]), new([5])];

var arr1 = new EquatableArray<EquatableArray<int>>(val1);
var arr2 = new EquatableArray<EquatableArray<int>>(val2);

Assert.True(arr1.Equals(arr2));
}

[Fact]
public void EquatableArray_BoxedNestedEquatableArrayComparison()
{
EquatableArray<int>[] val1 = [new([1]), new([2]), new([3]), new([4]), new([5])];
EquatableArray<int>[] val2 = [new([1]), new([2]), new([3]), new([4]), new([5])];

object arr1 = new EquatableArray<EquatableArray<int>>(val1);
var arr2 = new EquatableArray<EquatableArray<int>>(val2);

Assert.True(arr1.Equals(arr2));
Assert.True(arr2.Equals(arr1));
}

public record Record
{
public Record(int value)
{
Value = value;
}

Assert.True(instance.Equals(comparand));
public int Value { get; }
}
}
Loading