-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathTestNSSet.swift
69 lines (57 loc) · 2.17 KB
/
TestNSSet.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif
class TestNSSet : XCTestCase {
var allTests : [(String, () -> ())] {
return [
("test_BasicConstruction", test_BasicConstruction),
("test_enumeration", test_enumeration),
("test_sequenceType", test_sequenceType),
("test_setOperations", test_setOperations),
]
}
func test_BasicConstruction() {
let set = NSSet()
let set2 = NSSet(array: ["foo", "bar"].bridge().bridge())
XCTAssertEqual(set.count, 0)
XCTAssertEqual(set2.count, 2)
}
func test_enumeration() {
let set = NSSet(array: ["foo", "bar", "baz"].bridge().bridge())
let e = set.objectEnumerator()
var result = Set<String>()
result.insert((e.nextObject()! as! NSString).bridge())
result.insert((e.nextObject()! as! NSString).bridge())
result.insert((e.nextObject()! as! NSString).bridge())
XCTAssertEqual(result, Set(["foo", "bar", "baz"]))
let empty = NSSet().objectEnumerator()
XCTAssertNil(empty.nextObject())
XCTAssertNil(empty.nextObject())
}
func test_sequenceType() {
let set = NSSet(array: ["foo", "bar", "baz"].bridge().bridge())
var res = Set<String>()
for obj in set {
res.insert((obj as! NSString).bridge())
}
XCTAssertEqual(res, Set(["foo", "bar", "baz"]))
}
func test_setOperations() {
// TODO: This fails because hashValue and == use NSObject's implementaitons, which don't have the right semantics
// let set = NSMutableSet(array: ["foo", "bar"])
// set.unionSet(["bar", "baz"])
// XCTAssertTrue(set.isEqualToSet(["foo", "bar", "baz"]))
}
}