[m-rev.] for review: Changes to time library test cases.
James Goddard
goddardjames at yahoo.com
Wed Dec 17 12:55:17 AEDT 2003
Estimated hours taken: 3
Branches: main
Revised the test cases for the time library.
tests/time_test.m:
mktime(localtime(Time)) is now considered to be close enough to the
original Time if it is less than 1 second earlier.
tests/dst_test.m:
Tests daylight savings time is implemented correctly.
Also tests localtime vs gmtime on the changeover dates.
tests/dst_test.exp:
corresponding expected output.
tests/Mmakefile:
Added dst_test to the list.
Added rule for dst_test, which sets the TZ environmental variable
to 'Australia/Melbourne' before running the test.
Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.211
diff -u -d -r1.211 Mmakefile
--- Mmakefile 5 Dec 2003 05:15:14 -0000 1.211
+++ Mmakefile 17 Dec 2003 01:14:20 -0000
@@ -40,6 +40,7 @@
det_in_semidet_cntxt \
division_test \
dot_separator \
+ dst_test \
dupcall_types_bug \
dupcall_impurity \
elim_special_pred \
@@ -186,7 +187,7 @@
endif
# Tests of the Java foreign language interface only
-# work in IL grades
+# work in Java grades
ifeq "$(filter java%,$(GRADE))" ""
JAVA_PROGS =
else
@@ -347,16 +348,16 @@
# We currently don't do any testing in grade java on this directory,
# except for java_test.m.
-ifneq "$(findstring java,$(GRADE))" ""
- PROGS = $(JAVA_PROGS)
-else
+#ifneq "$(findstring java,$(GRADE))" ""
+# PROGS = $(JAVA_PROGS)
+#else
PROGS = $(ORDINARY_PROGS) $(BROKEN_FOR_LCC_PROGS) \
$(CLOSURE_LAYOUT_PROGS) $(EXCEPTION_PROGS) \
$(BACKEND_PROGS) $(NONDET_C_PROGS) \
$(C_AND_GC_ONLY_PROGS) $(STATIC_LINK_PROGS) \
$(CHAR_REP_PROGS) $(BROKEN_FOR_PROFDEEP) \
$(FACTT_PROGS) $(DOTNET_PROGS) $(JAVA_PROGS)
-endif
+#endif
# --split-c-files does not work in the hl* grades (e.g. hlc.gc),
# because it hasn't yet been implemented yet.
@@ -400,6 +401,26 @@
< $@.tmp > $@; \
rm -f $@.tmp; \
fi
+
+#-----------------------------------------------------------------------------#
+
+# dst_test checks various predicates associated with Daylight Savings.
+# Since all the test data is based on Melbourne's DST conventions, the
+# timezone environment variable TZ must be set accordingly.
+
+ifneq "$(findstring java,$(GRADE))" ""
+
+dst_test.out: dst_test.class
+ TZ="Australia/Melbourne" $(JAVA) dst_test > $@ 2>&1 || \
+ { grep . $@ /dev/null; exit 1; }
+
+else
+
+dst_test.out: dst_test
+ TZ="Australia/Melbourne" ./$< > $@ 2>&1 || \
+ { grep . $@ /dev/null; exit 1; }
+
+endif
#-----------------------------------------------------------------------------#
Index: dst_test.exp
===================================================================
RCS file: dst_test.exp
diff -N dst_test.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dst_test.exp 17 Dec 2003 01:40:29 -0000
@@ -0,0 +1,31 @@
+start DST succeeded
+end DST succeeded
+
+Local: Sun Oct 26 01:59:00 2003
+GMT: Sat Oct 25 15:59:00 2003
+Local: Sun Oct 26 03:00:00 2003
+GMT: Sat Oct 25 16:00:00 2003
+Local: Sun Oct 26 03:01:00 2003
+GMT: Sat Oct 25 16:01:00 2003
+
+Local: Sun Mar 28 01:59:00 2004
+GMT: Sat Mar 27 14:59:00 2004
+Local: Sun Mar 28 02:00:00 2004
+GMT: Sat Mar 27 15:00:00 2004
+Local: Sun Mar 28 02:01:00 2004
+GMT: Sat Mar 27 15:01:00 2004
+
+Local: Sun Mar 28 02:59:00 2004
+GMT: Sat Mar 27 15:59:00 2004
+Local: Sun Mar 28 02:00:00 2004
+GMT: Sat Mar 27 16:00:00 2004
+Local: Sun Mar 28 02:01:00 2004
+GMT: Sat Mar 27 16:01:00 2004
+
+Local: Sun Mar 28 02:59:00 2004
+GMT: Sat Mar 27 16:59:00 2004
+Local: Sun Mar 28 03:00:00 2004
+GMT: Sat Mar 27 17:00:00 2004
+Local: Sun Mar 28 03:01:00 2004
+GMT: Sat Mar 27 17:01:00 2004
+
Index: dst_test.m
===================================================================
RCS file: dst_test.m
diff -N dst_test.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dst_test.m 17 Dec 2003 01:33:51 -0000
@@ -0,0 +1,85 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% In Melbourne, daylight savings
+% Starts: 2 am EST (Eastern Standard Time) on 26 October 2003
+% Ends: 2 am EST (Eastern Standard Time) on 28 March 2004
+% At start of daylight saving period, move clock forward one hour
+% At end of daylight saving period, move clock back one hour
+%
+
+:- module dst_test.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module std_util, time.
+
+main -->
+ difftest,
+ io__nl,
+ local_vs_gm_test,
+ io__nl.
+
+:- pred difftest(io__state::di, io__state::uo) is det.
+
+difftest -->
+ % Sunday 2003-10-26 01:30:00
+ { BeforeStart = mktime(tm(103, 9, 26, 1, 30, 0, 298, 0,
+ yes(standard_time))) },
+ % Sunday 2003-10-26 03:30:00
+ { AfterStart = mktime(tm(103, 9, 26, 3, 30, 0, 298, 0,
+ yes(daylight_time))) },
+ % difference should be 1 hour
+ ( { difftime(AfterStart, BeforeStart) = 3600.0 } ->
+ io__write_string("start DST succeeded\n")
+ ;
+ io__write_string("start DST failed\n")
+ ),
+
+ % Sunday 2004-02-28 02:30:00 (occurs twice)
+ { BeforeEnd = mktime(tm(104, 2, 28, 2, 30, 0, 87, 0,
+ yes(daylight_time))) },
+ { AfterEnd = mktime(tm(104, 2, 28, 2, 30, 0, 87, 0,
+ yes(standard_time))) },
+ % difference should be 1 hour
+ ( { difftime(AfterEnd, BeforeEnd) = 3600.0 } ->
+ io__write_string("end DST succeeded\n")
+ ;
+ io__write_string("end DST failed\n")
+ ).
+
+:- pred local_vs_gm_test(io__state::di, io__state::uo) is det.
+
+local_vs_gm_test -->
+ local_vs_gm_test(tm(103, 9, 26, 1, 59, 0, 298, 0, yes(standard_time))),
+ local_vs_gm_test(tm(103, 9, 26, 3, 0, 0, 298, 0, yes(daylight_time))),
+ local_vs_gm_test(tm(103, 9, 26, 3, 1, 0, 298, 0, yes(daylight_time))),
+ io__nl,
+
+ local_vs_gm_test(tm(104, 2, 28, 1, 59, 0, 87, 0, yes(daylight_time))),
+ local_vs_gm_test(tm(104, 2, 28, 2, 0, 0, 87, 0, yes(daylight_time))),
+ local_vs_gm_test(tm(104, 2, 28, 2, 1, 0, 87, 0, yes(daylight_time))),
+ io__nl,
+
+ local_vs_gm_test(tm(104, 2, 28, 2, 59, 0, 87, 0, yes(daylight_time))),
+ local_vs_gm_test(tm(104, 2, 28, 2, 0, 0, 87, 0, yes(standard_time))),
+ local_vs_gm_test(tm(104, 2, 28, 2, 1, 0, 87, 0, yes(standard_time))),
+ io__nl,
+
+ local_vs_gm_test(tm(104, 2, 28, 2, 59, 0, 87, 0, yes(standard_time))),
+ local_vs_gm_test(tm(104, 2, 28, 3, 0, 0, 87, 0, yes(standard_time))),
+ local_vs_gm_test(tm(104, 2, 28, 3, 1, 0, 87, 0, yes(standard_time))).
+
+:- pred local_vs_gm_test(tm::in, io__state::di, io__state::uo) is det.
+
+local_vs_gm_test(TM) -->
+ { Time = mktime(TM) },
+ io__write_string("Local:\t"),
+ io__write_string(asctime(localtime(Time))),
+ io__write_string("GMT:\t"),
+ io__write_string(asctime(gmtime(Time))).
+
Index: time_test.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/time_test.m,v
retrieving revision 1.2
diff -u -d -r1.2 time_test.m
--- time_test.m 31 May 2001 17:12:52 -0000 1.2
+++ time_test.m 16 Dec 2003 06:14:11 -0000
@@ -8,11 +8,12 @@
:- implementation.
-:- import_module std_util, time.
+:- import_module std_util, time, float.
main -->
time(Time),
- ( { mktime(localtime(Time)) = Time } ->
+ { Diff = difftime(Time, mktime(localtime(Time))) },
+ ( { (Diff >= 0.0, Diff < 1.0) } ->
io__write_string("mktime succeeded\n")
;
io__write_string("mktime failed\n")
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list