Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import XCTest
final class WeakSetTests: XCTestCase {
var subject: WeakSet<ThemeObserver>!
override func setUp() {
subject = []
}
override func tearDown() {
subject = nil
}
func test_initLiteral_oneObject_subjectHasOneObject() {
let view = MockThemedView()
subject = [view]
XCTAssertEqual(subject.count, 1)
}
func test_initLiteral_oneObject_addSameObjectTwoTimes_subjectHasOneObject() {
let view = MockThemedView()
subject = [view, view]
XCTAssertEqual(subject.count, 1)
}
func test_initLiteral_oneObject_objectIsNil_subjectDoesntHoldObject_objectIsNil() {
var view: MockThemedView? = MockThemedView()
weak var weakView: MockThemedView? = view
subject = [view!]
view = nil
XCTAssertNil(weakView)
}
func test_initLiteral_oneObject_objectIsNil_accessViewFromSet_subjectDoesntHoldObject_obejctIsNil() {
var view: MockThemedView? = MockThemedView()
subject = [view!]
view = nil
XCTAssertNil(subject.allObjects.first)
}
func test_initLiteral_threeHundertFour_objectsAreNil_subjectDoesntHoldObjects_objectsAreNil() {
var mockViews: [MockThemedView]? = threeHundertFourViews()
subject = WeakSet(mockViews!)
mockViews = nil
XCTAssertNil(mockViews)
}
private func threeHundertFourViews() -> [MockThemedView] {
var views = [MockThemedView]()
for _ in 1 ... 304 {
views.append(MockThemedView())
}
return views
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.