mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 01:13:30 +00:00
Add further calendar tests.
tests/hard_coded/calendar_basics.{m,exp}:
Add tests of current_{local,utc}_time/3.
Fix spelling a spot.
This commit is contained in:
@@ -122,7 +122,7 @@ Unix epoch microsecond = 0
|
|||||||
julian_day_number(-4713-11-24 00:00:00) = 0 OK (Start of Julian period)
|
julian_day_number(-4713-11-24 00:00:00) = 0 OK (Start of Julian period)
|
||||||
julian_day_number(1970-01-01 00:00:00) = 2440588 OK (Unix epoch)
|
julian_day_number(1970-01-01 00:00:00) = 2440588 OK (Unix epoch)
|
||||||
julian_day_number(2000-01-01 00:00:00) = 2451545 OK (J2000)
|
julian_day_number(2000-01-01 00:00:00) = 2451545 OK (J2000)
|
||||||
julian_day_number(1582-10-14 00:00:00) = 2299160 OK (Day before Gregorian calender adoption)
|
julian_day_number(1582-10-14 00:00:00) = 2299160 OK (Day before Gregorian calendar adoption)
|
||||||
julian_day_number(1582-10-15 00:00:00) = 2299161 OK (First day of the Gregorian calendar)
|
julian_day_number(1582-10-15 00:00:00) = 2299161 OK (First day of the Gregorian calendar)
|
||||||
julian_day_number(2000-02-29 00:00:00) = 2451604 OK (Leap day)
|
julian_day_number(2000-02-29 00:00:00) = 2451604 OK (Leap day)
|
||||||
julian_day_number(2000-03-01 00:00:00) = 2451605 OK (Day after leap day)
|
julian_day_number(2000-03-01 00:00:00) = 2451605 OK (Day after leap day)
|
||||||
@@ -137,3 +137,7 @@ julian_day_number(2000-01-01 00:00:00) = 2451545 OK (Midnight)
|
|||||||
julian_day_number(2000-01-01 23:59:59) = 2451545 OK (End of day)
|
julian_day_number(2000-01-01 23:59:59) = 2451545 OK (End of day)
|
||||||
julian_day_number(10000-01-01 00:00:00) = 5373485 OK (Large year)
|
julian_day_number(10000-01-01 00:00:00) = 5373485 OK (Large year)
|
||||||
|
|
||||||
|
=== Test current_{local,utc}_time/3 ===
|
||||||
|
|
||||||
|
TEST: current_local_time/3 PASSED
|
||||||
|
TEST: current_utc_time/3 PASSED
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ main(!IO) :-
|
|||||||
test_days_in_month(!IO),
|
test_days_in_month(!IO),
|
||||||
test_is_leap_year(!IO),
|
test_is_leap_year(!IO),
|
||||||
test_unix_epoch(!IO),
|
test_unix_epoch(!IO),
|
||||||
test_julian_day_number(!IO).
|
test_julian_day_number(!IO),
|
||||||
|
test_clocks(!IO).
|
||||||
|
|
||||||
%---------------------------------------------------------------------------%
|
%---------------------------------------------------------------------------%
|
||||||
|
|
||||||
@@ -223,7 +224,7 @@ julian_day_tests = [
|
|||||||
2451545
|
2451545
|
||||||
),
|
),
|
||||||
julian_day_test(
|
julian_day_test(
|
||||||
"Day before Gregorian calender adoption",
|
"Day before Gregorian calendar adoption",
|
||||||
det_init_date_time(1582, october, 14, 0, 0, 0, 0),
|
det_init_date_time(1582, october, 14, 0, 0, 0, 0),
|
||||||
2299160
|
2299160
|
||||||
),
|
),
|
||||||
@@ -313,6 +314,44 @@ months = [
|
|||||||
december
|
december
|
||||||
].
|
].
|
||||||
|
|
||||||
|
%---------------------------------------------------------------------------%
|
||||||
|
|
||||||
|
:- pred test_clocks(io::di, io::uo) is cc_multi.
|
||||||
|
|
||||||
|
test_clocks(!IO) :-
|
||||||
|
io.write_string("=== Test current_{local,utc}_time/3 ===\n\n", !IO),
|
||||||
|
|
||||||
|
% Any test that examines the entire date_time returned by
|
||||||
|
% current_{local,utc}_time/3 will necessarily be nondeterministic.
|
||||||
|
% We can however check that:
|
||||||
|
%
|
||||||
|
% 1. The predicate returns a valid date_time and does not throw an
|
||||||
|
% exception.
|
||||||
|
% 2. The microsecond component is zero (as documented).
|
||||||
|
|
||||||
|
do_clock_test("current_local_time/3", current_local_time, !IO),
|
||||||
|
do_clock_test("current_utc_time/3", current_utc_time, !IO).
|
||||||
|
|
||||||
|
:- pred do_clock_test(string::in,
|
||||||
|
pred(date_time, io, io)::in(pred(out,di, uo) is det),
|
||||||
|
io::di, io::uo) is cc_multi.
|
||||||
|
|
||||||
|
do_clock_test(ClockDesc, ClockPred, !IO) :-
|
||||||
|
io.format("TEST: %s ", [s(ClockDesc)], !IO),
|
||||||
|
( try [io(!IO)]
|
||||||
|
ClockPred(DateTime, !IO)
|
||||||
|
then
|
||||||
|
Microseconds = DateTime ^ microsecond,
|
||||||
|
( if Microseconds = 0 then
|
||||||
|
io.write_string("PASSED\n", !IO)
|
||||||
|
else
|
||||||
|
io.format("FAILED (microseconds = %d)\n",
|
||||||
|
[i(Microseconds)], !IO)
|
||||||
|
)
|
||||||
|
catch_any _ ->
|
||||||
|
io.write_string("FAILED (exception)\n", !IO)
|
||||||
|
).
|
||||||
|
|
||||||
%---------------------------------------------------------------------------%
|
%---------------------------------------------------------------------------%
|
||||||
:- end_module calendar_basics.
|
:- end_module calendar_basics.
|
||||||
%---------------------------------------------------------------------------%
|
%---------------------------------------------------------------------------%
|
||||||
|
|||||||
Reference in New Issue
Block a user