From 48b18b8e9fbaa38df427b3d435ab6f73c5da0db5 Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 21 Apr 2018 14:24:33 +0200 Subject: Add test --- .gitignore | 5 +++++ .merlin | 1 + README.md | 18 ++++++++++++++++-- main.ml | 1 + makefile | 7 ++++++- urm_test.ml | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 .merlin create mode 100644 urm_test.ml diff --git a/.gitignore b/.gitignore index f7817ae..71dcd26 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ # ocamlbuild working directory _build/ +._d/ +._ncdi/ # ocamlbuild targets *.byte @@ -18,3 +20,6 @@ _build/ # oasis generated files setup.data setup.log + +# binaries +urm 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 @@ Unlimited Register Machine in OCaml. -## Usage +## Requirements + +* ocaml +* GNU Make +* [OCaml Makefile](https://mmottl.github.io/ocaml-makefile/) +* [kaputt](http://kaputt.x9c.fr/) + + +## Make targets -* Requirements: ocaml, GNU Make, OCaml Makefile * Build: `make nc` produces a binary named `urm` +* Test: `make test` * Clean: `make clean` +## Usage + +TODO: describe usage of the `urm` program. + + ## Authors * Pacien TRAN-GIRARD @@ -18,3 +31,4 @@ Unlimited Register Machine in OCaml. ## License Project distributed under the terms of the Creative Commons BY-NC-SA 3.0 license. + diff --git a/main.ml b/main.ml index e85aeb2..1bb6704 100644 --- a/main.ml +++ b/main.ml @@ -8,3 +8,4 @@ open Parser open Instptr open Reg open Urm + diff --git a/makefile b/makefile index f027be5..2ccd250 100644 --- a/makefile +++ b/makefile @@ -1,11 +1,16 @@ RESULT = urm LIBS = str +PACKS = kaputt SOURCES = \ common.ml \ parser.mli parser.ml \ instptr.mli instptr.ml \ reg.mli reg.ml \ - urm.mli urm.ml + urm.mli urm.ml urm_test.ml OCAMLMAKEFILE = /usr/share/ocamlmakefile/OCamlMakefile include $(OCAMLMAKEFILE) + +test: nc + ./$(RESULT) run-tests + 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 @@ +(* + * UPEM / L3 / Functional programming / Project: URM + * Pacien TRAN-GIRARD, Adam NAILI + *) + +open Common +open Instptr +open Urm +open Kaputt.Abbreviations + +let () = + Test.add_simple_test + ~title:"example_urm_add_program" + (fun () -> + let input_prgm = [ + Zero 0; + Zero 3; + Jump (1, 3, 6); + Succ 0; + Succ 3; + Jump (3, 3, 2); + Zero 3; + Jump (2, 3, 11); + Succ 0; + Succ 3; + Jump (3, 3, 7)] + and input_regs = [ + Reg (1, 2); + Reg (2, 3)] + and expected_urm = { + instptr = InstPtr ([], [ + (0, Zero 0); + (1, Zero 3); + (2, Jump (1, 3, 6)); + (3, Succ 0); + (4, Succ 3); + (5, Jump (3, 3, 2)); + (6, Zero 3); + (7, Jump (2, 3, 11)); + (8, Succ 0); + (9, Succ 3); + (10, Jump (3, 3, 7))]); + regs = [ + Reg (1, 2); + Reg (2, 3)]} + and expected_output = [ + Reg (0, 5); + Reg (1, 2); + Reg (2, 3); + Reg (3, 3)] + in let output_prgm = urm_mk input_prgm input_regs + in let output_regs = urm_run output_prgm + in + Assert.is_true (output_prgm = expected_urm); + Assert.is_true ((List.sort (fun (Reg(l, _)) (Reg(r, _)) -> compare l r) output_regs) = expected_output)) + +let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () + -- cgit v1.2.3