1 (*i $Id: test_ftime.ml,v 1.2 2008/02/08 10:36:14 signoles Exp $ i*)
3 Printf.printf "Tests of Ftime:\n";;
10 Time_Zone.change (Time_Zone.UTC_Plus 10);;
12 (* Some [=] are used which should be replaced by [equal]. *)
14 test (make 30 60 80.5 = make 31 1 20.5) "30-60-80.5 = 31-1-20.5";;
15 test (normalize (make 22 0 0.1) = (make 22 0 0.1, 0)) "normalize 22-0-0.1";;
16 test (normalize (make 73 0 0.) = (make 1 0 0., 3)) "normalize 73-0-0";;
17 test (normalize (make (-73) 0 0.) = (make 23 0 0., -4)) "normalize (-73)-0-0";;
18 test (add (make 20 0 0.2) (Period.minute 70) = make 21 10 0.2)
20 test (next (make 20 3 31.) `Minute = make 20 4 31.) "next 20-3-31 `Minute";
21 test (prev (make 20 3 31.34) `Second = make 20 3 30.34)
22 "prev 20-3-31.34 `Second";;
23 test (Period.equal (sub (make 6 5 4.) (make 4 5 6.1)) (Period.make 1 59 57.9))
24 "sub 6-5-4. 4-5-6.1";;
25 test (convert (make 20 0 0.123) (Time_Zone.UTC_Plus 2) (Time_Zone.UTC_Plus 4) =
26 make 22 0 0.123) "convert";;
27 test (to_gmt (make 20 0 0.) = make 10 0 0.) "to_gmt";;
28 test (from_gmt (make 20 0 0.) = make 30 0 0.) "from_gmt";;
29 test (midnight () = make 0 0 0.) "midnight";;
30 test (midday () = make 12 0 0.) "midday";;
31 test (hour (make 20 0 59.99) = 20) "hour";;
32 test (minute (make 20 10 0.) = 10) "minute";;
33 test (second (make 20 10 5.) = 5.) "second";;
35 let one_two_three = make 1 2 3.;;
36 test (to_seconds one_two_three = 3723.) "to_seconds";;
37 test (to_minutes one_two_three = 62.05) "to_minutes";;
38 test (Utils.Float.equal (to_hours (make 1 3 0.4)) 1.050111) "to_hours";;
39 test (equal (from_seconds 3723.2) (from_minutes 62.053333333))
40 "from_seconds; from_minutes";;
41 test (from_hours 1.05 = make 1 3 0.) "from_hours";;
42 test (is_pm (midnight ())) "is_pm midnight";;
43 test (is_pm (make 10 0 0.)) "is_pm 10-0-0";;
44 test (is_pm (make 34 0 0.)) "is_pm 34-0-0";;
45 test (not (is_pm (make (- 10) 0 0.))) "not (is_pm (- 10) 0 0)";;
46 test (is_am (midday ())) "is_am midday";;
47 test (is_am (make 20 0 0.)) "is_am 20-0-0";;
48 test (is_am (make (- 34) 0 0.)) "is_am (- 34) 0 0";;
49 test (not (is_am (make 34 0 0.))) "not (is_pm 34 0 0)";;
51 let one_two_three = Period.make 1 2 3.;;
52 let eq f1 f2 = abs_float (f1 -. f2) < 1e-5;;
53 test (eq (Period.to_seconds one_two_three) 3723.) "Period.to_seconds";;
54 test (eq (Period.to_minutes one_two_three) 62.05) "Period.to_minutes";;
55 test (Utils.Float.equal (Period.to_hours (Period.make 1 3 0.1)) 1.050028)
60 Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;