From 0ee40f69a18dc344257893465ec89fdbc2d0d670 Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Mon, 30 Sep 2024 22:31:18 +0100 Subject: [PATCH] add more tests --- src/StronglyTypedIds/EquatableArray.cs | 2 +- test/StronglyTypedIds.Tests/EqualityTests.cs | 59 ++++++++++++++++++-- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/StronglyTypedIds/EquatableArray.cs b/src/StronglyTypedIds/EquatableArray.cs index fd4d1512..d3970db0 100644 --- a/src/StronglyTypedIds/EquatableArray.cs +++ b/src/StronglyTypedIds/EquatableArray.cs @@ -37,7 +37,7 @@ public bool Equals(EquatableArray array) /// public override bool Equals(object? obj) { - return obj is EquatableArray array && Equals(array); + return obj is EquatableArray array && this.Equals(array); } /// diff --git a/test/StronglyTypedIds.Tests/EqualityTests.cs b/test/StronglyTypedIds.Tests/EqualityTests.cs index 8b2eddc1..bfdc1c7a 100644 --- a/test/StronglyTypedIds.Tests/EqualityTests.cs +++ b/test/StronglyTypedIds.Tests/EqualityTests.cs @@ -151,10 +151,61 @@ public void ResultWithDiagnosticHasExpectedEqualityBehaviour() } [Fact] - public void EquatableArrayOverridenEqualsComparesAsExpected() { - var instance = new EquatableArray(["A"]); - object comparand = new EquatableArray(["A"]); + public void EquatableArray_PrimitiveComparison() + { + int[] val1 = [1, 2, 3, 4, 5]; + int[] val2 = [1, 2, 3, 4, 5]; + + var arr1 = new EquatableArray(val1); + var arr2 = new EquatableArray(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(val1); + var arr2 = new EquatableArray(val2); + + Assert.True(arr1.Equals(arr2)); + } + + [Fact] + public void EquatableArray_NestedEquatableArrayComparison() + { + EquatableArray[] val1 = [new([1]), new([2]), new([3]), new([4]), new([5])]; + EquatableArray[] val2 = [new([1]), new([2]), new([3]), new([4]), new([5])]; + + var arr1 = new EquatableArray>(val1); + var arr2 = new EquatableArray>(val2); + + Assert.True(arr1.Equals(arr2)); + } + + [Fact] + public void EquatableArray_BoxedNestedEquatableArrayComparison() + { + EquatableArray[] val1 = [new([1]), new([2]), new([3]), new([4]), new([5])]; + EquatableArray[] val2 = [new([1]), new([2]), new([3]), new([4]), new([5])]; + + object arr1 = new EquatableArray>(val1); + var arr2 = new EquatableArray>(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; } } } \ No newline at end of file