Skip to content

Replace XCTAssertNotNil with enhanced tests on TestDate and TestTimer #1523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions TestFoundation/TestDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,27 @@ class TestDate : XCTestCase {

func test_BasicConstruction() {
let d = Date()
XCTAssertNotNil(d)
XCTAssert(d.timeIntervalSince1970 != 0)
XCTAssert(d.timeIntervalSinceReferenceDate != 0)
}

func test_descriptionWithLocale() {
let d = NSDate(timeIntervalSince1970: 0)
XCTAssertEqual(d.description(with: nil), "1970-01-01 00:00:00 +0000")
XCTAssertNotNil(d.description(with: Locale(identifier: "ja_JP")))
XCTAssertFalse(d.description(with: Locale(identifier: "ja_JP")).isEmpty)
}

func test_InitTimeIntervalSince1970() {
let ti: TimeInterval = 1
let d = Date(timeIntervalSince1970: ti)
XCTAssertNotNil(d)
XCTAssert(d.timeIntervalSince1970 == ti)
}

func test_InitTimeIntervalSinceSinceDate() {
let ti: TimeInterval = 1
let d1 = Date()
let d2 = Date(timeInterval: ti, since: d1)
XCTAssertNotNil(d2)
XCTAssertNotNil(d2.timeIntervalSince1970 == d1.timeIntervalSince1970 + ti)
}

func test_TimeIntervalSinceSinceDate() {
Expand All @@ -73,19 +74,22 @@ class TestDate : XCTestCase {

func test_DistantFuture() {
let d = Date.distantFuture
XCTAssertNotNil(d)
let now = Date()
XCTAssertGreaterThan(d, now)
}

func test_DistantPast() {
let now = Date()
let d = Date.distantPast
XCTAssertNotNil(d)

XCTAssertLessThan(d, now)
}

func test_DateByAddingTimeInterval() {
let ti: TimeInterval = 1
let d1 = Date()
let d2 = d1 + ti
XCTAssertNotNil(d2)
XCTAssertNotNil(d2.timeIntervalSince1970 == d1.timeIntervalSince1970 + ti)
}

func test_EarlierDate() {
Expand Down
14 changes: 12 additions & 2 deletions TestFoundation/TestTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ class TestTimer : XCTestCase {
}

func test_timerInit() {
let timer = Timer(fire: Date(), interval: 0.3, repeats: false) { _ in }
XCTAssertNotNil(timer)
let fireDate = Date()
let timeInterval: TimeInterval = 0.3

let timer = Timer(fire: fireDate, interval: timeInterval, repeats: false) { _ in }
XCTAssertEqual(timer.fireDate, fireDate)
XCTAssertEqual(timer.timeInterval, 0, "Time interval should be 0 for a non repeating Timer")
XCTAssert(timer.isValid)

let repeatingTimer = Timer(fire: fireDate, interval: timeInterval, repeats: true) { _ in }
XCTAssertEqual(repeatingTimer.fireDate, fireDate)
XCTAssertEqual(repeatingTimer.timeInterval, timeInterval)
XCTAssert(timer.isValid)
}

func test_timerTickOnce() {
Expand Down