File tree 2 files changed +43
-0
lines changed
Sources/DataStructures/Pair
Tests/DataStructuresTests 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -29,5 +29,15 @@ extension Cross {
29
29
}
30
30
}
31
31
32
+ extension Cross : Comparable where T: Comparable , U: Comparable {
33
+
34
+ /// - Returns: true if and only if the first element of `lhs` is less than the first element
35
+ /// of `rhs` OR if those elements are equal and the second element of `lhs` is less than the
36
+ /// second element of `rhs` (lexicographic ordering).
37
+ public static func < ( lhs: Cross , rhs: Cross ) -> Bool {
38
+ return lhs. a < rhs. a || ( lhs. a == rhs. a && lhs. b < rhs. b)
39
+ }
40
+ }
41
+
32
42
extension Cross : Equatable where T: Equatable , U: Equatable { }
33
43
extension Cross : Hashable where T: Hashable , U: Hashable { }
Original file line number Diff line number Diff line change
1
+ //
2
+ // CrossTests.swift
3
+ // DataStructuresTests
4
+ //
5
+ // Created by James Bean on 10/20/18.
6
+ //
7
+
8
+ import XCTest
9
+ import DataStructures
10
+
11
+ class CrossTests : XCTestCase {
12
+
13
+ func testComparableFalseEqual( ) {
14
+ let a = Cross ( 1 , 1 )
15
+ let b = Cross ( 1 , 1 )
16
+ XCTAssertEqual ( a, b)
17
+ XCTAssertFalse ( a < b)
18
+ }
19
+
20
+ func testComparableLexicographic( ) {
21
+ let a = Cross ( 1 , 1 )
22
+ let b = Cross ( 1 , 2 )
23
+ XCTAssert ( a < b)
24
+ XCTAssert ( b > a)
25
+ }
26
+
27
+ func testComparableLexicographicFalse( ) {
28
+ let a = Cross ( 1 , 2 )
29
+ let b = Cross ( 1 , 1 )
30
+ XCTAssertFalse ( a < b)
31
+ XCTAssertFalse ( b > a)
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments