Commit ff3470b5 authored by POTTIER Francois's avatar POTTIER Francois

New demo [tst]. Add [dune-project] files.

parent b1f3c6ff
dune-project
_build
.merlin
fix.install
DEMOS := cfg cyk fib hco
DEMOS := tst cfg cyk fib hco
.PHONY: all clean test
......
.PHONY: all
all:
dune build Test.exe
.PHONY: test
test: all
_build/default/Test.exe
.PHONY: clean
clean:
rm -f *~
dune clean
(* Tests. *)
open Fix
(* -------------------------------------------------------------------------- *)
(* Test that [defensive_fix] detects cycles. *)
module M =
Memoize.ForType(Glue.INT)
(* We define a cyclic function where [f x] calls [f (x-1)] when [x] is positive
and [f 0] calls [f n] for some fixed [n]. *)
let test n =
let f =
M.defensive_fix (fun f x ->
if x = 0 then f n else f (x - 1) + 1
)
in
Printf.printf "Testing n = %d... %!" n;
let x = 2 * n in
match f x with
| y ->
Printf.printf "failure! f(%d) returns %d.\n%!" x y
| exception M.Cycle (zs, z) ->
Printf.printf "success! A cycle is detected:\n";
List.iter (fun z ->
Printf.printf "%d, " z
) zs;
Printf.printf "%d" z;
Printf.printf "\n%!"
(* Test several values of [n]. *)
let () =
test 0;
test 5;
test 10;
test 100;
()
(executable
(name Test)
(libraries fix)
(flags "-w" "A")
)
(lang dune 1.3)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment