1
+ // This source file is part of the Swift.org open source project
2
+ //
3
+ // Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4
+ // Licensed under Apache License v2.0 with Runtime Library Exception
5
+ //
6
+ // See http://swift.org/LICENSE.txt for license information
7
+ // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8
+ //
9
+
10
+
11
+
12
+ #if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
13
+ import Foundation
14
+ import XCTest
15
+ #else
16
+ import SwiftFoundation
17
+ import SwiftXCTest
18
+ #endif
19
+
20
+
21
+
22
+ class TestNSDate : XCTestCase {
23
+
24
+ var allTests : [ ( String , ( ) -> ( ) ) ] {
25
+ return [
26
+ ( " test_BasicConstruction " , test_BasicConstruction) ,
27
+ ( " test_InitTimeIntervalSince1970 " , test_InitTimeIntervalSince1970) ,
28
+ ( " test_InitTimeIntervalSinceSinceDate " , test_InitTimeIntervalSinceSinceDate) ,
29
+ ( " test_TimeIntervalSinceSinceDate " , test_TimeIntervalSinceSinceDate) ,
30
+ ( " test_DistantFuture " , test_DistantFuture) ,
31
+ ( " test_DistantPast " , test_DistantPast) ,
32
+ ( " test_DateByAddingTimeInterval " , test_DateByAddingTimeInterval) ,
33
+ ( " test_EarlierDate " , test_EarlierDate) ,
34
+ ( " test_LaterDate " , test_LaterDate) ,
35
+ ( " test_Compare " , test_Compare) ,
36
+ ( " test_IsEqualToDate " , test_IsEqualToDate) ,
37
+ ]
38
+ }
39
+
40
+ func test_BasicConstruction( ) {
41
+ let d = NSDate ( )
42
+ XCTAssertNotNil ( d)
43
+ }
44
+
45
+ func test_InitTimeIntervalSince1970( ) {
46
+ let ti : NSTimeInterval = 1
47
+ let d = NSDate ( timeIntervalSince1970: ti)
48
+ XCTAssertNotNil ( d)
49
+ }
50
+
51
+ func test_InitTimeIntervalSinceSinceDate( ) {
52
+ let ti : NSTimeInterval = 1
53
+ let d1 = NSDate ( )
54
+ let d2 = NSDate ( timeInterval: ti, sinceDate: d1)
55
+ XCTAssertNotNil ( d2)
56
+ }
57
+
58
+ func test_TimeIntervalSinceSinceDate( ) {
59
+ let ti : NSTimeInterval = 1
60
+ let d1 = NSDate ( )
61
+ let d2 = NSDate ( timeInterval: ti, sinceDate: d1)
62
+ XCTAssertEqual ( d2. timeIntervalSinceDate ( d1) , ti)
63
+ }
64
+
65
+ func test_DistantFuture( ) {
66
+ let d = NSDate . distantFuture ( )
67
+ XCTAssertNotNil ( d)
68
+ }
69
+
70
+ func test_DistantPast( ) {
71
+ let d = NSDate . distantPast ( )
72
+ XCTAssertNotNil ( d)
73
+ }
74
+
75
+ func test_DateByAddingTimeInterval( ) {
76
+ let ti : NSTimeInterval = 1
77
+ let d1 = NSDate ( )
78
+ let d2 = d1. dateByAddingTimeInterval ( ti)
79
+ XCTAssertNotNil ( d2)
80
+ }
81
+
82
+ func test_EarlierDate( ) {
83
+ let ti : NSTimeInterval = 1
84
+ let d1 = NSDate ( )
85
+ let d2 = d1. dateByAddingTimeInterval ( ti)
86
+ XCTAssertEqual ( d1. earlierDate ( d2) , d1)
87
+ }
88
+
89
+ func test_LaterDate( ) {
90
+ let ti : NSTimeInterval = 1
91
+ let d1 = NSDate ( )
92
+ let d2 = d1. dateByAddingTimeInterval ( ti)
93
+ XCTAssertEqual ( d1. laterDate ( d2) , d2)
94
+ }
95
+
96
+ func test_Compare( ) {
97
+ let ti : NSTimeInterval = 1
98
+ let d1 = NSDate ( )
99
+ let d2 = d1. dateByAddingTimeInterval ( ti)
100
+ XCTAssertEqual ( d1. compare ( d2) , NSComparisonResult . OrderedAscending)
101
+ }
102
+
103
+ func test_IsEqualToDate( ) {
104
+ let ti : NSTimeInterval = 1
105
+ let d1 = NSDate ( )
106
+ let d2 = d1. dateByAddingTimeInterval ( ti)
107
+ let d3 = d1. dateByAddingTimeInterval ( ti)
108
+ XCTAssertTrue ( d2. isEqualToDate ( d3) )
109
+ }
110
+ }
0 commit comments