Skip to content

Commit 57305f9

Browse files
authored
Merge pull request #1523 from otaviolima/enhance-timer-date-tests
2 parents 76995e8 + ca5f395 commit 57305f9

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

TestFoundation/TestDate.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,27 @@ class TestDate : XCTestCase {
4242

4343
func test_BasicConstruction() {
4444
let d = Date()
45-
XCTAssertNotNil(d)
45+
XCTAssert(d.timeIntervalSince1970 != 0)
46+
XCTAssert(d.timeIntervalSinceReferenceDate != 0)
4647
}
4748

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

5455
func test_InitTimeIntervalSince1970() {
5556
let ti: TimeInterval = 1
5657
let d = Date(timeIntervalSince1970: ti)
57-
XCTAssertNotNil(d)
58+
XCTAssert(d.timeIntervalSince1970 == ti)
5859
}
5960

6061
func test_InitTimeIntervalSinceSinceDate() {
6162
let ti: TimeInterval = 1
6263
let d1 = Date()
6364
let d2 = Date(timeInterval: ti, since: d1)
64-
XCTAssertNotNil(d2)
65+
XCTAssertNotNil(d2.timeIntervalSince1970 == d1.timeIntervalSince1970 + ti)
6566
}
6667

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

7475
func test_DistantFuture() {
7576
let d = Date.distantFuture
76-
XCTAssertNotNil(d)
77+
let now = Date()
78+
XCTAssertGreaterThan(d, now)
7779
}
7880

7981
func test_DistantPast() {
82+
let now = Date()
8083
let d = Date.distantPast
81-
XCTAssertNotNil(d)
84+
85+
XCTAssertLessThan(d, now)
8286
}
8387

8488
func test_DateByAddingTimeInterval() {
8589
let ti: TimeInterval = 1
8690
let d1 = Date()
8791
let d2 = d1 + ti
88-
XCTAssertNotNil(d2)
92+
XCTAssertNotNil(d2.timeIntervalSince1970 == d1.timeIntervalSince1970 + ti)
8993
}
9094

9195
func test_EarlierDate() {

TestFoundation/TestTimer.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@ class TestTimer : XCTestCase {
2828
}
2929

3030
func test_timerInit() {
31-
let timer = Timer(fire: Date(), interval: 0.3, repeats: false) { _ in }
32-
XCTAssertNotNil(timer)
31+
let fireDate = Date()
32+
let timeInterval: TimeInterval = 0.3
33+
34+
let timer = Timer(fire: fireDate, interval: timeInterval, repeats: false) { _ in }
35+
XCTAssertEqual(timer.fireDate, fireDate)
36+
XCTAssertEqual(timer.timeInterval, 0, "Time interval should be 0 for a non repeating Timer")
37+
XCTAssert(timer.isValid)
38+
39+
let repeatingTimer = Timer(fire: fireDate, interval: timeInterval, repeats: true) { _ in }
40+
XCTAssertEqual(repeatingTimer.fireDate, fireDate)
41+
XCTAssertEqual(repeatingTimer.timeInterval, timeInterval)
42+
XCTAssert(timer.isValid)
3343
}
3444

3545
func test_timerTickOnce() {

0 commit comments

Comments
 (0)