diff --git a/Sources/SortedCollections/SortedDictionary/SortedDictionary+Keys.swift b/Sources/SortedCollections/SortedDictionary/SortedDictionary+Keys.swift index 71dd4e5d..00c0a081 100644 --- a/Sources/SortedCollections/SortedDictionary/SortedDictionary+Keys.swift +++ b/Sources/SortedCollections/SortedDictionary/SortedDictionary+Keys.swift @@ -239,7 +239,7 @@ extension SortedDictionary.Keys: Equatable { public static func ==(lhs: Self, rhs: Self) -> Bool { if lhs.count != rhs.count { return false } for (e1, e2) in zip(lhs, rhs) { - if e1 == e2 { + if e1 != e2 { return false } } diff --git a/Sources/SortedCollections/SortedDictionary/SortedDictionary+SubSequence.swift b/Sources/SortedCollections/SortedDictionary/SortedDictionary+SubSequence.swift index 56880112..720f14a7 100644 --- a/Sources/SortedCollections/SortedDictionary/SortedDictionary+SubSequence.swift +++ b/Sources/SortedCollections/SortedDictionary/SortedDictionary+SubSequence.swift @@ -300,7 +300,7 @@ extension SortedDictionary.SubSequence: Equatable where Value: Equatable { public static func ==(lhs: Self, rhs: Self) -> Bool { if lhs.count != rhs.count { return false } for (e1, e2) in zip(lhs, rhs) { - if e1 == e2 { + if e1 != e2 { return false } } diff --git a/Sources/SortedCollections/SortedDictionary/SortedDictionary+Values.swift b/Sources/SortedCollections/SortedDictionary/SortedDictionary+Values.swift index e75f3e44..f99cdd8b 100644 --- a/Sources/SortedCollections/SortedDictionary/SortedDictionary+Values.swift +++ b/Sources/SortedCollections/SortedDictionary/SortedDictionary+Values.swift @@ -258,7 +258,7 @@ extension SortedDictionary.Values: Equatable where Value: Equatable { public static func ==(lhs: Self, rhs: Self) -> Bool { if lhs.count != rhs.count { return false } for (e1, e2) in zip(lhs, rhs) { - if e1 == e2 { + if e1 != e2 { return false } } diff --git a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift index d12e62a0..fc25dddd 100644 --- a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift +++ b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift @@ -284,6 +284,97 @@ final class SortedDictionaryTests: CollectionTestCase { } } } + + func test_keys_Equatable() { + let left: SortedDictionary = [ + 1: "one", + 2: "two", + 3: "three", + ] + let rightEqual: SortedDictionary = [ + 3: "trois", + 1: "un", + 2: "deux", + ] + let rightUnequal: SortedDictionary = [ + 1: "one", + 2: "two", + 4: "four", + ] + + expectEqual(left.keys, left.keys) + expectEqual(left.keys, rightEqual.keys) + expectNotEqual(left.keys, rightUnequal.keys) + + checkEquatable(equivalenceClasses: [ + [SortedDictionary().keys, SortedDictionary().keys], + [left.keys, rightEqual.keys], + [rightUnequal.keys], + ]) + } + + func test_values_Equatable() { + let left: SortedDictionary = [ + 1: "one", + 2: "two", + 3: "three", + ] + let rightEqual: SortedDictionary = [ + 1: "one", + 2: "two", + 3: "three", + ] + let rightUnequal: SortedDictionary = [ + 1: "one", + 2: "two", + 3: "trois", + ] + + expectEqual(left.values, left.values) + expectEqual(left.values, rightEqual.values) + expectNotEqual(left.values, rightUnequal.values) + + checkEquatable(equivalenceClasses: [ + [SortedDictionary().values, SortedDictionary().values], + [left.values, rightEqual.values], + [rightUnequal.values], + ]) + } + + func test_subSequence_Equatable() { + let left: SortedDictionary = [ + 1: "one", + 2: "two", + 3: "three", + 4: "four", + ] + let rightEqual: SortedDictionary = [ + 1: "one", + 2: "two", + 3: "three", + 4: "four", + ] + let rightUnequal: SortedDictionary = [ + 1: "one", + 2: "two", + 3: "trois", + 4: "four", + ] + + let leftSlice = left[left.index(after: left.startIndex)..