Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Improvements to test.ceylon.time #570

Merged
merged 1 commit into from
May 9, 2016
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
56 changes: 30 additions & 26 deletions test-source/test/ceylon/time/testChronology.ceylon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ceylon.test {
assertEquals,
test
test,
parameters
}
import ceylon.time {
date,
Expand All @@ -16,39 +17,42 @@ import ceylon.time.chronology {
}

shared test void testUnixTime() {
assertEquals(719163, unixTime.epoch);
assertEquals(719163, unixTime.fixedFromTime(1));
assertEquals(1356998400000, unixTime.timeFromFixed(date(2013, january, 1).dayOfEra));
assertEquals(unixTime.timeOfDay(1357032630000), time(9, 30, 30).millisecondsOfDay);
assertEquals { expected = 719163; actual = unixTime.epoch; };
assertEquals { expected = 719163; actual = unixTime.fixedFromTime(1); };
assertEquals { expected = 1356998400000; actual = unixTime.timeFromFixed(date(2013, january, 1).dayOfEra); };
assertEquals { expected = unixTime.timeOfDay(1357032630000); actual = time(9, 30, 30).millisecondsOfDay; };
}

shared test void testGregorianMonths() {
assertEquals(1, gregorian.january);
assertEquals(2, gregorian.february);
assertEquals(3, gregorian.march);
assertEquals(4, gregorian.april);
assertEquals(5, gregorian.may);
assertEquals(6, gregorian.june);
assertEquals(7, gregorian.july);
assertEquals(8, gregorian.august);
assertEquals(9, gregorian.september);
assertEquals(10, gregorian.october);
assertEquals(11, gregorian.november);
assertEquals(12, gregorian.december);
}
[[Integer, Integer]*] gregorianMonths = [
[1, gregorian.january],
[2, gregorian.february],
[3, gregorian.march],
[4, gregorian.april],
[5, gregorian.may],
[6, gregorian.june],
[7, gregorian.july],
[8, gregorian.august],
[9, gregorian.september],
[10, gregorian.october],
[11, gregorian.november],
[12, gregorian.december]
];
parameters (`value gregorianMonths`)
shared test void testGregorianMonths(Integer expectedMonth, Integer actualMonth)
=> assertEquals { expected = expectedMonth; actual = actualMonth; };

shared test void testGregorian() {
gregorian.checkDate([2013, 1, 1]);
gregorian.checkDate([2012, 2, 29]);
gregorian.checkDate([2010, 12, 31]);

assertEquals([1970, 1, 1], gregorian.dateFrom(unixTime.epoch));
assertEquals(1, gregorian.dayFrom(unixTime.epoch));
assertEquals(tuesday.integer, gregorian.dayOfWeekFrom(735065));
assertEquals(719163, gregorian.fixedFrom([1970,1,1]));
assertEquals { expected = [1970, 1, 1]; actual = gregorian.dateFrom(unixTime.epoch); };
assertEquals { expected = 1; actual = gregorian.dayFrom(unixTime.epoch); };
assertEquals { expected = tuesday.integer; actual = gregorian.dayOfWeekFrom(735065); };
assertEquals { expected = 719163; actual = gregorian.fixedFrom([1970,1,1]); };

assertEquals(true, gregorian.leapYear(2012));
assertEquals(false, gregorian.leapYear(2010));
assertEquals { expected = true; actual = gregorian.leapYear(2012); };
assertEquals { expected = false; actual = gregorian.leapYear(2010); };

assertEquals(gregorian.january, gregorian.monthFrom(719163));
assertEquals { expected = gregorian.january; actual = gregorian.monthFrom(719163); };
}
8 changes: 4 additions & 4 deletions test-source/test/ceylon/time/testClock.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import ceylon.time { systemTime, Instant, fixedTime, offsetTime, Duration }
import ceylon.time.base { milliseconds }

test shared void testSystemTimeString() {
assertEquals("System time", systemTime.string);
assertEquals { expected = "System time"; actual = systemTime.string; };
}

test shared void testFixedTimeString() {
assertEquals("Fixed to 2013-11-07T20:52:10.000Z", fixedTime(Instant(1383857530000)).string);
assertEquals("Fixed to 2013-11-07T20:52:10.000Z", fixedTime(1383857530000).string);
assertEquals { expected = "Fixed to 2013-11-07T20:52:10.000Z"; actual = fixedTime(Instant(1383857530000)).string; };
assertEquals { expected = "Fixed to 2013-11-07T20:52:10.000Z"; actual = fixedTime(1383857530000).string; };
}

test shared void testOffsetTimeString() {
assertEquals("Offset of PT1H from ``systemTime.string``", offsetTime(systemTime, Duration(milliseconds.perHour)).string);
assertEquals { expected = "Offset of PT1H from ``systemTime.string``"; actual = offsetTime(systemTime, Duration(milliseconds.perHour)).string; };
}
56 changes: 28 additions & 28 deletions test-source/test/ceylon/time/testDateRange.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ shared test void testEqualsAndHashDateRange() {
}

shared test void testStepDays() {
assertEquals(days, jan_date_range.step);
assertEquals { expected = days; actual = jan_date_range.step; };
}

shared test void testStepMonths() {
assertEquals(months, jan_date_range.stepBy(months).step);
assertEquals { expected = months; actual = jan_date_range.stepBy(months).step; };
}

shared test void testStepYears() {
assertEquals(years, jan_date_range.stepBy(years).step);
assertEquals { expected = years; actual = jan_date_range.stepBy(years).step; };
}

shared test void testAnyExist() {
Expand Down Expand Up @@ -95,69 +95,69 @@ shared test void testGapDate() {
DateRange mar = date(2013, march, 1).rangeTo(date(2013, march, 31));
DateRange gap = date(2013, february, 1).rangeTo(date(2013, february, 28));

assertEquals(gap, jan_date_range.gap(mar));
assertEquals { expected = gap; actual = jan_date_range.gap(mar); };
}

shared test void testGapDateReverse() {
DateRange mar = date(2013, march, 1).rangeTo(date(2013, march,31));
DateRange gap = date(2013, february, 1).rangeTo(date(2013, february, 28));

assertEquals(gap, jan_date_range_reverse.gap(mar));
assertEquals { expected = gap; actual = jan_date_range_reverse.gap(mar); };
}

shared test void testGapDateOneYear() {
DateRange _2013 = date(2013, january, 1).rangeTo(date(2013, december, 31));
DateRange _2015 = date(2015, january, 1).rangeTo(date(2015, december, 31));

DateRange _2014 = date(2014, january, 1).rangeTo(date(2014, december, 31));
assertEquals(_2014, _2015.gap(_2013));
assertEquals { expected = _2014; actual = _2015.gap(_2013); };
}

shared test void testGapDateEmpty() {
DateRange feb = date(2013, february, 1).rangeTo(date(2013, february,28));

assertEquals(empty, jan_date_range_reverse.gap(feb));
assertEquals { expected = empty; actual = jan_date_range_reverse.gap(feb); };
}

shared test void testOverlapDateEmpty() {
DateRange decemberRange = date(2013, december, 1).rangeTo(date(2013, december, 31));

assertEquals(empty, jan_date_range.overlap(decemberRange));
assertEquals { expected = empty; actual = jan_date_range.overlap(decemberRange); };
}

shared test void testOverlapDate() {
DateRange halfJan = date(2013, january, 5).rangeTo(date(2013, january, 15));
DateRange overlap = date(2013, january, 5).rangeTo(date(2013, january, 15));

assertEquals(overlap, jan_date_range.overlap(halfJan));
assertEquals { expected = overlap; actual = jan_date_range.overlap(halfJan); };
}

shared test void testStepDayReverse() {
assertEquals( 31, jan_date_range_reverse.size);
assertEquals( date(2013, january, 31), jan_date_range_reverse.first);
assertEquals( date(2013, january, 1), jan_date_range_reverse.last);
assertEquals { expected = 31; actual = jan_date_range_reverse.size; };
assertEquals { expected = date(2013, january, 31); actual = jan_date_range_reverse.first; };
assertEquals { expected = date(2013, january, 1); actual = jan_date_range_reverse.last; };
}

shared test void testStepMonthReverse() {
DateRange interval = jan_date_range_reverse.stepBy(months);
assertEquals( 1, interval.size);
assertEquals( date(2013, january, 31), interval.first);
assertEquals( date(2013, january, 31), interval.last);
assertEquals { expected = 1; actual = interval.size; };
assertEquals { expected = date(2013, january, 31); actual = interval.first; };
assertEquals { expected = date(2013, january, 31); actual = interval.last; };
}

shared test void testStepYearReverse() {
DateRange interval = jan_date_range_reverse.stepBy(years);
assertEquals( 1, interval.size);
assertEquals( date(2013, january, 31), interval.first);
assertEquals( date(2013, january, 31), interval.last);
assertEquals { expected = 1; actual = interval.size; };
assertEquals { expected = date(2013, january, 31); actual = interval.first; };
assertEquals { expected = date(2013, january, 31); actual = interval.last; };
}

shared test void testContainsDate() {
assertEquals(true, date(2013, january, 15) in jan_date_range);
assertTrue(date(2013, january, 15) in jan_date_range);
}

shared test void testNotContainsDate() {
assertEquals(false, date(2013, january, 15) in jan_date_range.stepBy(years));
assertFalse(date(2013, january, 15) in jan_date_range.stepBy(years));
}

shared test void testGapRulesABSmallerCD() {
Expand Down Expand Up @@ -317,21 +317,21 @@ shared test void testOverlapRulesABHigherCD() {
}

test void testDateRangeString() {
assertEquals( "2013-10-01/2013-10-31", DateRange(date(2013, october, 1), date(2013, october, 31)).string );
assertEquals( "2014-01-01/2013-01-01", DateRange(date(2014, january, 1), date(2013, january, 1)).string );
assertEquals { expected = "2013-10-01/2013-10-31"; actual = DateRange(date(2013, october, 1), date(2013, october, 31)).string; };
assertEquals { expected = "2014-01-01/2013-01-01"; actual = DateRange(date(2014, january, 1), date(2013, january, 1)).string; };
}

void assertIntervalDate( Date start, Date end, Period period, Duration? duration = null ) {
value range = start.rangeTo(end);
assertEquals(period, range.period);
assertEquals { expected = period; actual = range.period; };

assertEquals( end, start.plus(period) );
assertEquals( start, end.minus(period) );
assertEquals { expected = end; actual = start.plus(period); };
assertEquals { expected = start; actual = end.minus(period); };

assertEquals( start, range.first );
assertEquals( end, range.last );
assertEquals { expected = start; actual = range.first; };
assertEquals { expected = end; actual = range.last; };

if( exists duration ) {
assertEquals(duration, range.duration);
assertEquals { expected = duration; actual = range.duration; };
}
}
Loading