aboutsummaryrefslogtreecommitdiff
path: root/urm_test.ml
diff options
context:
space:
mode:
Diffstat (limited to 'urm_test.ml')
-rw-r--r--urm_test.ml58
1 files changed, 58 insertions, 0 deletions
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