<commit_before>@import <Foundation/CPDate.j>

@implementation CPDateTest : OJTestCase

- (void)testSince1970
{
    /* These two dates should be equal to Fri Feb 13 2009 15:31:30 GMT-0800 */
    unixDate = [CPDate dateWithTimeIntervalSince1970: 1234567890];
    cocoaDate = [CPDate dateWithTimeIntervalSinceReferenceDate: 253582290];
    [self assertTrue:[unixDate isEqualToDate: cocoaDate]];
}

- (void)testDate
{
    var before = new Date(),
        middle = [CPDate date],
        after = new Date(),
        future = [CPDate distantFuture],
        past = [CPDate distantPast];

    [self assertTrue:(before <= middle) message:"before not less than middle"];
    [self assertTrue:(middle <= after) message:"middle not less than after ("+middle+","+after+")"];

    [self assert:middle equals:[middle earlierDate:future] message:"earlierDate incorrect"];
    [self assert:middle equals:[middle laterDate:past] message:"laterDate incorrect"];
}

- (void)testEquals
{
    var now = [CPDate date];
    [self assert:now equals:now];
    [self assertFalse:[now isEqual:[CPNull null]]];
    [self assertFalse:[now isEqual:nil]];
}

/*!
    [date description] displays time in the current timezone. This test is a crude
    way to validate that this works right for different timezones: just run the test
    with different timezones configured.
*/
- (void)testParseNow
{
    var now = [CPDate new],
        alsoNow = [[CPDate alloc] initWithString:[now description]];

    [self assert:[now description] equals:[alsoNow description]];
}

- (void)testInitWithString
{
    var tests = [
        ["1970-01-01 00:00:00 +0000", 0],
        ["1970-01-01 00:01:00 +0000", 60],
        ["1970-01-01 01:00:00 +0000", 60*60],
        ["1970-01-02 00:00:00 +0000", 24*60*60],
        ["2009-11-17 17:52:04 +0000", 1258480324],
        ["2009-11-17 18:52:04 +0200", 1258476724],
    ];

    for (var i = 0; i < tests.length; i++)
    {
        var parsed = [[CPDate alloc] initWithString:tests[i][0]],
            correctSeconds = tests[i][1];
        [self assert:correctSeconds equals:[parsed timeIntervalSince1970]];
    }
}

- (void)testEncoding
{
    var date = new Date(),
        encodedDate = [CPKeyedArchiver archivedDataWithRootObject:date],
        decodedDate = [CPKeyedUnarchiver unarchiveObjectWithData:encodedDate];

    [self assert:date equals:decodedDate];
}
<commit_msg>Re #1556. Unit test CPDate dateWithTimeIntervalSinceReferenceDate:.<commit_after>@import <Foundation/CPDate.j>

@implementation CPDateTest : OJTestCase

- (void)testSince1970
{
    /* These two dates should be equal to Fri Feb 13 2009 15:31:30 GMT-0800 */
    unixDate = [CPDate dateWithTimeIntervalSince1970: 1234567890];
    cocoaDate = [CPDate dateWithTimeIntervalSinceReferenceDate: 253582290];
    [self assertTrue:[unixDate isEqualToDate: cocoaDate]];
}

- (void)testDate
{
    var before = new Date(),
        middle = [CPDate date],
        after = new Date(),
        future = [CPDate distantFuture],
        past = [CPDate distantPast];

    [self assertTrue:(before <= middle) message:"before not less than middle"];
    [self assertTrue:(middle <= after) message:"middle not less than after ("+middle+","+after+")"];

    [self assert:middle equals:[middle earlierDate:future] message:"earlierDate incorrect"];
    [self assert:middle equals:[middle laterDate:past] message:"laterDate incorrect"];
}

- (void)testEquals
{
    var now = [CPDate date];
    [self assert:now equals:now];
    [self assertFalse:[now isEqual:[CPNull null]]];
    [self assertFalse:[now isEqual:nil]];
}

/*!
    [date description] displays time in the current timezone. This test is a crude
    way to validate that this works right for different timezones: just run the test
    with different timezones configured.
*/
- (void)testParseNow
{
    var now = [CPDate new],
        alsoNow = [[CPDate alloc] initWithString:[now description]];

    [self assert:[now description] equals:[alsoNow description]];
}

- (void)testInitWithString
{
    var tests = [
            ["1970-01-01 00:00:00 +0000", 0],
            ["1970-01-01 00:01:00 +0000", 60],
            ["1970-01-01 01:00:00 +0000", 60*60],
            ["1970-01-02 00:00:00 +0000", 24*60*60],
            ["2009-11-17 17:52:04 +0000", 1258480324],
            ["2009-11-17 18:52:04 +0200", 1258476724],
        ];

    for (var i = 0; i < tests.length; i++)
    {
        var parsed = [[CPDate alloc] initWithString:tests[i][0]],
            correctSeconds = tests[i][1];
        [self assert:correctSeconds equals:[parsed timeIntervalSince1970]];
    }
}

- (void)testInitWithTimeIntervalSinceReferenceDate_
{
    var referenceDate = [[CPDate alloc] initWithTimeIntervalSinceReferenceDate:0],
        referenceDatePlusOneHour = [[CPDate alloc] initWithTimeIntervalSinceReferenceDate:3600];

    [self assert:[[CPDate alloc] initWithString:"2001-01-01 00:00:00 +0000"] equals:referenceDate message:@"reference date"];
    [self assert:[[CPDate alloc] initWithString:"2001-01-01 01:00:00 +0000"] equals:referenceDatePlusOneHour message:@"reference date plus one hour"];
}

- (void)testEncoding
{
    var date = new Date(),
        encodedDate = [CPKeyedArchiver archivedDataWithRootObject:date],
        decodedDate = [CPKeyedUnarchiver unarchiveObjectWithData:encodedDate];

    [self assert:date equals:decodedDate];
}

{'fraction_non_alphanumeric': 0.13307130825379002, 'fraction_numerical': 0.07991764926071496, 'mean_word_length': 3.725022104332449, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '1050735', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1619, 'n_words': 430}