diff --git a/Bencodex.Tests/Types/ListTest.cs b/Bencodex.Tests/Types/ListTest.cs index ff21e25..be2e370 100644 --- a/Bencodex.Tests/Types/ListTest.cs +++ b/Bencodex.Tests/Types/ListTest.cs @@ -6,8 +6,6 @@ using Xunit; using static Bencodex.Misc.ImmutableByteArrayExtensions; using static Bencodex.Tests.TestUtils; -using IEquatableValues = - System.IEquatable>; namespace Bencodex.Tests.Types { @@ -204,48 +202,22 @@ public void Enumerate() public void Equality() { Assert.True(_zero.Equals(new List())); - Assert.True(((IEquatableValues)_zero).Equals(ImmutableArray.Empty)); Assert.True(_one.Equals(new List(Null.Value))); - Assert.True( - ((IEquatableValues)_one).Equals(ImmutableArray.Empty.Add(Null.Value)) - ); Assert.True(_two.Equals(new List((Text)"hello", (Text)"world"))); - Assert.True( - ((IEquatableValues)_two).Equals( - ImmutableArray.Create((Text)"hello", (Text)"world") - ) - ); Assert.True(_nest.Equals(new List(Null.Value, _zero, _one, _two))); - Assert.True( - ((IEquatableValues)_nest).Equals( - ImmutableArray.Create(Null.Value, _zero, _one, _two) - ) - ); Assert.False(_zero.Equals(_one)); - Assert.False(((IEquatableValues)_zero).Equals(_one)); Assert.False(_zero.Equals(_two)); - Assert.False(((IEquatableValues)_zero).Equals(_two)); Assert.False(_zero.Equals(_nest)); - Assert.False(((IEquatableValues)_zero).Equals(_nest)); Assert.False(_one.Equals(_zero)); - Assert.False(((IEquatableValues)_one).Equals(_zero)); Assert.False(_one.Equals(_two)); - Assert.False(((IEquatableValues)_one).Equals(_two)); Assert.False(_one.Equals(_nest)); - Assert.False(((IEquatableValues)_one).Equals(_nest)); Assert.False(_two.Equals(_zero)); - Assert.False(((IEquatableValues)_two).Equals(_zero)); Assert.False(_two.Equals(_one)); - Assert.False(((IEquatableValues)_two).Equals(_one)); Assert.False(_two.Equals(_nest)); - Assert.False(((IEquatableValues)_two).Equals(_nest)); Assert.False(_nest.Equals(_one)); - Assert.False(((IEquatableValues)_nest).Equals(_one)); Assert.False(_nest.Equals(_two)); - Assert.False(((IEquatableValues)_nest).Equals(_two)); Assert.False(_nest.Equals(_two)); - Assert.False(((IEquatableValues)_nest).Equals(_two)); } [Fact] diff --git a/Bencodex/Types/List.cs b/Bencodex/Types/List.cs index 9f98b92..905fdba 100644 --- a/Bencodex/Types/List.cs +++ b/Bencodex/Types/List.cs @@ -16,7 +16,6 @@ namespace Bencodex.Types public sealed class List : IValue, IImmutableList, - IEquatable>, IEquatable { /// @@ -259,36 +258,30 @@ public long EncodingLength /// public IValue this[int index] => _values[index]; - bool IEquatable>.Equals(IImmutableList other) - { - if (Count != other.Count) - { - return false; - } - else if (other is List otherList) - { - return Fingerprint.Equals(otherList.Fingerprint); - } + public override bool Equals(object obj) => obj is List l && Equals(l); + + public bool Equals(IValue other) => other is List l && Equals(l); - for (int i = 0; i < _values.Length; i++) + public bool Equals(List other) + { + if (Count == other.Count) { - IValue v = _values[i]; - IValue ov = other[i]; - if (!ov.Equals(v)) + for (int i = 0; i < Count; i++) { - return false; + if (!_values[i].Equals(other[i])) + { + return false; + } } - } - return true; + return true; + } + else + { + return false; + } } - /// - public bool Equals(List other) => Fingerprint.Equals(other.Fingerprint); - - bool IEquatable.Equals(IValue other) => - other is List o && Equals(o); - IEnumerator IEnumerable.GetEnumerator() { foreach (IValue element in _values) @@ -297,10 +290,6 @@ IEnumerator IEnumerable.GetEnumerator() } } - /// - public override bool Equals(object? obj) => obj is List other && - ((IEquatable>)this).Equals(other); - /// public override int GetHashCode() => unchecked(_values.Aggregate(GetType().GetHashCode(), (accum, next) diff --git a/CHANGES.md b/CHANGES.md index 70677d9..77a22a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ To be released. - Changed the behaviors of `Binary.Equals()` and `Binary.CompareTo()` to be more consistent. [[#106], [#110]] - Removed `ByteArrayComparer` and `FingerprintComparer`. [[#111]] + - Removed `IEquatable>` from `List`. [[#104], [#112]] [#104]: https://github.com/planetarium/bencodex.net/issues/104 [#106]: https://github.com/planetarium/bencodex.net/issues/106 @@ -29,6 +30,7 @@ To be released. [#109]: https://github.com/planetarium/bencodex.net/pull/109 [#110]: https://github.com/planetarium/bencodex.net/pull/110 [#111]: https://github.com/planetarium/bencodex.net/pull/111 +[#112]: https://github.com/planetarium/bencodex.net/pull/112 Version 0.14.0