diff options
author | pacien | 2018-04-21 14:24:33 +0200 |
---|---|---|
committer | pacien | 2018-04-21 14:24:33 +0200 |
commit | 48b18b8e9fbaa38df427b3d435ab6f73c5da0db5 (patch) | |
tree | 9681760a78eda79f52c369610caa466a8c27bc54 | |
parent | 3f25710a891dfcd17f597c16dfedf5499bc1bbd6 (diff) | |
download | urm-48b18b8e9fbaa38df427b3d435ab6f73c5da0db5.tar.gz |
Add test
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | .merlin | 1 | ||||
-rw-r--r-- | README.md | 18 | ||||
-rw-r--r-- | main.ml | 1 | ||||
-rw-r--r-- | makefile | 7 | ||||
-rw-r--r-- | urm_test.ml | 58 |
6 files changed, 87 insertions, 3 deletions
@@ -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 |
19 | setup.data | 21 | setup.data |
20 | setup.log | 22 | setup.log |
23 | |||
24 | # binaries | ||
25 | urm | ||
@@ -0,0 +1 @@ | |||
PKG kaputt | |||
@@ -2,13 +2,26 @@ | |||
2 | 2 | ||
3 | Unlimited Register Machine in OCaml. | 3 | Unlimited 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 | |||
22 | TODO: 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 | ||
20 | Project distributed under the terms of the Creative Commons BY-NC-SA 3.0 license. | 33 | Project distributed under the terms of the Creative Commons BY-NC-SA 3.0 license. |
34 | |||
@@ -8,3 +8,4 @@ open Parser | |||
8 | open Instptr | 8 | open Instptr |
9 | open Reg | 9 | open Reg |
10 | open Urm | 10 | open Urm |
11 | |||
@@ -1,11 +1,16 @@ | |||
1 | RESULT = urm | 1 | RESULT = urm |
2 | LIBS = str | 2 | LIBS = str |
3 | PACKS = kaputt | ||
3 | SOURCES = \ | 4 | SOURCES = \ |
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 | ||
10 | OCAMLMAKEFILE = /usr/share/ocamlmakefile/OCamlMakefile | 11 | OCAMLMAKEFILE = /usr/share/ocamlmakefile/OCamlMakefile |
11 | include $(OCAMLMAKEFILE) | 12 | include $(OCAMLMAKEFILE) |
13 | |||
14 | test: 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 | |||
6 | open Common | ||
7 | open Instptr | ||
8 | open Urm | ||
9 | open Kaputt.Abbreviations | ||
10 | |||
11 | let () = | ||
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 | |||
57 | let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () | ||
58 | |||