File: Test110.ML

package info (click to toggle)
polyml 5.6-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,892 kB
  • ctags: 34,453
  • sloc: cpp: 44,983; ansic: 24,520; asm: 14,850; sh: 11,730; makefile: 551; exp: 484; python: 253; awk: 91; sed: 9
file content (38 lines) | stat: -rw-r--r-- 889 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(* Check integer conversion. *)

fun verifyBase radix n =
    valOf(StringCvt.scanString (Int.scan radix)(Int.fmt radix n)) = n

fun verify n =
    if verifyBase StringCvt.DEC n andalso verifyBase StringCvt.HEX n andalso
       verifyBase StringCvt.OCT n andalso verifyBase StringCvt.BIN n
    then () else raise Fail "failed";

(* Random number generator.  From Isabelle. *)

local
    fun rmod x y = x - y * Real.realFloor (x / y);
    val a = 16807.0;
    val m = 2147483647.0;
    val random_seed = ref 1.0;
in

    fun random () =
    let
        val r = rmod (a * ! random_seed) m
    in
        random_seed := r;
        Real.floor r
    end
end;

fun doFor f 0 = () | doFor f n = (f(); doFor f (n-1));

verify 0;
verify 1;
verify ~1;
verify 100000000000000000000000;
verify 100000000000000000000001;
verify 9051234567;

doFor(fn () => (verify(random()); verify(~(random())))) 100;