home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / test / time.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  2.8 KB  |  98 lines  |  [TEXT/R*ch]

  1. (* test/time.sml
  2.    PS 1995-03-23
  3. *)
  4.  
  5. use "auxil.sml";
  6.  
  7. local 
  8.     fun fib n = if n<2 then 1 else fib(n-1) + fib(n-2);
  9.     open Time
  10.     val bigt = fromSeconds 987654321 + fromMicroseconds 500012;
  11.     val litt = fromSeconds 454 + fromMicroseconds 501701
  12. in
  13.  
  14. val test1 = 
  15.     check'(fn _ => zeroTime + bigt = bigt andalso bigt - zeroTime = bigt);
  16.  
  17. val test2a = 
  18.     check'(fn _ => toSeconds zeroTime = 0
  19.        andalso zeroTime = fromSeconds 0
  20.        andalso zeroTime = fromMilliseconds 0
  21.        andalso zeroTime = fromMicroseconds 0);
  22. val test2b = 
  23.     check'(fn _ => toSeconds bigt = 987654321
  24.        andalso toSeconds litt = 454
  25.        andalso toMilliseconds litt = 454501
  26.        andalso toMicroseconds litt = 454501701);
  27. val test2c = (fromSeconds ~1 seq "WRONG")
  28.              handle Time => "OK" | _ => "WRONG";
  29. val test2d = (fromMilliseconds ~1 seq "WRONG")
  30.              handle Time => "OK" | _ => "WRONG";
  31. val test2e = (fromMicroseconds ~1 seq "WRONG")
  32.              handle Time => "OK" | _ => "WRONG";
  33.  
  34. val test3a = 
  35.     check'(fn _ => realToTime 0.0 = zeroTime
  36.        andalso realToTime 10.25 = fromSeconds 10 + fromMilliseconds 250);
  37. val test3b = (realToTime ~1.0 seq "WRONG")
  38.              handle Time => "OK" | _ => "WRONG";
  39. val test3c = (realToTime 1E300 seq "WRONG")
  40.              handle Time => "OK" | _ => "WRONG"; 
  41.  
  42. val test4a = 
  43.     check'(fn _ => timeToReal (realToTime 100.25) = 100.25);
  44.  
  45. val test6a = 
  46.     check'(fn _ => bigt + litt = litt + bigt
  47.        andalso (bigt + litt) - litt = bigt
  48.        andalso (bigt - litt) + litt = bigt);
  49.  
  50. val test7a = 
  51.     check'(fn _ => litt <= litt andalso litt >= litt
  52.        andalso zeroTime < litt andalso litt > zeroTime
  53.        andalso litt < bigt andalso bigt > litt
  54.        andalso not (litt > bigt) 
  55.        andalso not (bigt < litt) 
  56.        andalso not(litt < litt)
  57.        andalso not(litt > litt));
  58.  
  59. val test8a = 
  60.     check'(fn _ => now() <= now() 
  61.        andalso (now () before fib 27 seq ()) < now());
  62.  
  63. val test9a = 
  64.     check'(fn _ => fmt ~1 litt  = "455"
  65.        andalso fmt 0 litt = "455");
  66.  
  67. val test9b = 
  68.     check'(fn _ => fmt 1 litt = "454.5"
  69.        andalso fmt 2 litt = "454.50"
  70.        andalso fmt 3 litt = "454.502"
  71.        andalso fmt 4 litt = "454.5017"
  72.        andalso fmt 5 litt = "454.50170"
  73.        andalso fmt 6 litt = "454.501701");
  74.     
  75. fun chk (s, r) = 
  76.     check'(fn _ => 
  77.        case fromString s of
  78.            SOME res => res = fromMicroseconds r
  79.          | NONE     => false)
  80.  
  81. val test10a = 
  82.     List.map chk
  83.          [("189", 189000000),
  84.       ("189.1", 189100000),
  85.       ("189.125125", 189125125),
  86.       (".1", 100000),
  87.       (".125125", 125125),
  88.       (" \n\t189crap", 189000000),
  89.       (" \n\t189.1crap", 189100000),
  90.       (" \n\t189.125125crap", 189125125),
  91.       (" \n\t.1crap", 100000),
  92.       (" \n\t.125125crap", 125125)];
  93.  
  94. val test10b = 
  95.     List.map (fn s => case fromString s of NONE => "OK" | _ => "WRONG")
  96.          ["", "+189", "~189", "now", "Monday"];
  97. end
  98.