55// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
66//
77//===----------------------------------------------------------------------===//
8- //
9- // RUN: %target-run-simple-swift
10- // REQUIRES: executable_test
11- // REQUIRES: objc_interop
8+
9+ import Testing
1210
1311#if canImport(TestSupport)
1412import TestSupport
1513#endif
1614
17- final class DateIntervalTests : XCTestCase {
15+ #if canImport(FoundationEssentials)
16+ import FoundationEssentials
17+ #elseif FOUNDATION_FRAMEWORK
18+ import Foundation
19+ #endif
20+
21+ @Suite ( " DateInterval " )
22+ private struct DateIntervalTests {
1823
19- func test_compareDateIntervals ( ) {
24+ @ Test func compareDateIntervals ( ) {
2025 // dateWithString("2010-05-17 14:49:47 -0700")
2126 let start = Date ( timeIntervalSinceReferenceDate: 295825787.0 )
2227 let duration : TimeInterval = 10000000.0
2328 let testInterval1 = DateInterval ( start: start, duration: duration)
2429 let testInterval2 = DateInterval ( start: start, duration: duration)
25- XCTAssertEqual ( testInterval1, testInterval2)
26- XCTAssertEqual ( testInterval2, testInterval1)
27- XCTAssertEqual ( testInterval1. compare ( testInterval2) , ComparisonResult . orderedSame)
30+ #expect ( testInterval1 == testInterval2)
31+ #expect ( testInterval2 == testInterval1)
32+ #expect ( testInterval1. compare ( testInterval2) == . orderedSame)
2833
2934 let testInterval3 = DateInterval ( start: start, duration: 10000000000.0 )
30- XCTAssertTrue ( testInterval1 < testInterval3)
31- XCTAssertTrue ( testInterval3 > testInterval1)
35+ #expect ( testInterval1 < testInterval3)
36+ #expect ( testInterval3 > testInterval1)
3237
3338 // dateWithString("2009-05-17 14:49:47 -0700")
3439 let earlierStart = Date ( timeIntervalSinceReferenceDate: 264289787.0 )
3540 let testInterval4 = DateInterval ( start: earlierStart, duration: duration)
3641
37- XCTAssertTrue ( testInterval4 < testInterval1)
38- XCTAssertTrue ( testInterval1 > testInterval4)
42+ #expect ( testInterval4 < testInterval1)
43+ #expect ( testInterval1 > testInterval4)
3944 }
4045
41- func test_isEqualToDateInterval ( ) {
46+ @ Test func isEqualToDateInterval ( ) {
4247 // dateWithString("2010-05-17 14:49:47 -0700")
4348 let start = Date ( timeIntervalSinceReferenceDate: 295825787.0 )
4449 let duration = 10000000.0
4550 let testInterval1 = DateInterval ( start: start, duration: duration)
4651 let testInterval2 = DateInterval ( start: start, duration: duration)
4752
48- XCTAssertEqual ( testInterval1, testInterval2)
53+ #expect ( testInterval1 == testInterval2)
4954
5055 let testInterval3 = DateInterval ( start: start, duration: 100.0 )
51- XCTAssertNotEqual ( testInterval1, testInterval3)
56+ #expect ( testInterval1 != testInterval3)
5257 }
5358
54- func test_hashing ( ) {
59+ @ Test func hashing ( ) {
5560 // dateWithString("2019-04-04 17:09:23 -0700")
5661 let start1a = Date ( timeIntervalSinceReferenceDate: 576115763.0 )
5762 let start1b = Date ( timeIntervalSinceReferenceDate: 576115763.0 )
@@ -77,10 +82,10 @@ final class DateIntervalTests : XCTestCase {
7782 DateInterval ( start: start2b, duration: duration2) ,
7883 ] ,
7984 ]
80- XCTCheckHashableGroups ( intervals)
85+ checkHashableGroups ( intervals)
8186 }
8287
83- func test_checkIntersection ( ) {
88+ @ Test func checkIntersection ( ) {
8489 // dateWithString("2010-05-17 14:49:47 -0700")
8590 let start1 = Date ( timeIntervalSinceReferenceDate: 295825787.0 )
8691 // dateWithString("2010-08-17 14:49:47 -0700")
@@ -95,7 +100,7 @@ final class DateIntervalTests : XCTestCase {
95100
96101 let testInterval2 = DateInterval ( start: start2, end: end2)
97102
98- XCTAssertTrue ( testInterval1. intersects ( testInterval2) )
103+ #expect ( testInterval1. intersects ( testInterval2) )
99104
100105 // dateWithString("2010-10-17 14:49:47 -0700")
101106 let start3 = Date ( timeIntervalSinceReferenceDate: 309044987.0 )
@@ -104,10 +109,10 @@ final class DateIntervalTests : XCTestCase {
104109
105110 let testInterval3 = DateInterval ( start: start3, end: end3)
106111
107- XCTAssertFalse ( testInterval1. intersects ( testInterval3) )
112+ #expect ( ! testInterval1. intersects ( testInterval3) )
108113 }
109114
110- func test_validIntersections ( ) {
115+ @ Test func validIntersections ( ) {
111116 // dateWithString("2010-05-17 14:49:47 -0700")
112117 let start1 = Date ( timeIntervalSinceReferenceDate: 295825787.0 )
113118 // dateWithString("2010-08-17 14:49:47 -0700")
@@ -130,15 +135,13 @@ final class DateIntervalTests : XCTestCase {
130135 let testInterval3 = DateInterval ( start: start3, end: end3)
131136
132137 let intersection1 = testInterval2. intersection ( with: testInterval1)
133- XCTAssertNotNil ( intersection1)
134- XCTAssertEqual ( testInterval3, intersection1)
138+ #expect( testInterval3 == intersection1)
135139
136140 let intersection2 = testInterval1. intersection ( with: testInterval2)
137- XCTAssertNotNil ( intersection2)
138- XCTAssertEqual ( intersection1, intersection2)
141+ #expect( intersection1 == intersection2)
139142 }
140143
141- func test_containsDate ( ) {
144+ @ Test func containsDate ( ) {
142145 // dateWithString("2010-05-17 14:49:47 -0700")
143146 let start = Date ( timeIntervalSinceReferenceDate: 295825787.0 )
144147 let duration = 10000000.0
@@ -147,14 +150,14 @@ final class DateIntervalTests : XCTestCase {
147150 // dateWithString("2010-05-17 20:49:47 -0700")
148151 let containedDate = Date ( timeIntervalSinceReferenceDate: 295847387.0 )
149152
150- XCTAssertTrue ( testInterval. contains ( containedDate) )
153+ #expect ( testInterval. contains ( containedDate) )
151154
152155 // dateWithString("2009-05-17 14:49:47 -0700")
153156 let earlierStart = Date ( timeIntervalSinceReferenceDate: 264289787.0 )
154- XCTAssertFalse ( testInterval. contains ( earlierStart) )
157+ #expect ( ! testInterval. contains ( earlierStart) )
155158 }
156159
157- func test_AnyHashableContainingDateInterval ( ) {
160+ @ Test func anyHashableContainingDateInterval ( ) {
158161 // dateWithString("2010-05-17 14:49:47 -0700")
159162 let start = Date ( timeIntervalSinceReferenceDate: 295825787.0 )
160163 let duration = 10000000.0
@@ -164,18 +167,19 @@ final class DateIntervalTests : XCTestCase {
164167 DateInterval ( start: start, duration: duration / 2 ) ,
165168 ]
166169 let anyHashables = values. map ( AnyHashable . init)
167- expectEqual ( DateInterval . self, type ( of: anyHashables [ 0 ] . base) )
168- expectEqual ( DateInterval . self, type ( of: anyHashables [ 1 ] . base) )
169- expectEqual ( DateInterval . self, type ( of: anyHashables [ 2 ] . base) )
170- XCTAssertNotEqual ( anyHashables [ 0 ] , anyHashables [ 1 ] )
171- XCTAssertEqual ( anyHashables [ 1 ] , anyHashables [ 2 ] )
170+ #expect ( DateInterval . self == type ( of: anyHashables [ 0 ] . base) )
171+ #expect ( DateInterval . self == type ( of: anyHashables [ 1 ] . base) )
172+ #expect ( DateInterval . self == type ( of: anyHashables [ 2 ] . base) )
173+ #expect ( anyHashables [ 0 ] != anyHashables [ 1 ] )
174+ #expect ( anyHashables [ 1 ] == anyHashables [ 2 ] )
172175 }
173176}
174177
175178// MARK: - Bridging Tests
176179#if FOUNDATION_FRAMEWORK
177- extension DateIntervalTests {
178- func test_AnyHashableCreatedFromNSDateInterval( ) {
180+ @Suite ( " DateInterval Bridging " )
181+ private struct DateIntervalBridgingTests {
182+ @Test func anyHashableCreatedFromNSDateInterval( ) {
179183 // dateWithString("2010-05-17 14:49:47 -0700")
180184 let start = Date ( timeIntervalSinceReferenceDate: 295825787.0 )
181185 let duration = 10000000.0
@@ -185,11 +189,11 @@ extension DateIntervalTests {
185189 NSDateInterval ( start: start, duration: duration / 2 ) ,
186190 ]
187191 let anyHashables = values. map ( AnyHashable . init)
188- expectEqual ( DateInterval . self, type ( of: anyHashables [ 0 ] . base) )
189- expectEqual ( DateInterval . self, type ( of: anyHashables [ 1 ] . base) )
190- expectEqual ( DateInterval . self, type ( of: anyHashables [ 2 ] . base) )
191- XCTAssertNotEqual ( anyHashables [ 0 ] , anyHashables [ 1 ] )
192- XCTAssertEqual ( anyHashables [ 1 ] , anyHashables [ 2 ] )
192+ #expect ( DateInterval . self == type ( of: anyHashables [ 0 ] . base) )
193+ #expect ( DateInterval . self == type ( of: anyHashables [ 1 ] . base) )
194+ #expect ( DateInterval . self == type ( of: anyHashables [ 2 ] . base) )
195+ #expect ( anyHashables [ 0 ] != anyHashables [ 1 ] )
196+ #expect ( anyHashables [ 1 ] == anyHashables [ 2 ] )
193197 }
194198}
195199#endif
0 commit comments