1 (*i $Id: test_time.ml,v 1.10 2008/02/08 10:36:14 signoles Exp $ i*)
3 Printf.printf "Tests of Time:\n";;
10 Time_Zone.change (Time_Zone.UTC_Plus 10);;
12 test (make 30 60 80 = make 31 1 20) "30-60-80 = 31-1-20";;
13 test (normalize (make 22 0 0) = (make 22 0 0, 0)) "normalize 22-0-0";;
14 test (normalize (make 73 0 0) = (make 1 0 0, 3)) "normalize 73-0-0";;
15 test (normalize (make (-73) 0 0) = (make 23 0 0, -4)) "normalize (-73)-0-0";;
16 test (add (make 20 0 0) (Period.minute 70) = make 21 10 0) "add 20-0-0 70mn";;
17 test (next (make 20 3 31) `Minute = make 20 4 31) "next 20-3-31 `Minute";
18 test (prev (make 20 3 31) `Second = make 20 3 30) "prev 20-3-31 `Second";;
19 test (sub (make 6 5 4) (make 4 5 6) = Period.make 1 59 58) "sub 6-5-4 4-5-6";;
20 test (convert (make 20 0 0) (Time_Zone.UTC_Plus 2) (Time_Zone.UTC_Plus 4) =
21 make 22 0 0) "convert";;
22 test (to_gmt (make 20 0 0) = make 10 0 0) "to_gmt";;
23 test (from_gmt (make 20 0 0) = make 30 0 0) "from_gmt";;
24 test (midnight () = make 0 0 0) "midnight";;
25 test (midday () = make 12 0 0) "midday";;
26 test (hour (make 20 0 0) = 20) "hour";;
27 test (minute (make 20 10 0) = 10) "minute";;
28 test (second (make 20 10 5) = 5) "second";;
30 let one_two_three = make 1 2 3;;
31 let eq f1 f2 = abs_float (f1 -. f2) < 1e-5;;
32 test (to_seconds one_two_three = 3723) "to_seconds";;
33 test (eq (to_minutes one_two_three) 62.05) "to_minutes";;
34 test (to_hours (make 1 3 0) = 1.05) "to_hours";;
35 test (from_seconds 3723 = from_minutes 62.05) "from_seconds; from_minutes";;
36 test (from_hours 1.05 = make 1 3 0) "from_hours";;
37 test (is_pm (midnight ())) "is_pm midnight";;
38 test (is_pm (make 10 0 0)) "is_pm 10-0-0";;
39 test (is_pm (make 34 0 0)) "is_pm 34-0-0";;
40 test (not (is_pm (make (- 10) 0 0))) "not (is_pm (- 10) 0 0)";;
41 test (is_am (midday ())) "is_am midday";;
42 test (is_am (make 20 0 0)) "is_am 20-0-0";;
43 test (is_am (make (- 34) 0 0)) "is_am (- 34) 0 0";;
44 test (not (is_am (make 34 0 0))) "not (is_pm 34 0 0)";;
46 let one_two_three = Period.make 1 2 3;;
47 test (Period.to_seconds one_two_three = 3723) "Period.to_seconds";;
48 test (eq (Period.to_minutes one_two_three) 62.05) "Period.to_minutes";;
49 test (eq (Period.to_hours (Period.make 1 3 0)) 1.05) "Period.to_hours";;
53 Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;