From c08a379efa928e6a2922debdd7126e963b4075c1 Mon Sep 17 00:00:00 2001 From: akio0911 Date: Tue, 10 May 2016 01:51:38 +0900 Subject: [PATCH] =?UTF-8?q?framework=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CalculateCalendarLogic.h | 19 + .../CalculateCalendarLogic.swift | 8 +- CalculateCalendarLogic/Info.plist | 26 ++ .../CalculateCalendarLogicTests.swift | 402 ++++++++++++++++++ CalculateCalendarLogicTests/Info.plist | 24 ++ .../project.pbxproj | 276 +++++++++++- handMadeCalendarAdvance/ViewController.swift | 1 + .../handMadeCalendarAdvanceTests.swift | 378 ---------------- 8 files changed, 745 insertions(+), 389 deletions(-) create mode 100644 CalculateCalendarLogic/CalculateCalendarLogic.h rename {handMadeCalendarAdvance => CalculateCalendarLogic}/CalculateCalendarLogic.swift (97%) create mode 100644 CalculateCalendarLogic/Info.plist create mode 100644 CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift create mode 100644 CalculateCalendarLogicTests/Info.plist diff --git a/CalculateCalendarLogic/CalculateCalendarLogic.h b/CalculateCalendarLogic/CalculateCalendarLogic.h new file mode 100644 index 0000000..7fe07d0 --- /dev/null +++ b/CalculateCalendarLogic/CalculateCalendarLogic.h @@ -0,0 +1,19 @@ +// +// CalculateCalendarLogic.h +// CalculateCalendarLogic +// +// Created by akio0911 on 2016/05/10. +// Copyright © 2016年 just1factory. All rights reserved. +// + +#import + +//! Project version number for CalculateCalendarLogic. +FOUNDATION_EXPORT double CalculateCalendarLogicVersionNumber; + +//! Project version string for CalculateCalendarLogic. +FOUNDATION_EXPORT const unsigned char CalculateCalendarLogicVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/handMadeCalendarAdvance/CalculateCalendarLogic.swift b/CalculateCalendarLogic/CalculateCalendarLogic.swift similarity index 97% rename from handMadeCalendarAdvance/CalculateCalendarLogic.swift rename to CalculateCalendarLogic/CalculateCalendarLogic.swift index 2e32855..00f4995 100644 --- a/handMadeCalendarAdvance/CalculateCalendarLogic.swift +++ b/CalculateCalendarLogic/CalculateCalendarLogic.swift @@ -14,7 +14,7 @@ import Foundation * */ -enum Weekday: Int { +public enum Weekday: Int { case Sun, Mon, Tue, Wed, Thu, Fri, Sat var shortName: String { @@ -38,7 +38,7 @@ enum Weekday: Int { } } -struct CalculateCalendarLogic { +public struct CalculateCalendarLogic { private enum SpringAutumn { /// 春分の日 @@ -63,7 +63,7 @@ struct CalculateCalendarLogic { } } - + public init() {} // FIXME: static化した後はprivateにする /** * @@ -75,7 +75,7 @@ struct CalculateCalendarLogic { * ※3. [Swift] 関数における引数/戻り値とタプルの関係:http://dev.classmethod.jp/smartphone/swift-function-tupsle/ * */ - func judgeJapaneseHoliday(year: Int, month: Int, day: Int, weekdayIndex: Int) -> Bool { + public func judgeJapaneseHoliday(year: Int, month: Int, day: Int, weekdayIndex: Int) -> Bool { guard let weekday = Weekday(rawValue: weekdayIndex) else { fatalError("weekdayIndex is invalid.") } diff --git a/CalculateCalendarLogic/Info.plist b/CalculateCalendarLogic/Info.plist new file mode 100644 index 0000000..d3de8ee --- /dev/null +++ b/CalculateCalendarLogic/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift b/CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift new file mode 100644 index 0000000..ba1bf4e --- /dev/null +++ b/CalculateCalendarLogicTests/CalculateCalendarLogicTests.swift @@ -0,0 +1,402 @@ +// +// CalculateCalendarLogicTests.swift +// CalculateCalendarLogicTests +// +// Created by akio0911 on 2016/05/10. +// Copyright © 2016年 just1factory. All rights reserved. +// + +import XCTest +@testable import CalculateCalendarLogic + +class CalculateCalendarLogicTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + /** + * + * 今年(2016年)の祝祭日の判定テスト + * + */ + func testCurrentYear() { + + let test = CalculateCalendarLogic() + + //2016年の場合のテストケース + let testCases: [(Int,Int,Int,Weekday,Bool)] = + [ + // 元日: 2016年1月1日(金曜日) + (2016, 1, 1, .Fri, true), + + // 成人の日: 2016年1月11日(月曜日) + (2016, 1, 11, .Mon, true), + + // 建国記念の日: 2016年2月11日(木曜日) + (2016, 2, 11, .Thu, true), + + // 春分の日の振替休日: 2016年3月21日(月曜日) + (2016, 3, 21, .Mon, true), + + // 昭和の日: 2016年4月29日(金曜日) + (2016, 4, 29, .Fri, true), + + // 憲法記念日: 2016年5月3日(火曜日) + (2016, 5, 3, .Tue, true), + + // みどりの日: 2016年5月4日(水曜日) + (2016, 5, 4, .Wed, true), + + // こどもの日: 2016年5月5日(木曜日) + (2016, 5, 5, .Thu, true), + + // 海の日: 2016年7月18日(月曜日) + (2016, 7, 18, .Mon, true), + + // 山の日: 2016年8月11日(木曜日) + (2016, 8, 11, .Thu, true), + + // 敬老の日: 2016年9月19日(月曜日) + (2016, 9, 19, .Mon, true), + + // 秋分の日: 2016年9月22日(木曜日) + (2016, 9, 22, .Thu, true), + + // 体育の日: 2016年10月10日(月曜日) + (2016, 10, 10, .Mon, true), + + // 文化の日: 2016年11月3日(木曜日) + (2016, 11, 3, .Thu, true), + + // 勤労感謝の日: 2016年11月23日(水曜日) + (2016, 11, 23, .Wed, true), + + //天皇誕生日: 2016年12月23日(金曜日) + (2016, 12, 23, .Fri, true) + ] + testCases.forEach { year, month, day, weekday, expected in + let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) + let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" + if expected { + XCTAssertTrue (result, message) + }else{ + XCTAssertFalse(result, message) + } + } + } + + /** + * + * ゴールデンウィークの判定のテスト + * + */ + func testGoldenWeek() { + + let test = CalculateCalendarLogic() + + let testCases: [(Int,Int,Int,Weekday,Bool)] = + [ + // 2017年 + (2017, 5, 2, .Tue, false), + (2017, 5, 3, .Wed, true ), + (2017, 5, 4, .Thu, true ), + (2017, 5, 5, .Fri, true ), + (2017, 5, 6, .Sat, false), + + // 2019年 + (2019, 5, 2, .Thu, false), + (2019, 5, 3, .Fri, true ), + (2019, 5, 4, .Sat, true ), + (2019, 5, 5, .Sun, true ), + (2019, 5, 6, .Mon, true ), + + // 2020年 + (2020, 5, 2, .Sat, false), + (2020, 5, 3, .Sun, true ), + (2020, 5, 4, .Mon, true ), + (2020, 5, 5, .Tue, true ), + (2020, 5, 6, .Wed, true ), + (2020, 5, 7, .Thu, false), + + // 2021年 + (2021, 5, 2, .Sun, false), + (2021, 5, 3, .Mon, true ), + (2021, 5, 4, .Tue, true ), + (2021, 5, 5, .Wed, true ), + (2021, 5, 6, .Thu, false) + ] + + testCases.forEach { year, month, day, weekday, expected in + let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) + let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" + if expected { + XCTAssertTrue (result, message) + }else{ + XCTAssertFalse(result, message) + } + } + } + + /** + * + * シルバーウィークの判定のテスト + * 該当テストケース1: 2015年 + * 該当テストケース2: 2026年 + * 該当テストケース3: 2032年 + * + */ + func testSilverWeek() { + + let test = CalculateCalendarLogic() + + let testCases: [(Int,Int,Int,Weekday,Bool)] = [ + // 2015年 + (2015, 9, 19, .Sat, false), + (2015, 9, 20, .Sun, false), + (2015, 9, 21, .Mon, true), + (2015, 9, 22, .Tue, true), + (2015, 9, 23, .Wed, true), + (2015, 9, 24, .Thu, false), + + // 2016年 + (2016, 9, 19, .Mon, true), + (2016, 9, 20, .Tue, false), + (2016, 9, 21, .Wed, false), + (2016, 9, 22, .Thu, true), + (2016, 9, 23, .Fri, false), + (2016, 9, 24, .Sat, false), + + // 2026年 + (2026, 9, 19, .Sat, false), + (2026, 9, 20, .Sun, false), + (2026, 9, 21, .Mon, true), + (2026, 9, 22, .Tue, true), + (2026, 9, 23, .Wed, true), + (2026, 9, 24, .Thu, false), + + // 2032年 + (2032, 9, 18, .Sat, false), + (2032, 9, 19, .Sun, false), + (2032, 9, 20, .Mon, true), + (2032, 9, 21, .Tue, true), + (2032, 9, 22, .Wed, true), + (2032, 9, 23, .Thu, false), + ] + testCases.forEach { year, month, day, weekday, expected in + let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) + let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" + if expected { + XCTAssertTrue (result, message) + }else{ + XCTAssertFalse(result, message) + } + } + } + + /** + * + * 1回目のチェックで2015/9/22が祝日であると判定できるかどうか? + * + */ + func testFirstJudge20160920() { + let test = CalculateCalendarLogic() + + let testCases: [(Int,Int,Int,Weekday,Bool)] = [ + (2015, 9, 22, .Tue, true), + ] + testCases.forEach { year, month, day, weekday, expected in + let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) + let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" + if expected { + XCTAssertTrue (result, message) + }else{ + XCTAssertFalse(result, message) + } + } + } + + /** + * + * 春分の日・秋分の日の組み合わせが正しいかのテスト + * 計算式算出の参考:http://koyomi8.com/reki_doc/doc_0330.htm + * テストケース参考:http://www.nao.ac.jp/faq/a0301.html + * + */ + func testShunbunAndShubun() { + + let test = CalculateCalendarLogic() + + let testCases: [(Int,Int,Int,Weekday,Bool)] = [ + // 2000年 + (2000, 3, 20, .Mon, true), + (2000, 9, 23, .Sat, true), + + // 2001年 + (2001, 3, 20, .Tue, true), + (2001, 9, 23, .Sun, true), + + // 2002年 + (2002, 3, 21, .Thu, true), + (2002, 9, 23, .Mon, true), + + // 2003年 + (2003, 3, 21, .Fri, true), + (2003, 9, 23, .Tue, true), + + // 2004年 + (2004, 3, 20, .Sat, true), + (2004, 9, 23, .Thu, true), + + // 2005年 + (2005, 3, 20, .Sun, true), + (2005, 9, 23, .Fri, true), + + // 2006年 + (2006, 3, 21, .Tue, true), + (2006, 9, 23, .Sat, true), + + // 2007年 + (2007, 3, 21, .Wed, true), + (2007, 9, 23, .Sun, true), + + // 2008年 + (2008, 3, 20, .Thu, true), + (2008, 9, 23, .Tue, true), + + // 2009年 + (2009, 3, 20, .Fri, true), + (2009, 9, 23, .Wed, true), + + // 2010年 + (2010, 3, 21, .Sun, true), + (2010, 9, 23, .Thu, true), + + // 2011年 + (2011, 3, 21, .Mon, true), + (2011, 9, 23, .Fri, true), + + // 2012年 + (2012, 3, 20, .Tue, true), + (2012, 9, 22, .Sat, true), + + // 2013年 + (2013, 3, 20, .Wed, true), + (2013, 9, 23, .Mon, true), + + // 2014年 + (2014, 3, 21, .Fri, true), + (2014, 9, 23, .Tue, true), + + // 2015年 + (2015, 3, 21, .Sat, true), + (2015, 9, 23, .Wed, true), + + // 2016年 + (2016, 3, 20, .Sun, true), + (2016, 9, 22, .Thu, true), + + // 2017年 + (2017, 3, 20, .Mon, true), + (2017, 9, 23, .Sat, true), + + // 2018年 + (2018, 3, 21, .Wed, true), + (2018, 9, 23, .Sun, true), + + // 2019年 + (2019, 3, 21, .Thu, true), + (2019, 9, 23, .Mon, true), + + // 2020年 + (2020, 3, 20, .Fri, true), + (2020, 9, 22, .Tue, true), + + // 2021年 + (2021, 3, 20, .Sat, true), + (2021, 9, 23, .Thu, true), + + // 2022年 + (2022, 3, 21, .Mon, true), + (2022, 9, 23, .Fri, true), + + // 2023年 + (2023, 3, 21, .Tue, true), + (2023, 9, 23, .Sat, true), + + // 2024年 + (2024, 3, 20, .Wed, true), + (2024, 9, 22, .Sun, true), + + // 2025年 + (2025, 3, 20, .Thu, true), + (2025, 9, 23, .Tue, true), + + // 2026年 + (2026, 3, 20, .Fri, true), + (2026, 9, 23, .Wed, true), + + // 2027年 + (2027, 3, 21, .Sun, true), + (2027, 9, 23, .Thu, true), + + // 2028年 + (2028, 3, 20, .Mon, true), + (2028, 9, 22, .Fri, true), + + // 2029年 + (2029, 3, 20, .Tue, true), + (2029, 9, 23, .Sun, true), + + // 2030年 + (2030, 3, 20, .Wed, true), + (2030, 9, 23, .Mon, true) + ] + testCases.forEach { year, month, day, weekday, expected in + let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) + let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" + if expected { + XCTAssertTrue (result, message) + }else{ + XCTAssertFalse(result, message) + } + } + } + + func testOldPeopleDay() { + let testCases: [(year: Int, expectedDay: Int)] = [ + (2005, 19), + (2006, 18), + (2007, 17), + (2008, 15), + (2009, 21), + (2010, 20), + (2011, 19), + (2012, 17), + (2013, 16), + (2014, 15), + (2015, 21), + (2016, 19), + (2017, 18), + (2018, 17), + (2019, 16), + (2020, 21), + ] + + testCases.forEach { year, expectedDay in + // プロパティを確実に初期状態に戻してテストするため、このタイミングで毎回インスタンス化する + let test = CalculateCalendarLogic() + + let result = test.oldPeopleDay(year: year) + let message = "\(year)年:\(result)日" + XCTAssertEqual(result, expectedDay, message) + } + } +} + diff --git a/CalculateCalendarLogicTests/Info.plist b/CalculateCalendarLogicTests/Info.plist new file mode 100644 index 0000000..ba72822 --- /dev/null +++ b/CalculateCalendarLogicTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/handMadeCalendarAdvance.xcodeproj/project.pbxproj b/handMadeCalendarAdvance.xcodeproj/project.pbxproj index 3559e5d..5e181e3 100644 --- a/handMadeCalendarAdvance.xcodeproj/project.pbxproj +++ b/handMadeCalendarAdvance.xcodeproj/project.pbxproj @@ -15,7 +15,12 @@ DE7397041CCB4EC100A9A222 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DE7397021CCB4EC100A9A222 /* LaunchScreen.storyboard */; }; DE73970F1CCB4EC100A9A222 /* handMadeCalendarAdvanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE73970E1CCB4EC100A9A222 /* handMadeCalendarAdvanceTests.swift */; }; DE73971A1CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE7397191CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.swift */; }; - DEAA90EB1CD0CB0F003E20C1 /* CalculateCalendarLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEAA90EA1CD0CB0F003E20C1 /* CalculateCalendarLogic.swift */; }; + E517AF4D1CE0F63C006847A0 /* CalculateCalendarLogic.h in Headers */ = {isa = PBXBuildFile; fileRef = E517AF4C1CE0F63C006847A0 /* CalculateCalendarLogic.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E517AF541CE0F63C006847A0 /* CalculateCalendarLogic.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E517AF4A1CE0F63C006847A0 /* CalculateCalendarLogic.framework */; }; + E517AF5B1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E517AF5A1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift */; }; + E517AF5F1CE0F63C006847A0 /* CalculateCalendarLogic.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E517AF4A1CE0F63C006847A0 /* CalculateCalendarLogic.framework */; }; + E517AF601CE0F63C006847A0 /* CalculateCalendarLogic.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E517AF4A1CE0F63C006847A0 /* CalculateCalendarLogic.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + E517AF691CE0F669006847A0 /* CalculateCalendarLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = E517AF681CE0F669006847A0 /* CalculateCalendarLogic.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -33,8 +38,43 @@ remoteGlobalIDString = DE7396F51CCB4EC100A9A222; remoteInfo = handMadeCalendarAdvance; }; + E517AF551CE0F63C006847A0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DE7396EE1CCB4EC100A9A222 /* Project object */; + proxyType = 1; + remoteGlobalIDString = E517AF491CE0F63C006847A0; + remoteInfo = CalculateCalendarLogic; + }; + E517AF571CE0F63C006847A0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DE7396EE1CCB4EC100A9A222 /* Project object */; + proxyType = 1; + remoteGlobalIDString = DE7396F51CCB4EC100A9A222; + remoteInfo = handMadeCalendarAdvance; + }; + E517AF5D1CE0F63C006847A0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DE7396EE1CCB4EC100A9A222 /* Project object */; + proxyType = 1; + remoteGlobalIDString = E517AF491CE0F63C006847A0; + remoteInfo = CalculateCalendarLogic; + }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + E517AF661CE0F63D006847A0 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + E517AF601CE0F63C006847A0 /* CalculateCalendarLogic.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ DE0166BB1CDE5892002BB133 /* CalendarCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarCell.swift; sourceTree = ""; }; DE7396F61CCB4EC100A9A222 /* handMadeCalendarAdvance.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = handMadeCalendarAdvance.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -50,7 +90,13 @@ DE7397151CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = handMadeCalendarAdvanceUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; DE7397191CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = handMadeCalendarAdvanceUITests.swift; sourceTree = ""; }; DE73971B1CCB4EC100A9A222 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - DEAA90EA1CD0CB0F003E20C1 /* CalculateCalendarLogic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalculateCalendarLogic.swift; sourceTree = ""; }; + E517AF4A1CE0F63C006847A0 /* CalculateCalendarLogic.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CalculateCalendarLogic.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + E517AF4C1CE0F63C006847A0 /* CalculateCalendarLogic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CalculateCalendarLogic.h; sourceTree = ""; }; + E517AF4E1CE0F63C006847A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E517AF531CE0F63C006847A0 /* CalculateCalendarLogicTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CalculateCalendarLogicTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + E517AF5A1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculateCalendarLogicTests.swift; sourceTree = ""; }; + E517AF5C1CE0F63C006847A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E517AF681CE0F669006847A0 /* CalculateCalendarLogic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalculateCalendarLogic.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -58,6 +104,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E517AF5F1CE0F63C006847A0 /* CalculateCalendarLogic.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -75,6 +122,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E517AF461CE0F63C006847A0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E517AF501CE0F63C006847A0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + E517AF541CE0F63C006847A0 /* CalculateCalendarLogic.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -92,6 +154,8 @@ DE7396F81CCB4EC100A9A222 /* handMadeCalendarAdvance */, DE73970D1CCB4EC100A9A222 /* handMadeCalendarAdvanceTests */, DE7397181CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests */, + E517AF4B1CE0F63C006847A0 /* CalculateCalendarLogic */, + E517AF591CE0F63C006847A0 /* CalculateCalendarLogicTests */, DE7396F71CCB4EC100A9A222 /* Products */, ); sourceTree = ""; @@ -102,6 +166,8 @@ DE7396F61CCB4EC100A9A222 /* handMadeCalendarAdvance.app */, DE73970A1CCB4EC100A9A222 /* handMadeCalendarAdvanceTests.xctest */, DE7397151CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.xctest */, + E517AF4A1CE0F63C006847A0 /* CalculateCalendarLogic.framework */, + E517AF531CE0F63C006847A0 /* CalculateCalendarLogicTests.xctest */, ); name = Products; sourceTree = ""; @@ -110,7 +176,6 @@ isa = PBXGroup; children = ( DE0166BA1CDE40DC002BB133 /* Component */, - DEC9AE6F1CDB9F0600B661CE /* Library */, DE7396F91CCB4EC100A9A222 /* AppDelegate.swift */, DE7396FB1CCB4EC100A9A222 /* ViewController.swift */, DE7396FD1CCB4EC100A9A222 /* Main.storyboard */, @@ -139,16 +204,38 @@ path = handMadeCalendarAdvanceUITests; sourceTree = ""; }; - DEC9AE6F1CDB9F0600B661CE /* Library */ = { + E517AF4B1CE0F63C006847A0 /* CalculateCalendarLogic */ = { + isa = PBXGroup; + children = ( + E517AF4C1CE0F63C006847A0 /* CalculateCalendarLogic.h */, + E517AF4E1CE0F63C006847A0 /* Info.plist */, + E517AF681CE0F669006847A0 /* CalculateCalendarLogic.swift */, + ); + path = CalculateCalendarLogic; + sourceTree = ""; + }; + E517AF591CE0F63C006847A0 /* CalculateCalendarLogicTests */ = { isa = PBXGroup; children = ( - DEAA90EA1CD0CB0F003E20C1 /* CalculateCalendarLogic.swift */, + E517AF5A1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift */, + E517AF5C1CE0F63C006847A0 /* Info.plist */, ); - name = Library; + path = CalculateCalendarLogicTests; sourceTree = ""; }; /* End PBXGroup section */ +/* Begin PBXHeadersBuildPhase section */ + E517AF471CE0F63C006847A0 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + E517AF4D1CE0F63C006847A0 /* CalculateCalendarLogic.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + /* Begin PBXNativeTarget section */ DE7396F51CCB4EC100A9A222 /* handMadeCalendarAdvance */ = { isa = PBXNativeTarget; @@ -157,10 +244,12 @@ DE7396F21CCB4EC100A9A222 /* Sources */, DE7396F31CCB4EC100A9A222 /* Frameworks */, DE7396F41CCB4EC100A9A222 /* Resources */, + E517AF661CE0F63D006847A0 /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( + E517AF5E1CE0F63C006847A0 /* PBXTargetDependency */, ); name = handMadeCalendarAdvance; productName = handMadeCalendarAdvance; @@ -203,6 +292,43 @@ productReference = DE7397151CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests.xctest */; productType = "com.apple.product-type.bundle.ui-testing"; }; + E517AF491CE0F63C006847A0 /* CalculateCalendarLogic */ = { + isa = PBXNativeTarget; + buildConfigurationList = E517AF651CE0F63D006847A0 /* Build configuration list for PBXNativeTarget "CalculateCalendarLogic" */; + buildPhases = ( + E517AF451CE0F63C006847A0 /* Sources */, + E517AF461CE0F63C006847A0 /* Frameworks */, + E517AF471CE0F63C006847A0 /* Headers */, + E517AF481CE0F63C006847A0 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = CalculateCalendarLogic; + productName = CalculateCalendarLogic; + productReference = E517AF4A1CE0F63C006847A0 /* CalculateCalendarLogic.framework */; + productType = "com.apple.product-type.framework"; + }; + E517AF521CE0F63C006847A0 /* CalculateCalendarLogicTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = E517AF671CE0F63D006847A0 /* Build configuration list for PBXNativeTarget "CalculateCalendarLogicTests" */; + buildPhases = ( + E517AF4F1CE0F63C006847A0 /* Sources */, + E517AF501CE0F63C006847A0 /* Frameworks */, + E517AF511CE0F63C006847A0 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + E517AF561CE0F63C006847A0 /* PBXTargetDependency */, + E517AF581CE0F63C006847A0 /* PBXTargetDependency */, + ); + name = CalculateCalendarLogicTests; + productName = CalculateCalendarLogicTests; + productReference = E517AF531CE0F63C006847A0 /* CalculateCalendarLogicTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -224,6 +350,13 @@ CreatedOnToolsVersion = 7.3; TestTargetID = DE7396F51CCB4EC100A9A222; }; + E517AF491CE0F63C006847A0 = { + CreatedOnToolsVersion = 7.3; + }; + E517AF521CE0F63C006847A0 = { + CreatedOnToolsVersion = 7.3; + TestTargetID = DE7396F51CCB4EC100A9A222; + }; }; }; buildConfigurationList = DE7396F11CCB4EC100A9A222 /* Build configuration list for PBXProject "handMadeCalendarAdvance" */; @@ -242,6 +375,8 @@ DE7396F51CCB4EC100A9A222 /* handMadeCalendarAdvance */, DE7397091CCB4EC100A9A222 /* handMadeCalendarAdvanceTests */, DE7397141CCB4EC100A9A222 /* handMadeCalendarAdvanceUITests */, + E517AF491CE0F63C006847A0 /* CalculateCalendarLogic */, + E517AF521CE0F63C006847A0 /* CalculateCalendarLogicTests */, ); }; /* End PBXProject section */ @@ -271,6 +406,20 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E517AF481CE0F63C006847A0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E517AF511CE0F63C006847A0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -280,7 +429,6 @@ files = ( DE7396FC1CCB4EC100A9A222 /* ViewController.swift in Sources */, DE7396FA1CCB4EC100A9A222 /* AppDelegate.swift in Sources */, - DEAA90EB1CD0CB0F003E20C1 /* CalculateCalendarLogic.swift in Sources */, DE0166BC1CDE5892002BB133 /* CalendarCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -301,6 +449,22 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E517AF451CE0F63C006847A0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E517AF691CE0F669006847A0 /* CalculateCalendarLogic.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E517AF4F1CE0F63C006847A0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E517AF5B1CE0F63C006847A0 /* CalculateCalendarLogicTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -314,6 +478,21 @@ target = DE7396F51CCB4EC100A9A222 /* handMadeCalendarAdvance */; targetProxy = DE7397161CCB4EC100A9A222 /* PBXContainerItemProxy */; }; + E517AF561CE0F63C006847A0 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = E517AF491CE0F63C006847A0 /* CalculateCalendarLogic */; + targetProxy = E517AF551CE0F63C006847A0 /* PBXContainerItemProxy */; + }; + E517AF581CE0F63C006847A0 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = DE7396F51CCB4EC100A9A222 /* handMadeCalendarAdvance */; + targetProxy = E517AF571CE0F63C006847A0 /* PBXContainerItemProxy */; + }; + E517AF5E1CE0F63C006847A0 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = E517AF491CE0F63C006847A0 /* CalculateCalendarLogic */; + targetProxy = E517AF5D1CE0F63C006847A0 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -423,6 +602,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = handMadeCalendarAdvance/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.handMadeCalendarAdvance; @@ -434,6 +614,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = handMadeCalendarAdvance/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.handMadeCalendarAdvance; @@ -487,6 +668,71 @@ }; name = Release; }; + E517AF611CE0F63D006847A0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = CalculateCalendarLogic/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogic; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + E517AF621CE0F63D006847A0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = CalculateCalendarLogic/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogic; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + E517AF631CE0F63D006847A0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + INFOPLIST_FILE = CalculateCalendarLogicTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogicTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/handMadeCalendarAdvance.app/handMadeCalendarAdvance"; + }; + name = Debug; + }; + E517AF641CE0F63D006847A0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + INFOPLIST_FILE = CalculateCalendarLogicTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = net.just1factory.CalculateCalendarLogicTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/handMadeCalendarAdvance.app/handMadeCalendarAdvance"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -526,6 +772,22 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + E517AF651CE0F63D006847A0 /* Build configuration list for PBXNativeTarget "CalculateCalendarLogic" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E517AF611CE0F63D006847A0 /* Debug */, + E517AF621CE0F63D006847A0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; + E517AF671CE0F63D006847A0 /* Build configuration list for PBXNativeTarget "CalculateCalendarLogicTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E517AF631CE0F63D006847A0 /* Debug */, + E517AF641CE0F63D006847A0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; /* End XCConfigurationList section */ }; rootObject = DE7396EE1CCB4EC100A9A222 /* Project object */; diff --git a/handMadeCalendarAdvance/ViewController.swift b/handMadeCalendarAdvance/ViewController.swift index 2d28c62..d484dbd 100644 --- a/handMadeCalendarAdvance/ViewController.swift +++ b/handMadeCalendarAdvance/ViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import CalculateCalendarLogic //カレンダーに関する定数やメソッドを定義した構造体 struct CalendarSetting { diff --git a/handMadeCalendarAdvanceTests/handMadeCalendarAdvanceTests.swift b/handMadeCalendarAdvanceTests/handMadeCalendarAdvanceTests.swift index 1e92450..912fad9 100644 --- a/handMadeCalendarAdvanceTests/handMadeCalendarAdvanceTests.swift +++ b/handMadeCalendarAdvanceTests/handMadeCalendarAdvanceTests.swift @@ -20,382 +20,4 @@ class handMadeCalendarAdvanceTests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() } - - /** - * - * 今年(2016年)の祝祭日の判定テスト - * - */ - func testCurrentYear() { - - let test = CalculateCalendarLogic() - - //2016年の場合のテストケース - let testCases: [(Int,Int,Int,Weekday,Bool)] = - [ - // 元日: 2016年1月1日(金曜日) - (2016, 1, 1, .Fri, true), - - // 成人の日: 2016年1月11日(月曜日) - (2016, 1, 11, .Mon, true), - - // 建国記念の日: 2016年2月11日(木曜日) - (2016, 2, 11, .Thu, true), - - // 春分の日の振替休日: 2016年3月21日(月曜日) - (2016, 3, 21, .Mon, true), - - // 昭和の日: 2016年4月29日(金曜日) - (2016, 4, 29, .Fri, true), - - // 憲法記念日: 2016年5月3日(火曜日) - (2016, 5, 3, .Tue, true), - - // みどりの日: 2016年5月4日(水曜日) - (2016, 5, 4, .Wed, true), - - // こどもの日: 2016年5月5日(木曜日) - (2016, 5, 5, .Thu, true), - - // 海の日: 2016年7月18日(月曜日) - (2016, 7, 18, .Mon, true), - - // 山の日: 2016年8月11日(木曜日) - (2016, 8, 11, .Thu, true), - - // 敬老の日: 2016年9月19日(月曜日) - (2016, 9, 19, .Mon, true), - - // 秋分の日: 2016年9月22日(木曜日) - (2016, 9, 22, .Thu, true), - - // 体育の日: 2016年10月10日(月曜日) - (2016, 10, 10, .Mon, true), - - // 文化の日: 2016年11月3日(木曜日) - (2016, 11, 3, .Thu, true), - - // 勤労感謝の日: 2016年11月23日(水曜日) - (2016, 11, 23, .Wed, true), - - //天皇誕生日: 2016年12月23日(金曜日) - (2016, 12, 23, .Fri, true) - ] - testCases.forEach { year, month, day, weekday, expected in - let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) - let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" - if expected { - XCTAssertTrue (result, message) - }else{ - XCTAssertFalse(result, message) - } - } - } - - /** - * - * ゴールデンウィークの判定のテスト - * - */ - func testGoldenWeek() { - - let test = CalculateCalendarLogic() - - let testCases: [(Int,Int,Int,Weekday,Bool)] = - [ - // 2017年 - (2017, 5, 2, .Tue, false), - (2017, 5, 3, .Wed, true ), - (2017, 5, 4, .Thu, true ), - (2017, 5, 5, .Fri, true ), - (2017, 5, 6, .Sat, false), - - // 2019年 - (2019, 5, 2, .Thu, false), - (2019, 5, 3, .Fri, true ), - (2019, 5, 4, .Sat, true ), - (2019, 5, 5, .Sun, true ), - (2019, 5, 6, .Mon, true ), - - // 2020年 - (2020, 5, 2, .Sat, false), - (2020, 5, 3, .Sun, true ), - (2020, 5, 4, .Mon, true ), - (2020, 5, 5, .Tue, true ), - (2020, 5, 6, .Wed, true ), - (2020, 5, 7, .Thu, false), - - // 2021年 - (2021, 5, 2, .Sun, false), - (2021, 5, 3, .Mon, true ), - (2021, 5, 4, .Tue, true ), - (2021, 5, 5, .Wed, true ), - (2021, 5, 6, .Thu, false) - ] - - testCases.forEach { year, month, day, weekday, expected in - let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) - let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" - if expected { - XCTAssertTrue (result, message) - }else{ - XCTAssertFalse(result, message) - } - } - } - - /** - * - * シルバーウィークの判定のテスト - * 該当テストケース1: 2015年 - * 該当テストケース2: 2026年 - * 該当テストケース3: 2032年 - * - */ - func testSilverWeek() { - - let test = CalculateCalendarLogic() - - let testCases: [(Int,Int,Int,Weekday,Bool)] = [ - // 2015年 - (2015, 9, 19, .Sat, false), - (2015, 9, 20, .Sun, false), - (2015, 9, 21, .Mon, true), - (2015, 9, 22, .Tue, true), - (2015, 9, 23, .Wed, true), - (2015, 9, 24, .Thu, false), - - // 2016年 - (2016, 9, 19, .Mon, true), - (2016, 9, 20, .Tue, false), - (2016, 9, 21, .Wed, false), - (2016, 9, 22, .Thu, true), - (2016, 9, 23, .Fri, false), - (2016, 9, 24, .Sat, false), - - // 2026年 - (2026, 9, 19, .Sat, false), - (2026, 9, 20, .Sun, false), - (2026, 9, 21, .Mon, true), - (2026, 9, 22, .Tue, true), - (2026, 9, 23, .Wed, true), - (2026, 9, 24, .Thu, false), - - // 2032年 - (2032, 9, 18, .Sat, false), - (2032, 9, 19, .Sun, false), - (2032, 9, 20, .Mon, true), - (2032, 9, 21, .Tue, true), - (2032, 9, 22, .Wed, true), - (2032, 9, 23, .Thu, false), - ] - testCases.forEach { year, month, day, weekday, expected in - let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) - let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" - if expected { - XCTAssertTrue (result, message) - }else{ - XCTAssertFalse(result, message) - } - } - } - - /** - * - * 1回目のチェックで2015/9/22が祝日であると判定できるかどうか? - * - */ - func testFirstJudge20160920() { - let test = CalculateCalendarLogic() - - let testCases: [(Int,Int,Int,Weekday,Bool)] = [ - (2015, 9, 22, .Tue, true), - ] - testCases.forEach { year, month, day, weekday, expected in - let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) - let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" - if expected { - XCTAssertTrue (result, message) - }else{ - XCTAssertFalse(result, message) - } - } - } - - /** - * - * 春分の日・秋分の日の組み合わせが正しいかのテスト - * 計算式算出の参考:http://koyomi8.com/reki_doc/doc_0330.htm - * テストケース参考:http://www.nao.ac.jp/faq/a0301.html - * - */ - func testShunbunAndShubun() { - - let test = CalculateCalendarLogic() - - let testCases: [(Int,Int,Int,Weekday,Bool)] = [ - // 2000年 - (2000, 3, 20, .Mon, true), - (2000, 9, 23, .Sat, true), - - // 2001年 - (2001, 3, 20, .Tue, true), - (2001, 9, 23, .Sun, true), - - // 2002年 - (2002, 3, 21, .Thu, true), - (2002, 9, 23, .Mon, true), - - // 2003年 - (2003, 3, 21, .Fri, true), - (2003, 9, 23, .Tue, true), - - // 2004年 - (2004, 3, 20, .Sat, true), - (2004, 9, 23, .Thu, true), - - // 2005年 - (2005, 3, 20, .Sun, true), - (2005, 9, 23, .Fri, true), - - // 2006年 - (2006, 3, 21, .Tue, true), - (2006, 9, 23, .Sat, true), - - // 2007年 - (2007, 3, 21, .Wed, true), - (2007, 9, 23, .Sun, true), - - // 2008年 - (2008, 3, 20, .Thu, true), - (2008, 9, 23, .Tue, true), - - // 2009年 - (2009, 3, 20, .Fri, true), - (2009, 9, 23, .Wed, true), - - // 2010年 - (2010, 3, 21, .Sun, true), - (2010, 9, 23, .Thu, true), - - // 2011年 - (2011, 3, 21, .Mon, true), - (2011, 9, 23, .Fri, true), - - // 2012年 - (2012, 3, 20, .Tue, true), - (2012, 9, 22, .Sat, true), - - // 2013年 - (2013, 3, 20, .Wed, true), - (2013, 9, 23, .Mon, true), - - // 2014年 - (2014, 3, 21, .Fri, true), - (2014, 9, 23, .Tue, true), - - // 2015年 - (2015, 3, 21, .Sat, true), - (2015, 9, 23, .Wed, true), - - // 2016年 - (2016, 3, 20, .Sun, true), - (2016, 9, 22, .Thu, true), - - // 2017年 - (2017, 3, 20, .Mon, true), - (2017, 9, 23, .Sat, true), - - // 2018年 - (2018, 3, 21, .Wed, true), - (2018, 9, 23, .Sun, true), - - // 2019年 - (2019, 3, 21, .Thu, true), - (2019, 9, 23, .Mon, true), - - // 2020年 - (2020, 3, 20, .Fri, true), - (2020, 9, 22, .Tue, true), - - // 2021年 - (2021, 3, 20, .Sat, true), - (2021, 9, 23, .Thu, true), - - // 2022年 - (2022, 3, 21, .Mon, true), - (2022, 9, 23, .Fri, true), - - // 2023年 - (2023, 3, 21, .Tue, true), - (2023, 9, 23, .Sat, true), - - // 2024年 - (2024, 3, 20, .Wed, true), - (2024, 9, 22, .Sun, true), - - // 2025年 - (2025, 3, 20, .Thu, true), - (2025, 9, 23, .Tue, true), - - // 2026年 - (2026, 3, 20, .Fri, true), - (2026, 9, 23, .Wed, true), - - // 2027年 - (2027, 3, 21, .Sun, true), - (2027, 9, 23, .Thu, true), - - // 2028年 - (2028, 3, 20, .Mon, true), - (2028, 9, 22, .Fri, true), - - // 2029年 - (2029, 3, 20, .Tue, true), - (2029, 9, 23, .Sun, true), - - // 2030年 - (2030, 3, 20, .Wed, true), - (2030, 9, 23, .Mon, true) - ] - testCases.forEach { year, month, day, weekday, expected in - let result = test.judgeJapaneseHoliday(year, month: month, day: day, weekdayIndex: weekday.rawValue) - let message = "\(year)年\(month)月\(day)日(\(weekday.longName)):\(result)" - if expected { - XCTAssertTrue (result, message) - }else{ - XCTAssertFalse(result, message) - } - } - } - - func testOldPeopleDay() { - let testCases: [(year: Int, expectedDay: Int)] = [ - (2005, 19), - (2006, 18), - (2007, 17), - (2008, 15), - (2009, 21), - (2010, 20), - (2011, 19), - (2012, 17), - (2013, 16), - (2014, 15), - (2015, 21), - (2016, 19), - (2017, 18), - (2018, 17), - (2019, 16), - (2020, 21), - ] - - testCases.forEach { year, expectedDay in - // プロパティを確実に初期状態に戻してテストするため、このタイミングで毎回インスタンス化する - let test = CalculateCalendarLogic() - - let result = test.oldPeopleDay(year: year) - let message = "\(year)年:\(result)日" - XCTAssertEqual(result, expectedDay, message) - } - } }