Skip to content

Commit

Permalink
add more tests (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock authored Oct 1, 2024
1 parent 4096966 commit 1c1ff56
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
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; }
}
}

0 comments on commit 1c1ff56

Please sign in to comment.