Skip to content

Tests for NSDate #70

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
Dec 8, 2015
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
4 changes: 4 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
22B9C1E11C165D7A00DECFF9 /* TestNSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */; };
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */; };
525AECED1BF2C9C500D15BB0 /* TestNSFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */; };
528776141BF2629700CB0090 /* FoundationErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522C253A1BF16E1600804FC6 /* FoundationErrors.swift */; };
Expand Down Expand Up @@ -314,6 +315,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSDate.swift; sourceTree = "<group>"; };
4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSPipe.swift; sourceTree = "<group>"; };
522C253A1BF16E1600804FC6 /* FoundationErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationErrors.swift; sourceTree = "<group>"; };
525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSFileManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1015,6 +1017,7 @@
5BC1D8BC1BF3ADFE009D3973 /* TestNSCharacterSet.swift */,
525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */,
5B40F9F11C125187000E72E3 /* TestNSXMLParser.swift */,
22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */,
);
name = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1703,6 +1706,7 @@
EA66F6521BF1619600136161 /* TestNSPropertyList.swift in Sources */,
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */,
EA66F64E1BF1619600136161 /* TestNSIndexSet.swift in Sources */,
22B9C1E11C165D7A00DECFF9 /* TestNSDate.swift in Sources */,
EA66F6541BF1619600136161 /* TestNSSet.swift in Sources */,
EA66F64A1BF1619600136161 /* TestNSArray.swift in Sources */,
5BC1D8BE1BF3B09E009D3973 /* TestNSCharacterSet.swift in Sources */,
Expand Down
110 changes: 110 additions & 0 deletions TestFoundation/TestNSDate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//



#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif



class TestNSDate : XCTestCase {

var allTests : [(String, () -> ())] {
return [
("test_BasicConstruction", test_BasicConstruction),
("test_InitTimeIntervalSince1970", test_InitTimeIntervalSince1970),
("test_InitTimeIntervalSinceSinceDate", test_InitTimeIntervalSinceSinceDate),
("test_TimeIntervalSinceSinceDate", test_TimeIntervalSinceSinceDate),
("test_DistantFuture", test_DistantFuture),
("test_DistantPast", test_DistantPast),
("test_DateByAddingTimeInterval", test_DateByAddingTimeInterval),
("test_EarlierDate", test_EarlierDate),
("test_LaterDate", test_LaterDate),
("test_Compare", test_Compare),
("test_IsEqualToDate", test_IsEqualToDate),
]
}

func test_BasicConstruction() {
let d = NSDate()
XCTAssertNotNil(d)
}

func test_InitTimeIntervalSince1970() {
let ti: NSTimeInterval = 1
let d = NSDate(timeIntervalSince1970: ti)
XCTAssertNotNil(d)
}

func test_InitTimeIntervalSinceSinceDate() {
let ti: NSTimeInterval = 1
let d1 = NSDate()
let d2 = NSDate(timeInterval: ti, sinceDate: d1)
XCTAssertNotNil(d2)
}

func test_TimeIntervalSinceSinceDate() {
let ti: NSTimeInterval = 1
let d1 = NSDate()
let d2 = NSDate(timeInterval: ti, sinceDate: d1)
XCTAssertEqual(d2.timeIntervalSinceDate(d1), ti)
}

func test_DistantFuture() {
let d = NSDate.distantFuture()
XCTAssertNotNil(d)
}

func test_DistantPast() {
let d = NSDate.distantPast()
XCTAssertNotNil(d)
}

func test_DateByAddingTimeInterval() {
let ti: NSTimeInterval = 1
let d1 = NSDate()
let d2 = d1.dateByAddingTimeInterval(ti)
XCTAssertNotNil(d2)
}

func test_EarlierDate() {
let ti: NSTimeInterval = 1
let d1 = NSDate()
let d2 = d1.dateByAddingTimeInterval(ti)
XCTAssertEqual(d1.earlierDate(d2), d1)
}

func test_LaterDate() {
let ti: NSTimeInterval = 1
let d1 = NSDate()
let d2 = d1.dateByAddingTimeInterval(ti)
XCTAssertEqual(d1.laterDate(d2), d2)
}

func test_Compare() {
let ti: NSTimeInterval = 1
let d1 = NSDate()
let d2 = d1.dateByAddingTimeInterval(ti)
XCTAssertEqual(d1.compare(d2), NSComparisonResult.OrderedAscending)
}

func test_IsEqualToDate() {
let ti: NSTimeInterval = 1
let d1 = NSDate()
let d2 = d1.dateByAddingTimeInterval(ti)
let d3 = d1.dateByAddingTimeInterval(ti)
XCTAssertTrue(d2.isEqualToDate(d3))
}
}
1 change: 1 addition & 0 deletions TestFoundation/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ XCTMain([
TestNSFileManger(),
TestNSRange(),
TestNSXMLParser(),
TestNSDate(),
])