Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
import Foundation
6
import Shared
7
import XCTest
8
9
class ArrayExtensionTests: XCTestCase {
10
override func setUp() {
11
super.setUp()
12
}
13
14
override func tearDown() {
15
super.tearDown()
16
}
17
18
func testUnique() {
19
let a = [1, 2, 3, 4, 5, 6, 1, 2]
20
let result = a.unique { return $0 }
21
XCTAssertEqual(result, [1, 2, 3, 4, 5, 6])
22
23
let b = [1, 2, 3]
24
let resultB = b.unique { return $0 }
25
XCTAssertEqual(resultB, [1, 2, 3])
26
}
27
28
func testUnion() {
29
let a = [1, 2, 3, 4, 5, 6]
30
let b = [7, 8, 9, 10]
31
XCTAssertEqual(a.union(b) { return $0 },
32
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
33
34
let c = [1, 2, 3, 4, 5, 6]
35
let d = [4, 5, 6, 7, 8, 9, 10]
36
XCTAssertEqual(c.union(d) { return $0 }, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
37
38
let e = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
39
let f = [4, 5, 6, 7, 8, 9, 10]
40
XCTAssertEqual(e.union(f) { return $0 }, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
41
42
let g = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
43
let h = [Int]()
44
XCTAssertEqual(g.union(h) { return $0 }, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
45
46
let i = [Int]()
47
let j = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
48
XCTAssertEqual(i.union(j) { return $0 }, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
49
}
50
51
func testSameElements() {
52
let k = [1, 2, 3, 4, 5]
53
let l = [1, 2, 3, 4, 5]
54
let m = [2, 4, 6, 8, 10]
55
let n: [Int]?
56
n = k
57
XCTAssertTrue(k.sameElements(l))
58
XCTAssertFalse(l.sameElements(m))
59
XCTAssertTrue((n?.sameElements(k))!)
60
}
61
62
}