aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2018-04-21 14:24:33 +0200
committerpacien2018-04-21 14:24:33 +0200
commit48b18b8e9fbaa38df427b3d435ab6f73c5da0db5 (patch)
tree9681760a78eda79f52c369610caa466a8c27bc54
parent3f25710a891dfcd17f597c16dfedf5499bc1bbd6 (diff)
downloadurm-48b18b8e9fbaa38df427b3d435ab6f73c5da0db5.tar.gz
Add test
-rw-r--r--.gitignore5
-rw-r--r--.merlin1
-rw-r--r--README.md18
-rw-r--r--main.ml1
-rw-r--r--makefile7
-rw-r--r--urm_test.ml58
6 files changed, 87 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index f7817ae..71dcd26 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,8 @@
10 10
11# ocamlbuild working directory 11# ocamlbuild working directory
12_build/ 12_build/
13._d/
14._ncdi/
13 15
14# ocamlbuild targets 16# ocamlbuild targets
15*.byte 17*.byte
@@ -18,3 +20,6 @@ _build/
18# oasis generated files 20# oasis generated files
19setup.data 21setup.data
20setup.log 22setup.log
23
24# binaries
25urm
diff --git a/.merlin b/.merlin
new file mode 100644
index 0000000..22dd628
--- /dev/null
+++ b/.merlin
@@ -0,0 +1 @@
PKG kaputt
diff --git a/README.md b/README.md
index 79d65fa..2971b4c 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,26 @@
2 2
3Unlimited Register Machine in OCaml. 3Unlimited Register Machine in OCaml.
4 4
5## Usage 5## Requirements
6
7* ocaml
8* GNU Make
9* [OCaml Makefile](https://mmottl.github.io/ocaml-makefile/)
10* [kaputt](http://kaputt.x9c.fr/)
11
12
13## Make targets
6 14
7* Requirements: ocaml, GNU Make, OCaml Makefile
8* Build: `make nc` produces a binary named `urm` 15* Build: `make nc` produces a binary named `urm`
16* Test: `make test`
9* Clean: `make clean` 17* Clean: `make clean`
10 18
11 19
20## Usage
21
22TODO: describe usage of the `urm` program.
23
24
12## Authors 25## Authors
13 26
14* Pacien TRAN-GIRARD 27* Pacien TRAN-GIRARD
@@ -18,3 +31,4 @@ Unlimited Register Machine in OCaml.
18## License 31## License
19 32
20Project distributed under the terms of the Creative Commons BY-NC-SA 3.0 license. 33Project distributed under the terms of the Creative Commons BY-NC-SA 3.0 license.
34
diff --git a/main.ml b/main.ml
index e85aeb2..1bb6704 100644
--- a/main.ml
+++ b/main.ml
@@ -8,3 +8,4 @@ open Parser
8open Instptr 8open Instptr
9open Reg 9open Reg
10open Urm 10open Urm
11
diff --git a/makefile b/makefile
index f027be5..2ccd250 100644
--- a/makefile
+++ b/makefile
@@ -1,11 +1,16 @@
1RESULT = urm 1RESULT = urm
2LIBS = str 2LIBS = str
3PACKS = kaputt
3SOURCES = \ 4SOURCES = \
4 common.ml \ 5 common.ml \
5 parser.mli parser.ml \ 6 parser.mli parser.ml \
6 instptr.mli instptr.ml \ 7 instptr.mli instptr.ml \
7 reg.mli reg.ml \ 8 reg.mli reg.ml \
8 urm.mli urm.ml 9 urm.mli urm.ml urm_test.ml
9 10
10OCAMLMAKEFILE = /usr/share/ocamlmakefile/OCamlMakefile 11OCAMLMAKEFILE = /usr/share/ocamlmakefile/OCamlMakefile
11include $(OCAMLMAKEFILE) 12include $(OCAMLMAKEFILE)
13
14test: nc
15 ./$(RESULT) run-tests
16
diff --git a/urm_test.ml b/urm_test.ml
new file mode 100644
index 0000000..b6018d0
--- /dev/null
+++ b/urm_test.ml
@@ -0,0 +1,58 @@
1(*
2 * UPEM / L3 / Functional programming / Project: URM
3 * Pacien TRAN-GIRARD, Adam NAILI
4 *)
5
6open Common
7open Instptr
8open Urm
9open Kaputt.Abbreviations
10
11let () =
12 Test.add_simple_test
13 ~title:"example_urm_add_program"
14 (fun () ->
15 let input_prgm = [
16 Zero 0;
17 Zero 3;
18 Jump (1, 3, 6);
19 Succ 0;
20 Succ 3;
21 Jump (3, 3, 2);
22 Zero 3;
23 Jump (2, 3, 11);
24 Succ 0;
25 Succ 3;
26 Jump (3, 3, 7)]
27 and input_regs = [
28 Reg (1, 2);
29 Reg (2, 3)]
30 and expected_urm = {
31 instptr = InstPtr ([], [
32 (0, Zero 0);
33 (1, Zero 3);
34 (2, Jump (1, 3, 6));
35 (3, Succ 0);
36 (4, Succ 3);
37 (5, Jump (3, 3, 2));
38 (6, Zero 3);
39 (7, Jump (2, 3, 11));
40 (8, Succ 0);
41 (9, Succ 3);
42 (10, Jump (3, 3, 7))]);
43 regs = [
44 Reg (1, 2);
45 Reg (2, 3)]}
46 and expected_output = [
47 Reg (0, 5);
48 Reg (1, 2);
49 Reg (2, 3);
50 Reg (3, 3)]
51 in let output_prgm = urm_mk input_prgm input_regs
52 in let output_regs = urm_run output_prgm
53 in
54 Assert.is_true (output_prgm = expected_urm);
55 Assert.is_true ((List.sort (fun (Reg(l, _)) (Reg(r, _)) -> compare l r) output_regs) = expected_output))
56
57let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests ()
58