1 (* Auxiliary functions for test cases
*)
5 fun check b
= if b
then "OK" else "WRONG";
6 fun check
' f
= (if f () then "OK" else "WRONG") handle _
=> "EXN";
8 fun range (from
, to
) p
=
11 (from
> to
) orelse (p from
) andalso (range (from
+1, to
) p
)
14 fun checkrange bounds
= check
o range bounds
;
16 fun tst0 s s
' = print (s ^
" \t" ^ s
' ^
"\n");
17 fun tst s b
= tst0
s (check b
);
18 fun tst
' s f
= tst0
s (check
' f
);
20 fun tstrange s bounds
= (tst s
) o range bounds
26 val _
= print
"\nFile time.sml: Testing structure Time...\n"
29 fun fib n
= if n
<2 then 1 else fib(n
-1) + fib(n
-2);
31 val bigt
= fromSeconds
987654321 + fromMicroseconds
500012;
32 val litt
= fromSeconds
454 + fromMicroseconds
501701
35 tst
' "test1" (fn _
=> zeroTime
+ bigt
= bigt
andalso bigt
- zeroTime
= bigt
);
38 tst
' "test2a" (fn _
=> toSeconds zeroTime
= 0
39 andalso zeroTime
= fromSeconds
0
40 andalso zeroTime
= fromMilliseconds
0
41 andalso zeroTime
= fromMicroseconds
0);
43 tst
' "test2b" (fn _
=> toSeconds bigt
= 987654321
44 andalso toSeconds litt
= 454
45 andalso toMilliseconds litt
= 454501
46 andalso toMicroseconds litt
= 454501701);
47 val test2c
= tst0
"test2c" ((fromSeconds ~
1 seq
"OK")
49 val test2d
= tst0
"test2d" ((fromMilliseconds ~
1 seq
"OK")
51 val test2e
= tst0
"test2e" ((fromMicroseconds ~
1 seq
"OK")
55 tst
' "test3a" (fn _
=> fromReal
0.0 = zeroTime
56 andalso fromReal
10.25 = fromSeconds
10 + fromMilliseconds
250);
57 val test3b
= tst0
"test3b" ((fromReal ~
1.0 seq
"OK")
59 val test3c
= tst0
"test3c" ((fromReal
1E300 seq
"OK")
60 handle Time
=> "OK" | _
=> "WRONG")
63 tst
' "test4a" (fn _
=> Real.==(toReal (fromReal
100.25), 100.25));
66 tst
' "test6a" (fn _
=> bigt
+ litt
= litt
+ bigt
67 andalso (bigt
+ litt
) - litt
= bigt
68 andalso (bigt
- litt
) + litt
= bigt
);
71 tst
' "test7a" (fn _
=> litt
<= litt
andalso litt
>= litt
72 andalso zeroTime
< litt
andalso litt
> zeroTime
73 andalso litt
< bigt
andalso bigt
> litt
74 andalso not (litt
> bigt
)
75 andalso not (bigt
< litt
)
76 andalso not(litt
< litt
)
77 andalso not(litt
> litt
));
80 tst
' "test8a" (fn _
=> now() <= now()
81 andalso (now () before fib
27 seq ()) <= now());
84 tst
' "test9a" (fn _
=> fmt
0 litt
= "455")
87 tst
' "test9b" (fn _
=> fmt
1 litt
= "454.5"
88 andalso fmt
2 litt
= "454.50"
89 andalso fmt
3 litt
= "454.502"
90 andalso fmt
4 litt
= "454.5017"
91 andalso fmt
5 litt
= "454.50170"
92 andalso fmt
6 litt
= "454.501701");
95 tst
' "test10a" (fn _
=>
97 SOME res
=> res
= fromMicroseconds r
103 ("189.1", 189100000),
104 ("189.125125", 189125125),
107 (" \n\t189crap", 189000000),
108 (" \n\t189.1crap", 189100000),
109 (" \n\t189.125125crap", 189125125),
110 (" \n\t.1crap", 100000),
111 (" \n\t.125125crap", 125125)];
114 List.app (fn s
=> tst0
"test10b" (case fromString s
of NONE
=> "OK" | _
=> "WRONG"))
115 ["", "now", "Monday"];