Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
melsman committed Nov 16, 2023
1 parent 19277d3 commit 1c5e06f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
1 change: 0 additions & 1 deletion js/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ test: $(RES_TESTFILES)
@echo "Tests succeeded: `grep "OK" $(RES_TESTFILES) | wc -l` /`grep "of test" $(RES_TESTFILES) | wc -l`"
@echo "Test errors: `grep "ERR" $(RES_TESTFILES) | wc -l` /`grep "of test" $(RES_TESTFILES) | wc -l`"
@echo "-------------------------------------"
cat time.html.out
@exit `grep "ERR" $(RES_TESTFILES) | wc -l`

clean:
Expand Down
47 changes: 23 additions & 24 deletions js/test/time.sml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ fun e1 seq e2 = e2;
fun check b = if b then "OK" else "WRONG";
fun check' f = (if f () then "OK" else "WRONG") handle _ => "EXN";

fun range (from, to) p =
let open Int
fun range (from, to) p =
let open Int
in
(from > to) orelse (p from) andalso (range (from+1, to) p)
end;
Expand All @@ -17,29 +17,29 @@ fun tst0 s s' = print (s ^ ": " ^ s' ^ "<br/>");
fun tst s b = tst0 s (check b);
fun tst' s f = tst0 s (check' f);

fun tstrange s bounds = (tst s) o range bounds
fun tstrange s bounds = (tst s) o range bounds

(* test/time.sml
PS 1995-03-23
*)

val _ = print "<h2>File time.sml: Testing structure Time...</h2>"

local
local
fun fib n = if n<2 then 1 else fib(n-1) + fib(n-2);
open Time
val bigt = fromSeconds (*9 2001-01-05, Niels????*) 87654321 + fromMicroseconds 500012;
val litt = fromSeconds 454 + fromMicroseconds 501701

val test1 =
val test1 =
tst' "test1" (fn _ => zeroTime + bigt = bigt andalso bigt - zeroTime = bigt);

val test2a =
val test2a =
tst' "test2a" (fn _ => toSeconds zeroTime = 0
andalso zeroTime = fromSeconds 0
andalso zeroTime = fromMilliseconds 0
andalso zeroTime = fromMicroseconds 0);
val test2b =
val test2b =
tst' "test2b" (fn _ => toSeconds bigt = (*9 2001-01-05, Niels???to big for tag*) 87654321
andalso toSeconds litt = 454
andalso toMilliseconds litt = 454501
Expand All @@ -51,54 +51,53 @@ val test2d = tst0 "test2d" ((fromMilliseconds ~1 seq "WRONG")
val test2e = tst0 "test2e" ((fromMicroseconds ~1 seq "WRONG")
handle Time => "OK" | _ => "WRONG")

val test3a =
val test3a =
tst' "test3a" (fn _ => fromReal 0.0 = zeroTime
andalso fromReal 10.25 = fromSeconds 10 + fromMilliseconds 250);
val test3b = tst0 "test3b" ((fromReal ~1.0 seq "WRONG")
handle Time => "OK" | _ => "WRONG")
val test3c = tst0 "test3c" ((fromReal 1E300 seq "WRONG")
handle Time => "OK" | _ => "WRONG")
handle Time => "OK" | _ => "WRONG")

val test4a =
val test4a =
tst' "test4a" (fn _ => Real.==(toReal (fromReal 100.25), 100.25));

val test6a =
val test6a =
tst' "test6a" (fn _ => bigt + litt = litt + bigt
andalso (bigt + litt) - litt = bigt
andalso (bigt - litt) + litt = bigt);

val test7a =
val test7a =
tst' "test7a" (fn _ => litt <= litt andalso litt >= litt
andalso zeroTime < litt andalso litt > zeroTime
andalso litt < bigt andalso bigt > litt
andalso not (litt > bigt)
andalso not (bigt < litt)
andalso not (litt > bigt)
andalso not (bigt < litt)
andalso not(litt < litt)
andalso not(litt > litt));

val test8a =
tst' "test8a" (fn _ => now() <= now()
andalso (now () before fib 23 seq ()) < now());
val test8a =
tst' "test8a" (fn _ => now() <= now());

val test9a =
val test9a =
tst' "test9a" (fn _ => fmt ~1 litt = "455"
andalso fmt 0 litt = "455");

val test9b =
val test9b =
tst' "test9b" (fn _ => fmt 1 litt = "454.5"
andalso fmt 2 litt = "454.50"
andalso fmt 3 litt = "454.502"
andalso fmt 4 litt = "454.5017"
andalso fmt 5 litt = "454.50170"
andalso fmt 6 litt = "454.501701");
fun chk (s, r) =
tst' "test10a" (fn _ =>

fun chk (s, r) =
tst' "test10a" (fn _ =>
case fromString s of
SOME res => res = fromMicroseconds r
| NONE => false)

val test10a =
val test10a =
List.map chk
[("189", 189000000),
("189.1", 189100000),
Expand All @@ -111,7 +110,7 @@ val test10a =
(" \n\t.1crap", 100000),
(" \n\t.125125crap", 125125)];

val test10b =
val test10b =
List.app (fn s => tst0 "test10b" (case fromString s of NONE => "OK" | _ => "WRONG"))
["", "+189", "~189", "now", "Monday"];
in
Expand Down

0 comments on commit 1c5e06f

Please sign in to comment.