Skip to content

Commit 9f553c8

Browse files
authored
Merge pull request #9 from klaaspieter/equality
Implement equality operators
2 parents 8c5af2d + 07f177c commit 9f553c8

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Sources/SortedArray.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,11 @@ extension SortedArray {
313313
return .notFound(insertAt: left)
314314
}
315315
}
316+
317+
public func ==<Element: Equatable> (lhs: SortedArray<Element>, rhs: SortedArray<Element>) -> Bool {
318+
return lhs._elements == rhs._elements
319+
}
320+
321+
public func !=<Element: Equatable> (lhs: SortedArray<Element>, rhs: SortedArray<Element>) -> Bool {
322+
return lhs._elements != rhs._elements
323+
}

Tests/SortedArrayTests/SortedArrayTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ class SortedArrayTests: XCTestCase {
227227
sut.remove(3)
228228
assertElementsEqual(sut, [1,2])
229229
}
230+
231+
func testIsEqual() {
232+
let sut = SortedArray(unsorted: 1...3)
233+
234+
XCTAssertTrue(sut == SortedArray(unsorted: 1...3))
235+
}
236+
237+
func testIsNotEqual() {
238+
let sut = SortedArray(unsorted: 1...3)
239+
240+
XCTAssertTrue(sut != SortedArray(unsorted: 1...4))
241+
}
230242
}
231243

232244
extension SortedArrayTests {
@@ -267,6 +279,8 @@ extension SortedArrayTests {
267279
("testRemoveElementAtBeginningPreservesSortOrder", testRemoveElementAtBeginningPreservesSortOrder),
268280
("testRemoveElementInMiddlePreservesSortOrder", testRemoveElementInMiddlePreservesSortOrder),
269281
("testRemoveElementAtEndPreservesSortOrder", testRemoveElementAtEndPreservesSortOrder),
282+
("testImplements==", testIsEqual),
283+
("testImplements!=", testIsNotEqual),
270284
]
271285
}
272286
}

0 commit comments

Comments
 (0)