<commit_before>//
//  NSDate+TimepieceTests.swift
//  Timepiece
//
//  Created by <NAME> on 2014/08/16.
//  Copyright (c) 2014年 <NAME>. All rights reserved.
//

import Timepiece
import XCTest

class NSDateTestCase: XCTestCase {
    let now = NSDate()
    let calendar = NSCalendar.currentCalendar()
    var birthday: NSDate! {
        let components = NSDateComponents()
        components.year = 1987
        components.month = 6
        components.day = 2
        components.hour = 0
        components.minute = 0
        components.second = 0
        return calendar.dateFromComponents(components)
    }
    
    func testPlus() {
        let nextDay = calendar.dateByAddingUnit(.CalendarUnitDay, value: 1, toDate: now, options: .SearchBackwards)!
        XCTAssertEqual(now + 1.day, nextDay, "")
        
        let nextWeek = calendar.dateByAddingUnit(.CalendarUnitWeekOfYear, value: 1, toDate: now, options: .SearchBackwards)!
        XCTAssertEqual(now + 1.week, nextWeek, "")
    }
    
    
    func testMinus() {
        let lastDay = calendar.dateByAddingUnit(.CalendarUnitDay, value: -1, toDate: now, options: .SearchBackwards)!
        XCTAssertEqual(now - 1.day, lastDay, "")
        
        let lastWeek = calendar.dateByAddingUnit(.CalendarUnitWeekOfYear, value: -1, toDate: now, options: .SearchBackwards)!
        XCTAssertEqual(now - 1.week, lastWeek, "")
    }
    
    func testEqual() {
        let date1 = NSDate.date(year: 2015, month: 5, day: 1)
        let date2 = "2015-05-01".dateFromFormat("yyyy-MM-dd")
        let date3 = date1 - 1.second

        XCTAssertEqual(date1 == date2, true, "")
        XCTAssertEqual(date1 != date3, true, "")
    }

    func testCompare() {
        let date1 = NSDate.date(year: 2015, month: 5, day: 1)
        let date2 = date1 + 1.second
        let date3 = date1 - 1.second

        XCTAssertEqual(date1 < date2, true, "")
        XCTAssertEqual(date1 <= date1, true, "")
        XCTAssertEqual(date1 > date3, true, "")
        XCTAssertEqual(date1 >= date1, true, "")
    }

    func testYear() {
        XCTAssertEqual(birthday.year, 1987, "")
    }
    
    func testMonth() {
        XCTAssertEqual(birthday.month, 6, "")
    }
    
    func testDay() {
        XCTAssertEqual(birthday.day, 2, "")
    }
    
    func testHour() {
        XCTAssertEqual(birthday.hour, 0, "")
    }
    
    func testMinute() {
        XCTAssertEqual(birthday.minute, 0, "")
    }
    
    func testSecond() {
        XCTAssertEqual(birthday.second, 0, "")
    }
    
    func testDateWithYearAndMonthAndDayAndHourAndMinuteAndSecond() {
        XCTAssertEqual(NSDate.date(year: 1987, month: 6, day: 2), birthday, "")
    }
    
    func testToday() {
        let components = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond, fromDate: now)
        components.hour = 0
        components.minute = 0
        components.second = 0
        let today = calendar.dateFromComponents(components)
        XCTAssertEqual(NSDate.today(), today!, "")
    }
    
    func testYesterday() {
        let components = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond, fromDate: now)
        components.day = now.day - 1
        components.hour = 0
        components.minute = 0
        components.second = 0
        let yesterday = calendar.dateFromComponents(components)
        XCTAssertEqual(NSDate.yesterday(), yesterday!, "")
    }
    
    func testTomorrow() {
        let components = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond, fromDate: now)
        components.day = now.day + 1
        components.hour = 0
        components.minute = 0
        components.second = 0
        let tomorrow = calendar.dateFromComponents(components)
        XCTAssertEqual(NSDate.tomorrow(), tomorrow!, "")
    }
    
    func testChange() {
        XCTAssertEqual(now.change(year: 2000).year, 2000, "")
        XCTAssertEqual(now.change(month: 6).month, 6, "")
        XCTAssertEqual(now.change(day: 15).day, 15, "")
        XCTAssertEqual(now.change(hour: 9).hour, 9, "")
        XCTAssertEqual(now.change(minute: 30).minute, 30, "")
        XCTAssertEqual(now.change(second: 45).second, 45, "")
    }
    
    func testTimeIntervalDifference() {
        let oneMinuteFromNow = now + 1.minute
        let tenWeeksFromNow = now + 10.weeks
        
        XCTAssertEqual(oneMinuteFromNow - now, 60)
        XCTAssertEqual(tenWeeksFromNow - now, 3600*24*7*10)
    }
    
    func testChangeWeekday() {
        XCTAssertEqual(now.change(weekday: 1).weekday, 1, "")
    }
    
    func testBeginningOf() {
        XCTAssertEqual(now.beginningOfYear.month, 1, "")
        XCTAssertEqual(now.beginningOfMonth.day, 1, "")
        XCTAssertEqual(now.beginningOfDay.hour, 0, "")
        XCTAssertEqual(now.beginningOfHour.minute, 0, "")
        XCTAssertEqual(now.beginningOfMinute.second, 0, "")
    }
    
    func testEndOf() {
        XCTAssertEqual(now.endOfYear.month, 12, "")
        XCTAssertEqual(now.endOfDay.hour, 23, "")
        XCTAssertEqual(now.endOfHour.minute, 59, "")
        XCTAssertEqual(now.endOfMinute.second, 59, "")
    }
    <commit_msg>Added a test for beginningOfWeek / endOfWeek<commit_after>//
//  NSDate+TimepieceTests.swift
//  Timepiece
//
//  Created by <NAME> on 2014/08/16.
//  Copyright (c) 2014年 <NAME>. All rights reserved.
//

import Timepiece
import XCTest

class NSDateTestCase: XCTestCase {
    let now = NSDate()
    let calendar = NSCalendar.currentCalendar()
    var birthday: NSDate! {
        let components = NSDateComponents()
        components.year = 1987
        components.month = 6
        components.day = 2
        components.hour = 0
        components.minute = 0
        components.second = 0
        return calendar.dateFromComponents(components)
    }
    
    func testPlus() {
        let nextDay = calendar.dateByAddingUnit(.CalendarUnitDay, value: 1, toDate: now, options: .SearchBackwards)!
        XCTAssertEqual(now + 1.day, nextDay, "")
        
        let nextWeek = calendar.dateByAddingUnit(.CalendarUnitWeekOfYear, value: 1, toDate: now, options: .SearchBackwards)!
        XCTAssertEqual(now + 1.week, nextWeek, "")
    }
    
    
    func testMinus() {
        let lastDay = calendar.dateByAddingUnit(.CalendarUnitDay, value: -1, toDate: now, options: .SearchBackwards)!
        XCTAssertEqual(now - 1.day, lastDay, "")
        
        let lastWeek = calendar.dateByAddingUnit(.CalendarUnitWeekOfYear, value: -1, toDate: now, options: .SearchBackwards)!
        XCTAssertEqual(now - 1.week, lastWeek, "")
    }
    
    func testEqual() {
        let date1 = NSDate.date(year: 2015, month: 5, day: 1)
        let date2 = "2015-05-01".dateFromFormat("yyyy-MM-dd")
        let date3 = date1 - 1.second

        XCTAssertEqual(date1 == date2, true, "")
        XCTAssertEqual(date1 != date3, true, "")
    }

    func testCompare() {
        let date1 = NSDate.date(year: 2015, month: 5, day: 1)
        let date2 = date1 + 1.second
        let date3 = date1 - 1.second

        XCTAssertEqual(date1 < date2, true, "")
        XCTAssertEqual(date1 <= date1, true, "")
        XCTAssertEqual(date1 > date3, true, "")
        XCTAssertEqual(date1 >= date1, true, "")
    }

    func testYear() {
        XCTAssertEqual(birthday.year, 1987, "")
    }
    
    func testMonth() {
        XCTAssertEqual(birthday.month, 6, "")
    }
    
    func testDay() {
        XCTAssertEqual(birthday.day, 2, "")
    }
    
    func testHour() {
        XCTAssertEqual(birthday.hour, 0, "")
    }
    
    func testMinute() {
        XCTAssertEqual(birthday.minute, 0, "")
    }
    
    func testSecond() {
        XCTAssertEqual(birthday.second, 0, "")
    }
    
    func testDateWithYearAndMonthAndDayAndHourAndMinuteAndSecond() {
        XCTAssertEqual(NSDate.date(year: 1987, month: 6, day: 2), birthday, "")
    }
    
    func testToday() {
        let components = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond, fromDate: now)
        components.hour = 0
        components.minute = 0
        components.second = 0
        let today = calendar.dateFromComponents(components)
        XCTAssertEqual(NSDate.today(), today!, "")
    }
    
    func testYesterday() {
        let components = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond, fromDate: now)
        components.day = now.day - 1
        components.hour = 0
        components.minute = 0
        components.second = 0
        let yesterday = calendar.dateFromComponents(components)
        XCTAssertEqual(NSDate.yesterday(), yesterday!, "")
    }
    
    func testTomorrow() {
        let components = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond, fromDate: now)
        components.day = now.day + 1
        components.hour = 0
        components.minute = 0
        components.second = 0
        let tomorrow = calendar.dateFromComponents(components)
        XCTAssertEqual(NSDate.tomorrow(), tomorrow!, "")
    }
    
    func testChange() {
        XCTAssertEqual(now.change(year: 2000).year, 2000, "")
        XCTAssertEqual(now.change(month: 6).month, 6, "")
        XCTAssertEqual(now.change(day: 15).day, 15, "")
        XCTAssertEqual(now.change(hour: 9).hour, 9, "")
        XCTAssertEqual(now.change(minute: 30).minute, 30, "")
        XCTAssertEqual(now.change(second: 45).second, 45, "")
    }
    
    func testTimeIntervalDifference() {
        let oneMinuteFromNow = now + 1.minute
        let tenWeeksFromNow = now + 10.weeks
        
        XCTAssertEqual(oneMinuteFromNow - now, 60)
        XCTAssertEqual(tenWeeksFromNow - now, 3600*24*7*10)
    }
    
    func testChangeWeekday() {
        XCTAssertEqual(now.change(weekday: 1).weekday, 1, "")
    }
    
    func testBeginningOf() {
        XCTAssertEqual(now.beginningOfYear.month, 1, "")
        XCTAssertEqual(now.beginningOfMonth.day, 1, "")
        XCTAssertEqual(now.beginningOfDay.hour, 0, "")
        XCTAssertEqual(now.beginningOfHour.minute, 0, "")
        XCTAssertEqual(now.beginningOfMinute.second, 0, "")
    }
	
	func testBeginningEndOfWeek() {
		let systemFirstWeekday = calendar.firstWeekday
		// Birthday was on tuesday (Tuesday, June 2, 1987)
		if systemFirstWeekday == 1 {
			// Weeks start on sunday:
			XCTAssertEqual(birthday.beginningOfWeek.month, 5, "")
			XCTAssertEqual(birthday.beginningOfWeek.day, 31, "")
			XCTAssertEqual(birthday.endOfWeek.month, 6, "")
			XCTAssertEqual(birthday.endOfWeek.day, 6, "")
		} else if systemFirstWeekday == 2 {
			// Weeks start on monday:
			XCTAssertEqual(birthday.beginningOfWeek.month, 6, "")
			XCTAssertEqual(birthday.beginningOfWeek.day, 1, "")
			XCTAssertEqual(birthday.endOfWeek.month, 6, "")
			XCTAssertEqual(birthday.endOfWeek.day, 7, "")
		}
	}
	
    func testEndOf() {
        XCTAssertEqual(now.endOfYear.month, 12, "")
        XCTAssertEqual(now.endOfDay.hour, 23, "")
        XCTAssertEqual(now.endOfHour.minute, 59, "")
        XCTAssertEqual(now.endOfMinute.second, 59, "")
    }
    
{'fraction_non_alphanumeric': 0.1212041884816754, 'fraction_numerical': 0.027923211169284468, 'mean_word_length': 2.6040880503144654, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5265254', 'n_tokens_mistral': 3917, 'n_tokens_neox': 3575, 'n_words': 697}