From beae95b189cffa0bf08ae4a3b6734ea639ae5297 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Added tests of the Graphics module. --- .hgignore | 2 ++ ocaml/Makefile | 22 +++++++++++++++++----- ocaml/test3.ml | 12 ++++++++++++ ocaml/test4.ml | 24 ++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 ocaml/test3.ml create mode 100644 ocaml/test4.ml diff --git a/.hgignore b/.hgignore index 0eeb933..3b02a59 100644 --- a/.hgignore +++ b/.hgignore @@ -74,6 +74,8 @@ ocaml/ocaml-3.11.0+beta1.tar.bz2 ocaml/NUL ocaml/test1 ocaml/test2 +ocaml/test3 +ocaml/test4 ocaml/*.exe ocaml/*.cmi ocaml/*.cmx diff --git a/ocaml/Makefile b/ocaml/Makefile index 722f355..9cdd77e 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -1,19 +1,31 @@ # -*- Makefile -*- # Test programs for testing out the cross-compiler. -all: test1 test1.exe test2 test2.exe +all: test1 test1.exe test2 test2.exe test3 test3.exe test4 test4.exe test1: test1.ml ocamlopt $< -o $@ -test2: test2.ml - ocamlopt unix.cmxa $< -o $@ - test1.exe: test1.ml i686-pc-mingw32-ocamlopt $< -o $@ +test2: test2.ml + ocamlopt unix.cmxa $< -o $@ + test2.exe: test2.ml i686-pc-mingw32-ocamlopt unix.cmxa $< -o $@ +test3: test3.ml + ocamlopt graphics.cmxa $< -o $@ + +test3.exe: test3.ml + i686-pc-mingw32-ocamlopt graphics.cmxa $< -o $@ + +test4: test4.ml + ocamlopt graphics.cmxa $< -o $@ + +test4.exe: test4.ml + i686-pc-mingw32-ocamlopt graphics.cmxa $< -o $@ + clean: - rm -f test1 test2 *.exe *.cmi *.cmx *.o + rm -f test1 test2 test3 test4 *.exe *.cmi *.cmx *.o diff --git a/ocaml/test3.ml b/ocaml/test3.ml new file mode 100644 index 0000000..4d8b5e8 --- /dev/null +++ b/ocaml/test3.ml @@ -0,0 +1,12 @@ +(* From: http://www.ocaml-tutorial.org/the_structure_of_ocaml_programs *) + +open Graphics;; + +let () = + open_graph " 640x480"; + for i = 12 downto 1 do + let radius = i * 20 in + set_color (if (i mod 2) = 0 then red else yellow); + fill_circle 320 240 radius + done; + ignore (read_line ()) diff --git a/ocaml/test4.ml b/ocaml/test4.ml new file mode 100644 index 0000000..aef535b --- /dev/null +++ b/ocaml/test4.ml @@ -0,0 +1,24 @@ +(* From: http://www.ocaml-tutorial.org/the_structure_of_ocaml_programs *) + +let () = + Random.self_init (); + Graphics.open_graph " 640x480"; + + let rec iterate r x_init i = + if i = 1 then x_init + else + let x = iterate r x_init (i-1) in + r *. x *. (1.0 -. x) + in + + for x = 0 to 639 do + let r = 4.0 *. (float_of_int x) /. 640.0 in + for i = 0 to 39 do + let x_init = Random.float 1.0 in + let x_final = iterate r x_init 500 in + let y = int_of_float (x_final *. 480.) in + Graphics.plot x y + done + done; + + ignore (read_line ()) -- 1.8.3.1