From 4c94d4ddcfe54f58edda638f893381cbec87d73d Mon Sep 17 00:00:00 2001 From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr> Date: Mon, 10 Jul 2023 12:01:04 +0200 Subject: [PATCH] test: (re-) add the wolfram-cellular-automaton (was sierpinski) --- test/wolfram-cellular-automaton/Makefile | 25 ++++++++++++ test/wolfram-cellular-automaton/Makefile.dot | 1 + test/wolfram-cellular-automaton/Makefile.inc | 1 + test/wolfram-cellular-automaton/config.ml | 5 +++ test/wolfram-cellular-automaton/dune | 1 + test/wolfram-cellular-automaton/dune-project | 1 + .../wolfram-cellular-automaton/dune-workspace | 0 test/wolfram-cellular-automaton/p.ml | 39 +++++++++++++++++++ test/wolfram-cellular-automaton/ring.dot | 11 ++++++ test/wolfram-cellular-automaton/some_session | 7 ++++ test/wolfram-cellular-automaton/state.ml | 6 +++ 11 files changed, 97 insertions(+) create mode 100644 test/wolfram-cellular-automaton/Makefile create mode 120000 test/wolfram-cellular-automaton/Makefile.dot create mode 120000 test/wolfram-cellular-automaton/Makefile.inc create mode 100644 test/wolfram-cellular-automaton/config.ml create mode 120000 test/wolfram-cellular-automaton/dune create mode 120000 test/wolfram-cellular-automaton/dune-project create mode 100644 test/wolfram-cellular-automaton/dune-workspace create mode 100644 test/wolfram-cellular-automaton/p.ml create mode 100644 test/wolfram-cellular-automaton/ring.dot create mode 100644 test/wolfram-cellular-automaton/some_session create mode 100644 test/wolfram-cellular-automaton/state.ml diff --git a/test/wolfram-cellular-automaton/Makefile b/test/wolfram-cellular-automaton/Makefile new file mode 100644 index 00000000..3f567b25 --- /dev/null +++ b/test/wolfram-cellular-automaton/Makefile @@ -0,0 +1,25 @@ +# Time-stamp: <modified the 03/07/2023 (at 16:22) by Erwan Jahier> + +DECO_PATTERN="0-:p.ml" +-include ./Makefile.dot +-include ./Makefile.inc + +############################################################################## +# Non-regression tests + +test: chain10.gm_test chain10.rdbg-test demo50 clean + +# update golden-master tests (if necessary) +utest: + make chain10.ugm_test || echo "chain10 ok" + +# usage: make demo50 +demo%: + make chain$*.dot + sasa chain$*.dot --synchronous-daemon --length $(shell echo $$(( $* / 2 ))) \ + | grep outs | cut -d ' ' -f 2-$* \ + | sed -e "s/ //g" | sed -e "s/f/ /g" | sed -e "s/t/â–²/g" + + +clean: genclean + rm -f chain* diff --git a/test/wolfram-cellular-automaton/Makefile.dot b/test/wolfram-cellular-automaton/Makefile.dot new file mode 120000 index 00000000..618c8ab0 --- /dev/null +++ b/test/wolfram-cellular-automaton/Makefile.dot @@ -0,0 +1 @@ +../Makefile.dot \ No newline at end of file diff --git a/test/wolfram-cellular-automaton/Makefile.inc b/test/wolfram-cellular-automaton/Makefile.inc new file mode 120000 index 00000000..b9a83c9d --- /dev/null +++ b/test/wolfram-cellular-automaton/Makefile.inc @@ -0,0 +1 @@ +../Makefile.inc \ No newline at end of file diff --git a/test/wolfram-cellular-automaton/config.ml b/test/wolfram-cellular-automaton/config.ml new file mode 100644 index 00000000..1e0e05f1 --- /dev/null +++ b/test/wolfram-cellular-automaton/config.ml @@ -0,0 +1,5 @@ + +let potential = None (* None => only -sd, -cd, -lcd, -dd, or -custd are possible *) +let legitimate = None (* None => only silent configuration are legitimate *) +let fault = None (* None => the simulation stop once a legitimate configuration is reached *) +let init_search_utils = None (* To provide to use --init-search *) diff --git a/test/wolfram-cellular-automaton/dune b/test/wolfram-cellular-automaton/dune new file mode 120000 index 00000000..5cb715b8 --- /dev/null +++ b/test/wolfram-cellular-automaton/dune @@ -0,0 +1 @@ +../dune2copy \ No newline at end of file diff --git a/test/wolfram-cellular-automaton/dune-project b/test/wolfram-cellular-automaton/dune-project new file mode 120000 index 00000000..1c5c1f50 --- /dev/null +++ b/test/wolfram-cellular-automaton/dune-project @@ -0,0 +1 @@ +../dune-project2copy \ No newline at end of file diff --git a/test/wolfram-cellular-automaton/dune-workspace b/test/wolfram-cellular-automaton/dune-workspace new file mode 100644 index 00000000..e69de29b diff --git a/test/wolfram-cellular-automaton/p.ml b/test/wolfram-cellular-automaton/p.ml new file mode 100644 index 00000000..5fa45cef --- /dev/null +++ b/test/wolfram-cellular-automaton/p.ml @@ -0,0 +1,39 @@ +(* Time-stamp: <modified the 10/07/2023 (at 11:36) by Erwan Jahier> *) + +(* Draw the Sierpinski triangle using Wolfram cellular automata + +https://mathworld.wolfram.com/ElementaryCellularAutomaton.html +*) + +let rule_nb = 126 (* Sierpinski rule *) +let _ = assert( 0 <= rule_nb && rule_nb <256 ) + +let rec to_bool_list n = if n = 0 then [] else (n mod 2 = 1)::(to_bool_list (n/2)) +let to_array l = + let a = Array.make 8 false in + let ll = List.length l in + List.iteri (fun i b -> a.(i+8-ll) <- b) l; a + +let rule_nb_array = rule_nb |> to_bool_list |> List.rev |> to_array + +(* For each rule, the next value (of x2) depends its value and the ones of its 2 neighbors *) +let b2i b = if b then 1 else 0 +let next x1 x2 x3 = + let index = 7 - ((b2i x1)*4 + (b2i x2)*2 + b2i x3) in + (* Printf.printf "index=%d\n%!" index; *) + rule_nb_array.(index) + +let cpt = ref 0 +let init_state _ _ = + cpt := (!cpt+1) mod Algo.card(); + let res = !cpt = Algo.card() / 2 in (* one cell is true, in the middle *) + (* Printf.printf "cell(%d)=%b\n%!" !cpt res; *) + res + + +let enable_f x2 nl = + match List.map Algo.state nl with + | [x1; x3] -> if next x1 x2 x3 = not x2 then ["flip"] else [] + | _ -> [] + +let step_f x _ _ = not x diff --git a/test/wolfram-cellular-automaton/ring.dot b/test/wolfram-cellular-automaton/ring.dot new file mode 100644 index 00000000..bacf56c5 --- /dev/null +++ b/test/wolfram-cellular-automaton/ring.dot @@ -0,0 +1,11 @@ +graph ring { + p1 [algo="p.ml"] + p2 [algo="p.ml"] + p3 [algo="p.ml"] + p4 [algo="p.ml"] + p5 [algo="p.ml"] + p6 [algo="p.ml"] + p7 [algo="p.ml"] + + p1 -- p2 -- p3 -- p4 -- p5 -- p6 -- p7 -- p1 +} diff --git a/test/wolfram-cellular-automaton/some_session b/test/wolfram-cellular-automaton/some_session new file mode 100644 index 00000000..96b69b57 --- /dev/null +++ b/test/wolfram-cellular-automaton/some_session @@ -0,0 +1,7 @@ +n +n +n +n +wait 3 +print_event !e;; + diff --git a/test/wolfram-cellular-automaton/state.ml b/test/wolfram-cellular-automaton/state.ml new file mode 100644 index 00000000..3a8ddee9 --- /dev/null +++ b/test/wolfram-cellular-automaton/state.ml @@ -0,0 +1,6 @@ + +type t = bool +let to_string = (fun s -> Printf.sprintf "%B" s) +let of_string = Some bool_of_string +let copy x = x +let actions = ["flip"] -- GitLab