Added some tests.
authorRichard W.M. Jones <rjones@redhat.com>
Sun, 16 Nov 2008 10:38:35 +0000 (10:38 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Sun, 16 Nov 2008 10:38:35 +0000 (10:38 +0000)
13 files changed:
.hgignore
ocaml-calendar/Makefile [new file with mode: 0644]
ocaml-calendar/gen_test.ml [new file with mode: 0644]
ocaml-calendar/test.ml [new file with mode: 0644]
ocaml-calendar/test_calendar.ml [new file with mode: 0644]
ocaml-calendar/test_date.ml [new file with mode: 0644]
ocaml-calendar/test_fcalendar.ml [new file with mode: 0644]
ocaml-calendar/test_fpcalendar.ml [new file with mode: 0644]
ocaml-calendar/test_ftime.ml [new file with mode: 0644]
ocaml-calendar/test_pcalendar.ml [new file with mode: 0644]
ocaml-calendar/test_printer.ml [new file with mode: 0644]
ocaml-calendar/test_time.ml [new file with mode: 0644]
ocaml-calendar/test_timezone.ml [new file with mode: 0644]

index e0ae2e5..fd99d20 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -71,7 +71,6 @@ nspr/nspr-4.7.2.tar.gz
 nss/nss-3.12.2.0-stripped.tar.bz2
 nss/nss-pem-20080124.tar.bz2
 ocaml/ocaml-3.11.0+beta1.tar.bz2
-ocaml/NUL
 ocaml/test1
 ocaml/test2
 ocaml/test3
@@ -81,10 +80,14 @@ ocaml/*.cmi
 ocaml/*.cmx
 ocaml/*.o
 ocaml-calendar/calendar-2.0.4.tar.gz
+ocaml-calendar/test
+ocaml-calendar/*.exe
+ocaml-calendar/*.cmi
+ocaml-calendar/*.cmx
+ocaml-calendar/*.o
 ocaml-csv/ocaml-csv-1.1.7.tar.gz
 ocaml-curses/ocaml-curses-20020319.tar.gz
 ocaml-extlib/extlib-1.5.1.tar.gz
-ocaml-extlib/NUL
 ocaml-extlib/test1
 ocaml-extlib/*.exe
 ocaml-extlib/*.cmi
diff --git a/ocaml-calendar/Makefile b/ocaml-calendar/Makefile
new file mode 100644 (file)
index 0000000..bc7ba4b
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- Makefile -*-
+# Test programs for ocaml-calendar.
+
+OCAMLOPTFLAGS = str.cmxa unix.cmxa -I +calendar calendarLib.cmx
+
+SRCS = gen_test.ml test_fcalendar.ml test_time.ml test_calendar.ml \
+  test_fpcalendar.ml test_pcalendar.ml test_timezone.ml test_date.ml \
+  test_ftime.ml test_printer.ml test.ml
+
+all: test test.exe
+
+test: $(SRCS)
+       ocamlopt $(OCAMLOPTFLAGS) $^ -o $@
+
+test.exe: $(SRCS)
+       i686-pc-mingw32-ocamlopt $(OCAMLOPTFLAGS) $^ -o $@
+
+clean:
+       rm -f test *.exe *.cmi *.cmx *.o
diff --git a/ocaml-calendar/gen_test.ml b/ocaml-calendar/gen_test.ml
new file mode 100644 (file)
index 0000000..6f49d47
--- /dev/null
@@ -0,0 +1,24 @@
+(*i $Id: gen_test.ml,v 1.2 2008/02/01 10:48:33 signoles Exp $ i*)
+
+let ok_ref = ref 0
+let ok () = incr ok_ref
+let nb_ok () = !ok_ref
+
+let bug_ref = ref 0
+let bug () = incr bug_ref
+let nb_bug () = !bug_ref
+
+let reset () =
+  ok_ref := 0;
+  bug_ref := 0
+
+let test x s = 
+  if x then ok () else begin Printf.printf "%s\n" s; bug () end;;
+
+let test_exn x s =
+  try
+    ignore (Lazy.force x);
+    Printf.printf "%s\n" s;
+    bug ()
+  with _ ->
+    ok ();;
diff --git a/ocaml-calendar/test.ml b/ocaml-calendar/test.ml
new file mode 100644 (file)
index 0000000..9102007
--- /dev/null
@@ -0,0 +1,22 @@
+(*i $Id: test.ml,v 1.6 2008/07/07 09:42:17 signoles Exp $ i*)
+
+(* Display the results *)
+
+let ok = 
+  Test_timezone.ok + Test_time.ok + Test_ftime.ok 
+  + Test_date.ok + Test_calendar.ok + Test_pcalendar.ok 
+  + Test_fcalendar.ok + Test_fpcalendar.ok
+  + Test_printer.ok;;
+
+let bug =
+  Test_timezone.bug + Test_time.bug + Test_ftime.bug
+  + Test_date.bug + Test_calendar.bug + Test_pcalendar.bug 
+  + Test_fcalendar.bug + Test_fpcalendar.bug
+  + Test_printer.bug;;
+
+Printf.printf "\nFinal results:\n";;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+
+assert (bug >= 0);;
+
+if bug > 0 then exit 1;;
diff --git a/ocaml-calendar/test_calendar.ml b/ocaml-calendar/test_calendar.ml
new file mode 100644 (file)
index 0000000..9140d1d
--- /dev/null
@@ -0,0 +1,137 @@
+(*i $Id: test_calendar.ml,v 1.18 2008/02/08 10:36:14 signoles Exp $ i*)
+
+Printf.printf "Tests of Calendar:\n";;
+
+open CalendarLib;;
+open Calendar;;
+include Gen_test;;
+reset ();;
+
+let eps = 0.000001;;
+
+Time_Zone.change Time_Zone.UTC;;
+
+(* Calendar *)
+
+test_exn (lazy (make (-4712) 1 1 12 0 (-1))) "-4713-12-31-23-59-59";;
+test (make (-4712) 1 1 12 0 0 = make (-4712) 1 0 36 0 0) "calendar coercion";;
+test (from_jd 0. = make (-4712) 1 1 12 0 0) "from_jd 0 = 4713 BC-1-1";;
+test (from_mjd 0. = make 1858 11 17 0 0 0) "from_mjd 0 = 1858-11-17";;
+
+Time_Zone.change (Time_Zone.UTC_Plus 5);;
+
+test (abs_float (to_jd (from_jd 12345.6789) -. 12345.6789) < eps) 
+  "to_jd (from_jd x) = x";;
+test (abs_float (to_mjd (from_mjd 12345.6789) -. 12345.6789) < eps) 
+  "to_mjd (from_mjd x) = x";;
+test (Period.to_date (Period.hour 60) = Date.Period.day 2) 
+  "period(60h) = period(2d)";;
+test (Period.compare (Period.day 2) (Period.hour 60) < 0) "Period.compare <";;
+test (Period.compare (Period.day 3) (Period.hour 60) > 0) "Period.compare >";;
+test (Period.compare 
+       (Period.add (Period.day 2) (Period.hour 12)) 
+       (Period.hour 60) = 0) "Period.compare =";;
+test 
+  (add (make 1 2 3 4 5 6) (Period.make 9 8 7 6 5 4) = make 10 10 10 10 10 10) 
+  "add 1-2-3-4-5-6 9-8-7-6-5-4";;
+test 
+  (add (make 3 1 1 0 0 0) (Period.make 0 0 0 (-25) 0 (-1)) =
+  make 2 12 30 22 59 59)
+  "add 3-1-1-0-0-0 0-0-0-(-25)-0-(-1)";;
+
+test 
+  (equal (rem (make 9 8 7 6 5 4) (Period.make 1 2 3 4 5 6)) 
+     (make 8 6 4 1 59 58))
+  "rem 9-8-7-6-5-4 1-2-3-4-5-6";;
+test (sub (make 0 0 7 6 5 4) (make 0 0 3 54 5 6) = Period.make 0 0 1 23 59 58) 
+  "sub 0-0-7-6-5-4 0-0-3-54-5-6";;
+
+test (Period.equal 
+       (Period.opp (Period.make 0 0 2 3 0 0)) 
+       (Period.make 0 0 (-2) (-3) 0 0))
+  "period opp";;
+
+(* Date *)
+
+let d = make 2003 12 31 12 24 48;;
+test (next d `Month = make 2004 1 31 12 24 48) "2003-12-31 + 1 mois";;
+test (add d (Period.month 2) = make 2004 3 2 12 24 48) "2003-12-31 + 2 mois";;
+let d2 = make (-3000) 1 1 6 12 24;;
+test (equal (rem d (sub d d2)) d2) "rem x (sub x y) = y";;
+test (is_leap_day (make 2000 2 24 0 0 0)) "2000-2-24 leap day";;
+test (not (is_leap_day (make 2000 2 25 0 0 0))) "2000-2-25 not leap day";;
+test (is_gregorian (make 1600 1 1 0 0 0)) "1600-1-1 gregorian";;
+test (not (is_gregorian (make 1400 1 1 0 0 0))) "1400-1-1 not gregorian";;
+test (is_julian (make 1582 1 1 0 0 0)) "1582-1-1 julian";;
+test (not (is_julian (make 1583 1 1 0 0 0))) "1583-1-1 not julian";;
+
+(* Time *)
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant UTC";;
+test (let n = Unix.time () in 
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant UTC";;
+
+Time_Zone.change (Time_Zone.UTC_Plus 10);;
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant +10";;
+test (let n = Unix.time () in 
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant +10";;
+
+test (equal (add (make 0 0 0 10 0 0) (Period.hour 30)) (make 0 0 1 16 0 0))
+  "add 0-0-0-20-0-0 30h";;
+test (equal (next (make 1999 12 31 23 59 59) `Second) (make 2000 1 1 0 0 0))
+  "next 1999-31-12-23-59-59 `Second";;
+let n = now ();;
+test (equal (prev (next n `Minute) `Minute) n) "prev next = id";;
+test (equal 
+       (convert 
+          (make 0 0 0 23 0 0) 
+          (Time_Zone.UTC_Plus 2) 
+          (Time_Zone.UTC_Plus 4))
+       (make 0 0 1 1 0 0)) "convert";;
+test (hour (make 0 0 0 20 0 0) = 20) "hour";;
+test (minute (make 0 0 0 20 10 0) = 10) "minute";;
+test (second (make 0 0 0 20 10 5) = 5) "second";;
+test (is_pm (make 0 0 0 10 0 0)) "is_pm 10-0-0";;
+test (is_pm (make 0 0 0 34 0 0)) "is_pm 34-0-0";;
+test (not (is_pm (make 0 0 0 (- 10) 0 0))) "not (is_pm (- 10) 0 0)";;
+test (is_am (make 0 0 0 20 0 0)) "is_am 20-0-0";;
+test (is_am (make 0 0 0 (- 34) 0 0)) "is_am (- 34) 0 0";;
+test (not (is_am (make 0 0 0 34 0 0))) "not (is_pm 34 0 0)";;
+
+Time_Zone.change Time_Zone.UTC;;
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant UTC2";;
+test (let n = Unix.time () in
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant UTC2";;
+
+test (to_unixfloat (make 1970 1 1 0 0 0) = 0.) "to_unixfloat 1 Jan 1970";;
+test (from_unixfloat 0. = make 1970 1 1 0 0 0) "from_unixfloat 1 Jan 1970";;
+test (Utils.Float.equal (to_unixfloat (make 2004 11 13 19 17 9)) 1100373429.)
+  "to_unixfloat";;
+test (equal (from_unixfloat 1100373429.) (make 2004 11 13 19 17 9)) 
+  "from_unixfloat";;
+test (from_unixtm (to_unixtm (make 2003 7 16 23 22 21)) = 
+       make 2003 7 16 23 22 21) 
+  "from_unixtm to_unixtm = id";;
+
+test (Period.to_time (Period.second 30) = Time.Period.second 30) 
+  "Period.to_time second";;
+test (Period.to_time (Period.day 6) = Time.Period.second 518400) 
+  "Period.to_time day";;
+test_exn (lazy (Period.to_time (Period.year 1))) "Period.to_time year";;
+test (Period.ymds (Period.make 1 2 3 1 2 3) = (1, 2, 3, 3723)) "Period.ymds";;
+test
+  (Period.ymds (Period.make (-1) (-2) (-3) (-1) (-2) (-3)) = (-1,-2,-4,82677))
+  "Period.ymds neg";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;
diff --git a/ocaml-calendar/test_date.ml b/ocaml-calendar/test_date.ml
new file mode 100644 (file)
index 0000000..682be89
--- /dev/null
@@ -0,0 +1,121 @@
+(*i $Id: test_date.ml,v 1.21 2008/02/08 13:06:45 signoles Exp $ i*)
+
+Printf.printf "Tests of Date:\n";;
+
+open CalendarLib;;
+open Date;;
+include Gen_test;;
+reset ();;
+
+test_exn (lazy (make (-4713) 1 1)) "make (-4713) 1 1";;
+test_exn (lazy (make 3268 1 23)) "make 3268 1 23";;
+test_exn (lazy (make 1582 10 5)) "make 1582 10 10";;
+test (compare (make 2003 2 29) (make 2003 3 1) = 0) "2003-2-29 = 2003-3-1";;
+let d = make 2003 12 31;;
+test (next d `Month = make 2004 1 31) "2003-12-31 + 1 mois";;
+test (add d (Period.month 2) = make 2004 3 2) "2003-12-31 + 2 mois";;
+let d2 = make (-3000) 1 1;;
+test (rem d (sub d d2) = d2) "rem x (sub x y) = y";;
+test (from_jd 0 = make (-4712) 1 1) "from_jd 0 = 4713 BC-1-1";;
+test (to_jd (from_jd 12345) = 12345) "to_jd (from_jd x) = x";;
+test (from_mjd 0 = make 1858 11 17) "from_mjd 0 = 1858-11-17";;
+test (to_mjd (from_mjd 12345) = 12345) "to_mjd (from_mjd x) = x";;
+test (is_leap_day (make 2000 2 24)) "2000-2-24 leap day";;
+test (not (is_leap_day (make 2000 2 25))) "2000-2-25 not leap day";;
+test (is_gregorian (make 1600 1 1)) "1600-1-1 gregorian";;
+test (not (is_gregorian (make 1400 1 1))) "1400-1-1 not gregorian";;
+test (is_julian (make 1582 1 1)) "1582-1-1 julian";;
+test (not (is_julian (make 1583 1 1))) "1583-1-1 not julian";;
+test (int_of_day Mon = 1) "Monday = 1";;
+test (int_of_day Sun = 7) "Sunday = 7";;
+test (day_of_int 1 = Mon) "1 = Monday";;
+test (day_of_int 7 = Sun) "1 = Monday";;
+test (int_of_month Jan = 1) "January = 1";;
+test (month_of_int 12 = Dec) "12 = December";;
+test (not (is_leap_year 1999)) "1999 not leap year";;
+test (not (is_leap_year 1800)) "1800 not leap year";;
+test (is_leap_year 1996) "1996 leap year";;
+test (is_leap_year 1600) "1600 leap year";;
+test (same_calendar 1956 1900) "same calendar 1956 1900";;
+test (same_calendar 2001 2013) "same calendar 2001 2013";;
+test (same_calendar 1998 2009) "same calendar 1998 2009";;
+test (same_calendar 2003 2025) "same calendar 2003 2025";;
+test (days_in_year 2000 = 366) "days_in_year 2000";;
+test (days_in_year 1900 = 365) "days_in_year 1900";;
+test (days_in_year ~month:Jan 2000 = 31) "days_in_year Jan 2000";;
+test (days_in_year ~month:Feb 2000 = 60) "days_in_year Feb 2000";;
+test (days_in_year ~month:Jan 2000 = 31) "days_in_year Jan 2000";;
+test (days_in_year ~month:Mar 1900 = 90) "days_in_year Mar 1900";;
+test (weeks_in_year 2000 = 52) "weeks_in_year 2000";;
+test (weeks_in_year 2020 = 53) "weeks_in_year 2020";;
+test (weeks_in_year 1991 = 52) "weeks_in_year 1991";;
+test (weeks_in_year 1999 = 52) "weeks_in_year 1999";;
+test (century 2000 = 20) "century 2000";;
+test (century 2001 = 21) "century 2001";;
+test (millenium 2000 = 2) "millenium 2000";;
+test (millenium 2001 = 3) "millenium 2001";;
+test (easter 2003 = make 2003 4 20) "Paques 2003";;
+test (Period.nb_days (Period.make 0 0 6) = 6) "Period.nb_days ok";;
+test_exn (lazy (Period.nb_days (Period.make 1 0 0))) "Period.nb_days ko";;
+test (week_first_last 21 2004 = (make 2004 5 17, make 2004 5 23)) 
+  "week_beggining_end";;
+test (Period.ymd (Period.make 1 2 3) = (1, 2, 3)) "Period.ymd";;
+test (nth_weekday_of_month 2004 Oct Thu 4 = make 2004 10 28) 
+  "nth_weekday_of_month";;
+test (nth_weekday_of_month 2006 Mar Fri 3 = make 2006 3 17) 
+  "nth_weekday_of_month";;
+test (equal (from_day_of_year 2008 39) (make 2008 2 8)) 
+  "from_day_of_year";;
+test (is_valid_date 2008 2 8) "is_valid_date";;
+test (not (is_valid_date 2008 2 30)) "not is_valid_date";;
+
+(* Unix *)
+Time_Zone.change Time_Zone.UTC;;
+test (to_unixfloat (make 1970 1 1) = 0.) "to_unixfloat 1 Jan 1970";;
+test (from_unixfloat 0. = make 1970 1 1) "from_unixfloat 0.";;
+test (to_unixfloat (make 2004 11 13) = 1100304000.) "to_unixfloat";;
+test (from_unixfloat 1100304000. = make 2004 11 13) "from_unixfloat";;
+test (from_unixtm (to_unixtm (make 2003 7 16)) = make 2003 7 16) 
+  "from_unixtm to_unixtm = id";;
+Time_Zone.change (Time_Zone.UTC_Plus (-1));;
+test (from_unixfloat 0. = make 1969 12 31) "from_unixfloat 0. (dec-)";;
+test (from_unixtm { Unix.tm_sec = 0; tm_min = 0; tm_hour = 0; tm_mday = 1; 
+                   tm_mon = 0; tm_year = 70; tm_wday = 4; tm_yday = 0; 
+                   tm_isdst = false } = make 1969 12 31) 
+  "from_unixtm (dec-)";;
+Time_Zone.change (Time_Zone.UTC_Plus 1);;
+test (from_unixfloat 1100390390. = make 2004 11 14) "from_unixfloat (dec+)";;
+test (from_unixtm { Unix.tm_sec = 0; tm_min = 0; tm_hour = 0; tm_mday = 14; 
+                   tm_mon = 10; tm_year = 104; tm_wday = 0; tm_yday = 318;
+                   tm_isdst = false } = make 2004 11 14) 
+  "from_unixtm (dec+)";;
+test (from_unixtm (to_unixtm (make 2003 7 16)) = make 2003 7 16) 
+  "from_unixtm to_unixtm = id";;
+
+(* to_business *)
+test (to_business (make 2003 1 1) = (2003, 1, Wed)) "to_business 1";;
+test (to_business (make 2003 12 31) = (2004, 1, Wed)) "to_business 2";;
+test (to_business (make 2002 12 31) = (2003, 1, Tue)) "to_business 3";;
+test (to_business (make 2005 1 1) = (2004, 53, Sat)) "to_business 4";;
+test (to_business (make 2004 12 31) = (2004, 53, Fri)) "to_business 5";;
+test (to_business (make 2006 1 1) = (2005, 52, Sun)) "to_business 6";;
+test (to_business (make 2005 1 17) = (2005, 3, Mon)) "to_business 7";;
+test (to_business (make 2006 1 31) = (2006, 5, Tue)) "to_business 8";;
+test (to_business (make 2005 1 31) = (2005, 5, Mon)) "to_business 9";;
+(* from_business *)
+test (from_business 2003 1 Wed = make 2003 1 1) "from_business 1";;
+test (from_business 2004 1 Wed = make 2003 12 31) "from_business 2";;
+test (from_business 2003 1 Tue = make 2002 12 31) "from_business 3";;
+test (from_business 2004 53 Sat = make 2005 1 1) "from_business 4";;
+test (from_business 2004 53 Fri = make 2004 12 31) "from_business 5";;
+test (from_business 2005 52 Sun = make 2006 1 1) "from_business 6";;
+test (from_business 2005 3 Mon = make 2005 1 17) "from_business 7";;
+test (from_business 2006 5 Tue = make 2006 1 31) "from_business 8";;
+test (from_business 2005 5 Mon = make 2005 1 31) "from_business 9";;
+test_exn (lazy (from_business 2005 0 Sun)) "from_business_bad 1";;
+test_exn (lazy (from_business 2005 53 Sun)) "from_business_bad 2";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;
diff --git a/ocaml-calendar/test_fcalendar.ml b/ocaml-calendar/test_fcalendar.ml
new file mode 100644 (file)
index 0000000..4394c16
--- /dev/null
@@ -0,0 +1,154 @@
+(*i $Id: test_fcalendar.ml,v 1.3 2008/02/08 10:36:14 signoles Exp $ i*)
+
+Printf.printf "Tests of Fcalendar:\n";;
+
+open CalendarLib;;
+open Fcalendar;;
+include Gen_test;;
+reset ();;
+
+let eps = 0.000001;;
+
+Time_Zone.change Time_Zone.UTC;;
+
+(* Fcalendar *)
+
+test_exn (lazy (make (-4712) 1 1 12 0 (-1.))) "-4713-12-31-23-59-59";;
+test (make (-4712) 1 1 12 0 0. = make (-4712) 1 0 36 0 0.) "calendar coercion";;
+test (from_jd 0. = make (-4712) 1 1 12 0 0.) "from_jd 0 = 4713 BC-1-1";;
+test (from_mjd 0. = make 1858 11 17 0 0 0.) "from_mjd 0 = 1858-11-17";;
+
+Time_Zone.change (Time_Zone.UTC_Plus 5);;
+
+test (abs_float (to_jd (from_jd 12345.6789) -. 12345.6789) < eps) 
+  "to_jd (from_jd x) = x";;
+test (abs_float (to_mjd (from_mjd 12345.6789) -. 12345.6789) < eps) 
+  "to_mjd (from_mjd x) = x";;
+test (Period.to_date (Period.hour 60) = Date.Period.day 2) 
+  "period(60h) = period(2d)";;
+test (Period.compare (Period.day 2) (Period.hour 60) < 0) "Period.compare <";;
+test (Period.compare (Period.day 3) (Period.hour 60) > 0) "Period.compare >";;
+test (Period.compare 
+       (Period.add (Period.day 2) (Period.hour 12)) 
+       (Period.hour 60) = 0) "Period.compare =";;
+test 
+  (add (make 1 2 3 4 5 6.) (Period.make 9 8 7 6 5 4.5) = 
+      make 10 10 10 10 10 10.5) 
+  "add 1-2-3-4-5-6 9-8-7-6-5-4.5";;
+test 
+  (add (make 3 1 1 0 0 0.7) (Period.make 0 0 0 (-25) 0 (-1.3)) =
+  make 2 12 30 22 59 59.4)
+  "add 3-1-1-0-0-0.7 0-0-0-(-25)-0-(-1.3)";;
+
+test 
+  (equal (rem (make 9 8 7 6 5 4.9) (Period.make 1 2 3 4 5 6.4)) 
+     (make 8 6 4 1 59 58.5))
+  "rem 9-8-7-6-5-4 1-2-3-4-5-6";;
+
+test (Period.equal 
+       (sub (make 0 0 7 6 5 4.) (make 0 0 3 54 5 6.)) 
+       (Period.make 0 0 1 23 59 58.))
+  "sub 0-0-7-6-5-4 0-0-3-54-5-6";;
+
+test (Period.equal 
+       (Period.opp (Period.make 0 0 2 3 0 0.)) 
+       (Period.make 0 0 (-2) (-3) 0 0.))
+  "period opp";;
+
+(* Date *)
+
+let d = make 2003 12 31 12 24 48.;;
+test (next d `Month = make 2004 1 31 12 24 48.) "2003-12-31 + 1 mois";;
+test (add d (Period.month 2) = make 2004 3 2 12 24 48.) "2003-12-31 + 2 mois";;
+let d2 = make (-3000) 1 1 6 12 24.5;;
+test (equal (rem d (sub d d2)) d2) "rem x (sub x y) = y";;
+test (is_leap_day (make 2000 2 24 0 0 0.)) "2000-2-24 leap day";;
+test (not (is_leap_day (make 2000 2 25 0 0 0.))) "2000-2-25 not leap day";;
+test (is_gregorian (make 1600 1 1 0 0 0.4)) "1600-1-1 gregorian";;
+test (not (is_gregorian (make 1400 1 1 0 0 0.1))) "1400-1-1 not gregorian";;
+test (is_julian (make 1582 1 1 0 0 0.1)) "1582-1-1 julian";;
+test (not (is_julian (make 1583 1 1 0 0 0.9832))) "1583-1-1 not julian";;
+
+(* Time *)
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant UTC";;
+test (let n = Unix.time () in 
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant UTC";;
+
+Time_Zone.change (Time_Zone.UTC_Plus 10);;
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant +10";;
+test (let n = Unix.time () in 
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant +10";;
+
+test (equal (add (make 0 0 0 10 0 0.1) (Period.hour 30)) (make 0 0 1 16 0 0.1))
+  "add 0-0-0-20-0-0 30h";;
+test (equal 
+       (next (make 1999 12 31 23 59 59.43) `Second) 
+       (make 2000 1 1 0 0 0.43))
+  "next 1999-31-12-23-59-59 `Second";;
+let n = now ();;
+test (equal (prev (next n `Minute) `Minute) n) "prev next = id";;
+test (equal 
+       (convert 
+          (make 0 0 0 23 0 0.1234) 
+          (Time_Zone.UTC_Plus 2) 
+          (Time_Zone.UTC_Plus 4))
+       (make 0 0 1 1 0 0.1234)) "convert";;
+
+(* Loss of precision *)
+test (hour (make 0 0 0 20 0 0.) = 19) "hour";;
+test (hour (make 0 0 0 20 0 0.2) = 20) "hour";;
+
+test (minute (make 0 0 0 20 10 0.2) = 10) "minute";;
+
+(* Loss of precision *)
+test (Utils.Float.equal (second (make 0 0 0 20 10 5.123)) 5.123004) "second";;
+
+test (is_pm (make 0 0 0 10 0 0.1)) "is_pm 10-0-0";;
+test (is_pm (make 0 0 0 34 0 0.)) "is_pm 34-0-0";;
+test (not (is_pm (make 0 0 0 (- 10) 0 0.))) "not (is_pm (- 10) 0 0)";;
+test (is_am (make 0 0 0 20 0 0.)) "is_am 20-0-0";;
+test (is_am (make 0 0 0 (- 34) 0 0.)) "is_am (- 34) 0 0";;
+test (not (is_am (make 0 0 0 34 0 0.))) "not (is_pm 34 0 0)";;
+
+Time_Zone.change Time_Zone.UTC;;
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant UTC2";;
+test (let n = Unix.time () in
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant UTC2";;
+
+test (to_unixfloat (make 1970 1 1 0 0 0.) = 0.) "to_unixfloat 1 Jan 1970";;
+test (from_unixfloat 0. = make 1970 1 1 0 0 0.) "from_unixfloat 1 Jan 1970";;
+test (Utils.Float.equal (to_unixfloat (make 2004 11 13 19 17 9.)) 1100373429.)
+  "to_unixfloat";;
+test (equal (from_unixfloat 1100373429.) (make 2004 11 13 19 17 9.)) 
+  "from_unixfloat";;
+
+(* Loss of precision *)
+test (equal
+       (from_unixtm (to_unixtm (make 2003 7 16 23 22 21.)))
+       (make 2003 7 16 23 22 20.)) 
+  "from_unixtm to_unixtm = id";;
+
+test (Period.to_time (Period.second 30.12) = Time.Period.second 30.12) 
+  "Period.to_time second";;
+test (Period.to_time (Period.day 6) = Time.Period.second 518400.) 
+  "Period.to_time day";;
+test_exn (lazy (Period.to_time (Period.year 1))) "Period.to_time year";;
+test (Period.ymds (Period.make 1 2 3 1 2 3.1) = (1, 2, 3, 3723.1)) 
+  "Period.ymds";;
+test
+  (Period.ymds (Period.make (-1) (-2) (-3) (-1) (-2) (-3.)) = (-1,-2,-4,82677.))
+  "Period.ymds neg";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;
diff --git a/ocaml-calendar/test_fpcalendar.ml b/ocaml-calendar/test_fpcalendar.ml
new file mode 100644 (file)
index 0000000..03b591a
--- /dev/null
@@ -0,0 +1,148 @@
+(*i $Id: test_fpcalendar.ml,v 1.2 2008/02/08 10:36:14 signoles Exp $ i*)
+
+Printf.printf "Tests of FPcalendar:\n";;
+
+open CalendarLib;;
+open Fcalendar.Precise;;
+include Gen_test;;
+reset ();;
+
+let eps = 0.000001;;
+
+Time_Zone.change Time_Zone.UTC;;
+
+(* Fcalendar *)
+
+test_exn (lazy (make (-4712) 1 1 12 0 (-1.))) "-4713-12-31-23-59-59";;
+test (make (-4712) 1 1 12 0 0. = make (-4712) 1 0 36 0 0.) "calendar coercion";;
+test (from_jd 0. = make (-4712) 1 1 12 0 0.) "from_jd 0 = 4713 BC-1-1";;
+test (from_mjd 0. = make 1858 11 17 0 0 0.) "from_mjd 0 = 1858-11-17";;
+
+Time_Zone.change (Time_Zone.UTC_Plus 5);;
+
+test (abs_float (to_jd (from_jd 12345.6789) -. 12345.6789) < eps) 
+  "to_jd (from_jd x) = x";;
+test (abs_float (to_mjd (from_mjd 12345.6789) -. 12345.6789) < eps) 
+  "to_mjd (from_mjd x) = x";;
+test (Period.to_date (Period.hour 60) = Date.Period.day 2) 
+  "period(60h) = period(2d)";;
+test (Period.compare (Period.day 2) (Period.hour 60) < 0) "Period.compare <";;
+test (Period.compare (Period.day 3) (Period.hour 60) > 0) "Period.compare >";;
+test (Period.compare 
+       (Period.add (Period.day 2) (Period.hour 12)) 
+       (Period.hour 60) = 0) "Period.compare =";;
+test 
+  (add (make 1 2 3 4 5 6.) (Period.make 9 8 7 6 5 4.5) = 
+      make 10 10 10 10 10 10.5) 
+  "add 1-2-3-4-5-6 9-8-7-6-5-4.5";;
+test 
+  (add (make 3 1 1 0 0 0.7) (Period.make 0 0 0 (-25) 0 (-1.3)) =
+  make 2 12 30 22 59 59.4)
+  "add 3-1-1-0-0-0.7 0-0-0-(-25)-0-(-1.3)";;
+
+test 
+  (equal (rem (make 9 8 7 6 5 4.9) (Period.make 1 2 3 4 5 6.4)) 
+     (make 8 6 4 1 59 58.5))
+  "rem 9-8-7-6-5-4 1-2-3-4-5-6";;
+
+test (Period.equal 
+       (sub (make 0 0 7 6 5 4.) (make 0 0 3 54 5 6.)) 
+       (Period.make 0 0 1 23 59 58.))
+  "sub 0-0-7-6-5-4 0-0-3-54-5-6";;
+
+test (Period.equal 
+       (Period.opp (Period.make 0 0 2 3 0 0.)) 
+       (Period.make 0 0 (-2) (-3) 0 0.))
+  "period opp";;
+
+(* Date *)
+
+let d = make 2003 12 31 12 24 48.;;
+test (next d `Month = make 2004 1 31 12 24 48.) "2003-12-31 + 1 mois";;
+test (add d (Period.month 2) = make 2004 3 2 12 24 48.) "2003-12-31 + 2 mois";;
+let d2 = make (-3000) 1 1 6 12 24.5;;
+test (equal (rem d (sub d d2)) d2) "rem x (sub x y) = y";;
+test (is_leap_day (make 2000 2 24 0 0 0.)) "2000-2-24 leap day";;
+test (not (is_leap_day (make 2000 2 25 0 0 0.))) "2000-2-25 not leap day";;
+test (is_gregorian (make 1600 1 1 0 0 0.4)) "1600-1-1 gregorian";;
+test (not (is_gregorian (make 1400 1 1 0 0 0.1))) "1400-1-1 not gregorian";;
+test (is_julian (make 1582 1 1 0 0 0.1)) "1582-1-1 julian";;
+test (not (is_julian (make 1583 1 1 0 0 0.9832))) "1583-1-1 not julian";;
+
+(* Time *)
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant UTC";;
+test (let n = Unix.time () in 
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant UTC";;
+
+Time_Zone.change (Time_Zone.UTC_Plus 10);;
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant +10";;
+test (let n = Unix.time () in 
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant +10";;
+
+test (equal (add (make 0 0 0 10 0 0.1) (Period.hour 30)) (make 0 0 1 16 0 0.1))
+  "add 0-0-0-20-0-0 30h";;
+test (equal 
+       (next (make 1999 12 31 23 59 59.43) `Second) 
+       (make 2000 1 1 0 0 0.43))
+  "next 1999-31-12-23-59-59 `Second";;
+let n = now ();;
+test (equal (prev (next n `Minute) `Minute) n) "prev next = id";;
+test (equal 
+       (convert 
+          (make 0 0 0 23 0 0.1234) 
+          (Time_Zone.UTC_Plus 2) 
+          (Time_Zone.UTC_Plus 4))
+       (make 0 0 1 1 0 0.1234)) "convert";;
+
+test (hour (make 0 0 0 20 0 0.) = 20) "hour";;
+test (minute (make 0 0 0 20 10 0.2) = 10) "minute";;
+test (Utils.Float.equal (second (make 0 0 0 20 10 5.123)) 5.123) "second";;
+
+test (is_pm (make 0 0 0 10 0 0.1)) "is_pm 10-0-0";;
+test (is_pm (make 0 0 0 34 0 0.)) "is_pm 34-0-0";;
+test (not (is_pm (make 0 0 0 (- 10) 0 0.))) "not (is_pm (- 10) 0 0)";;
+test (is_am (make 0 0 0 20 0 0.)) "is_am 20-0-0";;
+test (is_am (make 0 0 0 (- 34) 0 0.)) "is_am (- 34) 0 0";;
+test (not (is_am (make 0 0 0 34 0 0.))) "not (is_pm 34 0 0)";;
+
+Time_Zone.change Time_Zone.UTC;;
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant UTC2";;
+test (let n = Unix.time () in
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant UTC2";;
+
+test (to_unixfloat (make 1970 1 1 0 0 0.) = 0.) "to_unixfloat 1 Jan 1970";;
+test (from_unixfloat 0. = make 1970 1 1 0 0 0.) "from_unixfloat 1 Jan 1970";;
+test (floor (to_unixfloat (make 2004 11 13 19 17 10.)) = 1100373429.)
+  "to_unixfloat";;
+test (equal (from_unixfloat 1100373429.) (make 2004 11 13 19 17 09.)) 
+  "from_unixfloat";;
+
+test (equal
+       (from_unixtm (to_unixtm (make 2003 7 16 23 22 21.)))
+       (make 2003 7 16 23 22 21.)) 
+  "from_unixtm to_unixtm = id";;
+
+test (Period.to_time (Period.second 30.12) = Time.Period.second 30.12) 
+  "Period.to_time second";;
+test (Period.to_time (Period.day 6) = Time.Period.second 518400.) 
+  "Period.to_time day";;
+test_exn (lazy (Period.to_time (Period.year 1))) "Period.to_time year";;
+test (Period.ymds (Period.make 1 2 3 1 2 3.1) = (1, 2, 3, 3723.1)) 
+  "Period.ymds";;
+test
+  (Period.ymds (Period.make (-1) (-2) (-3) (-1) (-2) (-3.)) = (-1,-2,-4,82677.))
+  "Period.ymds neg";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;
diff --git a/ocaml-calendar/test_ftime.ml b/ocaml-calendar/test_ftime.ml
new file mode 100644 (file)
index 0000000..fcddc3a
--- /dev/null
@@ -0,0 +1,60 @@
+(*i $Id: test_ftime.ml,v 1.2 2008/02/08 10:36:14 signoles Exp $ i*)
+
+Printf.printf "Tests of Ftime:\n";;
+
+open CalendarLib
+open Ftime;;
+include Gen_test;;
+reset ();;
+
+Time_Zone.change (Time_Zone.UTC_Plus 10);;
+
+(* Some [=] are used which should be replaced by [equal]. *)
+
+test (make 30 60 80.5 = make 31 1 20.5) "30-60-80.5 = 31-1-20.5";;
+test (normalize (make 22 0 0.1) = (make 22 0 0.1, 0)) "normalize 22-0-0.1";;
+test (normalize (make 73 0 0.) = (make 1 0 0., 3)) "normalize 73-0-0";;
+test (normalize (make (-73) 0 0.) = (make 23 0 0., -4)) "normalize (-73)-0-0";;
+test (add (make 20 0 0.2) (Period.minute 70) = make 21 10 0.2) 
+  "add 20-0-0.2 70mn";;
+test (next (make 20 3 31.) `Minute = make 20 4 31.) "next 20-3-31 `Minute";
+test (prev (make 20 3 31.34) `Second = make 20 3 30.34) 
+  "prev 20-3-31.34 `Second";;
+test (Period.equal (sub (make 6 5 4.) (make 4 5 6.1)) (Period.make 1 59 57.9))
+  "sub 6-5-4. 4-5-6.1";;
+test (convert (make 20 0 0.123) (Time_Zone.UTC_Plus 2) (Time_Zone.UTC_Plus 4) = 
+       make 22 0 0.123) "convert";;
+test (to_gmt (make 20 0 0.) = make 10 0 0.) "to_gmt";;
+test (from_gmt (make 20 0 0.) = make 30 0 0.) "from_gmt";;
+test (midnight () = make 0 0 0.) "midnight";;
+test (midday () = make 12 0 0.) "midday";;
+test (hour (make 20 0 59.99) = 20) "hour";;
+test (minute (make 20 10 0.) = 10) "minute";;
+test (second (make 20 10 5.) = 5.) "second";;
+
+let one_two_three = make 1 2 3.;;
+test (to_seconds one_two_three = 3723.) "to_seconds";;
+test (to_minutes one_two_three = 62.05) "to_minutes";;
+test (Utils.Float.equal (to_hours (make 1 3 0.4)) 1.050111) "to_hours";;
+test (equal (from_seconds 3723.2) (from_minutes 62.053333333)) 
+  "from_seconds; from_minutes";;
+test (from_hours 1.05 = make 1 3 0.) "from_hours";;
+test (is_pm (midnight ())) "is_pm midnight";;
+test (is_pm (make 10 0 0.)) "is_pm 10-0-0";;
+test (is_pm (make 34 0 0.)) "is_pm 34-0-0";;
+test (not (is_pm (make (- 10) 0 0.))) "not (is_pm (- 10) 0 0)";;
+test (is_am (midday ())) "is_am midday";;
+test (is_am (make 20 0 0.)) "is_am 20-0-0";;
+test (is_am (make (- 34) 0 0.)) "is_am (- 34) 0 0";;
+test (not (is_am (make 34 0 0.))) "not (is_pm 34 0 0)";;
+
+let one_two_three = Period.make 1 2 3.;;
+test (Period.to_seconds one_two_three = 3723.) "Period.to_seconds";;
+test (Period.to_minutes one_two_three = 62.05) "Period.to_minutes";;
+test (Utils.Float.equal (Period.to_hours (Period.make 1 3 0.1)) 1.050028) 
+  "Period.to_hours";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;
diff --git a/ocaml-calendar/test_pcalendar.ml b/ocaml-calendar/test_pcalendar.ml
new file mode 100644 (file)
index 0000000..5836d3a
--- /dev/null
@@ -0,0 +1,139 @@
+(*i $Id: test_pcalendar.ml,v 1.2 2008/02/08 10:36:14 signoles Exp $ i*)
+
+Printf.printf "Tests of Precise Calendar:\n";;
+
+open CalendarLib;;
+open Calendar.Precise;;
+include Gen_test;;
+reset ();;
+
+let eps = 0.000001;;
+
+Time_Zone.change Time_Zone.UTC;;
+
+(* Calendar *)
+
+test_exn (lazy (make (-4712) 1 1 12 0 (-1))) "-4713-12-31-23-59-59";;
+test (make (-4712) 1 1 12 0 0 = make (-4712) 1 0 36 0 0) "calendar coercion";;
+test (from_jd 0. = make (-4712) 1 1 12 0 0) "from_jd 0 = 4713 BC-1-1";;
+test (from_mjd 0. = make 1858 11 17 0 0 0) "from_mjd 0 = 1858-11-17";;
+
+Time_Zone.change (Time_Zone.UTC_Plus 5);;
+
+test (abs_float (to_jd (from_jd 12345.6789) -. 12345.6789) < eps) 
+  "to_jd (from_jd x) = x";;
+test (abs_float (to_mjd (from_mjd 12345.6789) -. 12345.6789) < eps) 
+  "to_mjd (from_mjd x) = x";;
+test (Period.to_date (Period.hour 60) = Date.Period.day 2) 
+  "period(60h) = period(2d)";;
+test (Period.compare (Period.day 2) (Period.hour 60) < 0) "Period.compare <";;
+test (Period.compare (Period.day 3) (Period.hour 60) > 0) "Period.compare >";;
+test (Period.compare 
+       (Period.add (Period.day 2) (Period.hour 12)) 
+       (Period.hour 60) = 0) "Period.compare =";;
+
+test 
+  (add (make 1 2 3 4 5 6) (Period.make 9 8 7 6 5 4) = make 10 10 10 10 10 10) 
+  "add 1-2-3-4-5-6 9-8-7-6-5-4";;
+test 
+  (add (make 3 1 1 0 0 0) (Period.make 0 0 0 (-25) 0 (-1)) =
+  make 2 12 30 22 59 59)
+  "add 3-1-1-0-0-0 0-0-0-(-25)-0-(-1)";;
+
+test 
+  (equal (rem (make 9 8 7 6 5 4) (Period.make 1 2 3 4 5 6)) 
+     (make 8 6 4 1 59 58))
+  "rem 9-8-7-6-5-4 1-2-3-4-5-6";;
+test (sub (make 0 0 7 6 5 4) (make 0 0 3 54 5 6) = Period.make 0 0 1 23 59 58) 
+  "sub 0-0-7-6-5-4 0-0-3-54-5-6";;
+
+test (Period.equal 
+       (Period.opp (Period.make 0 0 2 3 0 0)) 
+       (Period.make 0 0 (-2) (-3) 0 0))
+  "period opp";;
+
+(* Date *)
+
+let d = make 2003 12 31 12 24 48;;
+test (next d `Month = make 2004 1 31 12 24 48) "2003-12-31 + 1 mois";;
+test (add d (Period.month 2) = make 2004 3 2 12 24 48) "2003-12-31 + 2 mois";;
+let d2 = make (-3000) 1 1 6 12 24;;
+test (equal (rem d (sub d d2)) d2) "rem x (sub x y) = y";;
+test (is_leap_day (make 2000 2 24 0 0 0)) "2000-2-24 leap day";;
+test (not (is_leap_day (make 2000 2 25 0 0 0))) "2000-2-25 not leap day";;
+test (is_gregorian (make 1600 1 1 0 0 0)) "1600-1-1 gregorian";;
+test (not (is_gregorian (make 1400 1 1 0 0 0))) "1400-1-1 not gregorian";;
+test (is_julian (make 1582 1 1 0 0 0)) "1582-1-1 julian";;
+test (not (is_julian (make 1583 1 1 0 0 0))) "1583-1-1 not julian";;
+
+(* Time *)
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant UTC";;
+test (let n = Unix.time () in 
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant UTC";;
+
+Time_Zone.change (Time_Zone.UTC_Plus 10);;
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant +10";;
+test (let n = Unix.time () in 
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant +10";;
+
+test (equal (add (make 0 0 0 10 0 0) (Period.hour 30)) (make 0 0 1 16 0 0))
+  "add 0-0-0-20-0-0 30h";;
+test (equal (next (make 1999 12 31 23 59 59) `Second) (make 2000 1 1 0 0 0))
+  "next 1999-31-12-23-59-59 `Second";;
+let n = now ();;
+test (equal (prev (next n `Minute) `Minute) n) "prev next = id";;
+
+test (equal 
+       (convert 
+          (make 0 0 0 23 0 0) 
+          (Time_Zone.UTC_Plus 2) 
+          (Time_Zone.UTC_Plus 4))
+       (make 0 0 1 1 0 0)) "convert";;
+test (hour (make 0 0 0 20 0 0) = 20) "hour";;
+test (minute (make 0 0 0 20 10 0) = 10) "minute";;
+test (second (make 0 0 0 20 10 5) = 5) "second";;
+test (is_pm (make 0 0 0 10 0 0)) "is_pm 10-0-0";;
+test (is_pm (make 0 0 0 34 0 0)) "is_pm 34-0-0";;
+test (not (is_pm (make 0 0 0 (- 10) 0 0))) "not (is_pm (- 10) 0 0)";;
+test (is_am (make 0 0 0 20 0 0)) "is_am 20-0-0";;
+test (is_am (make 0 0 0 (- 34) 0 0)) "is_am (- 34) 0 0";;
+test (not (is_am (make 0 0 0 34 0 0))) "not (is_pm 34 0 0)";;
+
+Time_Zone.change Time_Zone.UTC;;
+
+test (let n = Unix.gmtime (Unix.time ()) in 
+      hour (from_unixtm n) = n.Unix.tm_hour) "from_unixtm invariant UTC2";;
+test (let n = Unix.time () in
+      hour (from_unixfloat n) = (Unix.gmtime n).Unix.tm_hour) 
+  "from_unixfloat invariant UTC2";;
+
+test (to_unixfloat (make 1970 1 1 0 0 0) = 0.) "to_unixfloat 1 Jan 1970";;
+test (from_unixfloat 0. = make 1970 1 1 0 0 0) "from_unixfloat 1 Jan 1970";;
+test (Utils.Float.equal (to_unixfloat (make 2004 11 13 19 17 9)) 1100373429.)
+  "to_unixfloat";;
+test (equal (from_unixfloat 1100373429.) (make 2004 11 13 19 17 9)) 
+  "from_unixfloat";;
+test (from_unixtm (to_unixtm (make 2003 7 16 23 22 21)) = 
+       make 2003 7 16 23 22 21) 
+  "from_unixtm to_unixtm = id";;
+
+test (Period.to_time (Period.second 30) = Time.Period.second 30) 
+  "Period.to_time second";;
+test (Period.to_time (Period.day 6) = Time.Period.second 518400) 
+  "Period.to_time day";;
+test_exn (lazy (Period.to_time (Period.year 1))) "Period.to_time year";;
+test (Period.ymds (Period.make 1 2 3 1 2 3) = (1, 2, 3, 3723)) "Period.ymds";;
+test
+  (Period.ymds (Period.make (-1) (-2) (-3) (-1) (-2) (-3)) = (-1,-2,-4,82677))
+  "Period.ymds neg";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;
diff --git a/ocaml-calendar/test_printer.ml b/ocaml-calendar/test_printer.ml
new file mode 100644 (file)
index 0000000..20dd8d8
--- /dev/null
@@ -0,0 +1,67 @@
+(*i $Id: test_printer.ml,v 1.9 2008/07/07 09:42:17 signoles Exp $ i*)
+
+Printf.printf "Tests of Printer:\n";;
+
+open CalendarLib;;
+include Gen_test;;
+reset ();;
+
+open Printer.Date;;
+let d = Date.make 2003 1 6;;
+test (sprint "%D" d = "01/06/03") "sprint %D";;
+test (sprint "the date is %B, the %-dth" d = "the date is January, the 6th")
+  "sprint (long sentence)";;
+test (sprint "%j" d = "006") "sprint %j";;
+test (sprint "%-j" d = "6") "sprint %j";;
+test (sprint "%_j" d = "  6") "sprint %j";;
+test (sprint "%j" (Date.make 2003 1 10) = "010") "sprint %j";;
+test (sprint "%-j" (Date.make 2003 1 10) = "10") "sprint %j";;
+test (sprint "%_j" (Date.make 2003 1 10) = " 10") "sprint %j";;
+test (from_string "2003-01-06" = Date.make 2003 1 6) "from_string";;
+test (from_fstring "%y-%m-%d" "03-01-06" = Date.make 1903 1 6) "from_fstring";;
+test 
+  (from_fstring "%Y%t%m%t%d" "1903\t01\t06" = Date.make 1903 1 6) 
+  "from_fstring %t";;
+test 
+  (from_fstring "%Y-%B-%d" "2007-May-14" = Date.make 2007 5 14) 
+  "from_fstring %B";;
+
+test 
+  (from_fstring "%Y-%b-%d" "2007-Jan-14" = Date.make 2007 1 14) 
+  "from_fstring %B";;
+
+test (from_fstring "%Y %V %w" "2004 01 1" = Date.make 2003 12 29) 
+  "from_fstring %Y %V %w";;
+test (from_fstring "%V %Y %w" "52 1999 7" = Date.make 2000 1 2) 
+  "from_fstring %w %Y %V";;
+test_exn (lazy (from_fstring "%Y %w" "1999 7")) "from_fstring_exn";;
+test (from_fstring "%Y%j" "1903001" = Date.make 1903 1 1) "from_fstring %Y%j";;
+test (from_fstring "%j%Y" "0011903" = Date.make 1903 1 1) "from_fstring %j%Y";;
+test_exn (lazy (from_fstring "%j" "001")) "from_fstring_exn 2";;
+
+open Printer.Time;;
+test (to_string (Time.make 12 1 4) = "12:01:04") "to_string (on TimePrinter)";;
+test (sprint "%I" (Time.make 36 4 3) = "12") "sprint %I (on TimePrinter)";;
+test (sprint "%r" (Time.make 24 4 3) = "12:04:03 AM") 
+  "sprint %r (on TimePrinter)";;
+test (from_fstring "%r" "10:47:25 AM" = Time.make 10 47 25)
+  "from_fstring AM (on TimePrinter)";;
+test (from_fstring "%r" "10:47:25 PM" = Time.make 22 47 25)
+  "from_fstring PM (on TimePrinter)";;
+test_exn (lazy (from_fstring "%p %I:%M:%S" "TM 5:26:17"))
+  "from_fstring error on %p (on TimePrinter)";;
+
+open Printer.Calendar;;
+test (sprint "%c" (Calendar.make 2003 1 6 12 1 4) = "Mon Jan 06 12:01:04 2003")
+  "sprint %c";;
+test (to_string (Calendar.make 2004 10 25 24 0 1) = "2004-10-26 00:00:01")
+  "to_string (on CalendarPrinter)";;
+test 
+  (from_fstring "%c" "Mon May 14 10:30:00 2007" 
+   = Calendar.make 2007 5 14 10 30 0)
+  "from_fstring (on CalendarPrinter)";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;
diff --git a/ocaml-calendar/test_time.ml b/ocaml-calendar/test_time.ml
new file mode 100644 (file)
index 0000000..4c034d9
--- /dev/null
@@ -0,0 +1,53 @@
+(*i $Id: test_time.ml,v 1.10 2008/02/08 10:36:14 signoles Exp $ i*)
+
+Printf.printf "Tests of Time:\n";;
+
+open CalendarLib
+open Time;;
+include Gen_test;;
+reset ();;
+
+Time_Zone.change (Time_Zone.UTC_Plus 10);;
+
+test (make 30 60 80 = make 31 1 20) "30-60-80 = 31-1-20";;
+test (normalize (make 22 0 0) = (make 22 0 0, 0)) "normalize 22-0-0";;
+test (normalize (make 73 0 0) = (make 1 0 0, 3)) "normalize 73-0-0";;
+test (normalize (make (-73) 0 0) = (make 23 0 0, -4)) "normalize (-73)-0-0";;
+test (add (make 20 0 0) (Period.minute 70) = make 21 10 0) "add 20-0-0 70mn";;
+test (next (make 20 3 31) `Minute = make 20 4 31) "next 20-3-31 `Minute";
+test (prev (make 20 3 31) `Second = make 20 3 30) "prev 20-3-31 `Second";;
+test (sub (make 6 5 4) (make 4 5 6) = Period.make 1 59 58) "sub 6-5-4 4-5-6";;
+test (convert (make 20 0 0) (Time_Zone.UTC_Plus 2) (Time_Zone.UTC_Plus 4) = 
+       make 22 0 0) "convert";;
+test (to_gmt (make 20 0 0) = make 10 0 0) "to_gmt";;
+test (from_gmt (make 20 0 0) = make 30 0 0) "from_gmt";;
+test (midnight () = make 0 0 0) "midnight";;
+test (midday () = make 12 0 0) "midday";;
+test (hour (make 20 0 0) = 20) "hour";;
+test (minute (make 20 10 0) = 10) "minute";;
+test (second (make 20 10 5) = 5) "second";;
+
+let one_two_three = make 1 2 3;;
+test (to_seconds one_two_three = 3723) "to_seconds";;
+test (to_minutes one_two_three = 62.05) "to_minutes";;
+test (to_hours (make 1 3 0) = 1.05) "to_hours";;
+test (from_seconds 3723 = from_minutes 62.05) "from_seconds; from_minutes";;
+test (from_hours 1.05 = make 1 3 0) "from_hours";;
+test (is_pm (midnight ())) "is_pm midnight";;
+test (is_pm (make 10 0 0)) "is_pm 10-0-0";;
+test (is_pm (make 34 0 0)) "is_pm 34-0-0";;
+test (not (is_pm (make (- 10) 0 0))) "not (is_pm (- 10) 0 0)";;
+test (is_am (midday ())) "is_am midday";;
+test (is_am (make 20 0 0)) "is_am 20-0-0";;
+test (is_am (make (- 34) 0 0)) "is_am (- 34) 0 0";;
+test (not (is_am (make 34 0 0))) "not (is_pm 34 0 0)";;
+
+let one_two_three = Period.make 1 2 3;;
+test (Period.to_seconds one_two_three = 3723) "Period.to_seconds";;
+test (Period.to_minutes one_two_three = 62.05) "Period.to_minutes";;
+test (Period.to_hours (Period.make 1 3 0) = 1.05) "Period.to_hours";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;
diff --git a/ocaml-calendar/test_timezone.ml b/ocaml-calendar/test_timezone.ml
new file mode 100644 (file)
index 0000000..c24f860
--- /dev/null
@@ -0,0 +1,27 @@
+(*i $Id: test_timezone.ml,v 1.8 2008/02/08 10:36:14 signoles Exp $ i*)
+
+Printf.printf "Tests of Time_Zone:\n";;
+
+open CalendarLib
+open Time_Zone;;
+include Gen_test;;
+reset ();;
+
+test (current () = UTC) "current () = UTC";;
+change Local;;
+test (current () = Local) "current () = Local";;
+test (gap UTC (UTC_Plus (-5)) = -5) "gap UTC (UTC_Plus (-5)) = -5";;
+let g6 = UTC_Plus 6;;
+test 
+  (gap g6 Local = gap g6 UTC + gap UTC Local)
+  "gap g6 Local = gap g6 UTC + gap UTC Local";;
+test_exn (lazy (change (UTC_Plus 13))) "change 13";;
+test_exn (lazy (change (UTC_Plus (-15)))) "change (-15)";;
+change (UTC_Plus 4);;
+test (from_gmt () = 4) "from_gmt () = 4";;
+test (to_gmt () = -4) "to_gmt () = -4";;
+
+let ok = nb_ok ();;
+let bug = nb_bug ();;
+Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;
+flush stdout;;