From 6adad1cb81e7780b856c612ec7f65bb42e97e667 Mon Sep 17 00:00:00 2001
From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr>
Date: Mon, 3 Jul 2023 16:24:23 +0200
Subject: [PATCH] test: add a Sierpinski triangle generation based on cellular
 automata

---
 test/Makefile                  |  3 +++
 test/Makefile.inc              |  5 ++++-
 test/sierpinski/Makefile       | 25 +++++++++++++++++++++++++
 test/sierpinski/Makefile.dot   |  1 +
 test/sierpinski/Makefile.inc   |  1 +
 test/sierpinski/config.ml      |  5 +++++
 test/sierpinski/dune           |  1 +
 test/sierpinski/dune-project   |  1 +
 test/sierpinski/dune-workspace |  0
 test/sierpinski/p.ml           | 34 ++++++++++++++++++++++++++++++++++
 test/sierpinski/ring.dot       | 11 +++++++++++
 test/sierpinski/state.ml       |  6 ++++++
 12 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 test/sierpinski/Makefile
 create mode 120000 test/sierpinski/Makefile.dot
 create mode 120000 test/sierpinski/Makefile.inc
 create mode 100644 test/sierpinski/config.ml
 create mode 120000 test/sierpinski/dune
 create mode 120000 test/sierpinski/dune-project
 create mode 100644 test/sierpinski/dune-workspace
 create mode 100644 test/sierpinski/p.ml
 create mode 100644 test/sierpinski/ring.dot
 create mode 100644 test/sierpinski/state.ml

diff --git a/test/Makefile b/test/Makefile
index f312b03d..bb1a0525 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -19,6 +19,7 @@ test:
 	cd toy-example-a5sf/ && make test
 	cd k-clustering/ && make test
 	cd ghosh/ && make test
+	cd sierpinski/ && make test
 	echo "Every test went fine!"
 
 clean:
@@ -42,6 +43,7 @@ clean:
 	cd toy-example-a5sf/ && make clean
 	cd k-clustering/ && make clean
 	cd ghosh/ && make clean
+	cd sierpinski/ && make clean
 
 utest:
 	cd skeleton/ &&	make test
@@ -63,5 +65,6 @@ utest:
 	cd toy-example-a5sf/ && make utest
 	cd k-clustering/ && make utest
 	cd ghosh/ && make utest
+	cd sierpinski/ && make utest
 
 -include Makefile.untracked
diff --git a/test/Makefile.inc b/test/Makefile.inc
index 0924984d..e837d615 100644
--- a/test/Makefile.inc
+++ b/test/Makefile.inc
@@ -1,4 +1,4 @@
-# Time-stamp: <modified the 27/02/2023 (at 16:05) by Erwan Jahier>
+# Time-stamp: <modified the 30/06/2023 (at 17:41) by Erwan Jahier>
 #
 # Define some default rules that ought to work most of the time
 #
@@ -112,3 +112,6 @@ endif
 
 %.rdbgui: %.cma
 	ledit -h rdbg-history -x rdbgui4sasa -sut "sasa $*.dot"  -l 10000
+
+%.simu:
+	make $*.rdbgui4sasa
diff --git a/test/sierpinski/Makefile b/test/sierpinski/Makefile
new file mode 100644
index 00000000..3f567b25
--- /dev/null
+++ b/test/sierpinski/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/sierpinski/Makefile.dot b/test/sierpinski/Makefile.dot
new file mode 120000
index 00000000..618c8ab0
--- /dev/null
+++ b/test/sierpinski/Makefile.dot
@@ -0,0 +1 @@
+../Makefile.dot
\ No newline at end of file
diff --git a/test/sierpinski/Makefile.inc b/test/sierpinski/Makefile.inc
new file mode 120000
index 00000000..b9a83c9d
--- /dev/null
+++ b/test/sierpinski/Makefile.inc
@@ -0,0 +1 @@
+../Makefile.inc
\ No newline at end of file
diff --git a/test/sierpinski/config.ml b/test/sierpinski/config.ml
new file mode 100644
index 00000000..1e0e05f1
--- /dev/null
+++ b/test/sierpinski/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/sierpinski/dune b/test/sierpinski/dune
new file mode 120000
index 00000000..5cb715b8
--- /dev/null
+++ b/test/sierpinski/dune
@@ -0,0 +1 @@
+../dune2copy
\ No newline at end of file
diff --git a/test/sierpinski/dune-project b/test/sierpinski/dune-project
new file mode 120000
index 00000000..1c5c1f50
--- /dev/null
+++ b/test/sierpinski/dune-project
@@ -0,0 +1 @@
+../dune-project2copy
\ No newline at end of file
diff --git a/test/sierpinski/dune-workspace b/test/sierpinski/dune-workspace
new file mode 100644
index 00000000..e69de29b
diff --git a/test/sierpinski/p.ml b/test/sierpinski/p.ml
new file mode 100644
index 00000000..bc5f0be1
--- /dev/null
+++ b/test/sierpinski/p.ml
@@ -0,0 +1,34 @@
+(* Time-stamp: <modified the 03/07/2023 (at 16:19) by Erwan Jahier> *)
+
+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/sierpinski/ring.dot b/test/sierpinski/ring.dot
new file mode 100644
index 00000000..bacf56c5
--- /dev/null
+++ b/test/sierpinski/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/sierpinski/state.ml b/test/sierpinski/state.ml
new file mode 100644
index 00000000..3a8ddee9
--- /dev/null
+++ b/test/sierpinski/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