aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2018-04-21 15:01:36 +0200
committerpacien2018-04-21 15:01:36 +0200
commit153df26a972405c11968f7833190346bc69e07ec (patch)
treee8c060859c5ceb1af6a3313979a9ca001295cf17
parent1b8fa63e3145a3778e065c42e9fc189344985c99 (diff)
downloadurm-153df26a972405c11968f7833190346bc69e07ec.tar.gz
Add EURM conv test
-rw-r--r--eurml_test.ml75
1 files changed, 75 insertions, 0 deletions
diff --git a/eurml_test.ml b/eurml_test.ml
new file mode 100644
index 0000000..7dc6e5e
--- /dev/null
+++ b/eurml_test.ml
@@ -0,0 +1,75 @@
1(*
2 * UPEM / L3 / Functional programming / Project: URM
3 * Pacien TRAN-GIRARD, Adam NAILI
4 *)
5
6open Common
7open Urm
8open Eurm
9open Kaputt.Abbreviations
10
11let () =
12 Test.add_simple_test
13 ~title:"example_eurm_factorial_conversion"
14 (fun () ->
15 let input_eurm = [
16 Comment "Compute r1! and place the result in r1";
17 ZeroPredicate (1, "r1=0");
18 Goto "r1>0";
19 Comment "r1 holds 0";
20 Label "r1=0";
21 Inc 1;
22 Goto "done";
23 Comment "r1 holds a positive integer";
24 Label "r1>0";
25 Copy (2, 1);
26 Zero 1;
27 Inc 1;
28 Zero 3;
29 Inc 3;
30 Comment "main loop";
31 Label "loop";
32 Mult (1, 3);
33 EqPredicate (2, 3, "done");
34 Inc 3;
35 Goto "loop";
36 Label "done";
37 Quit]
38 and expected_urm = [
39 URMZero 4;
40 URMJump (1, 4, 4);
41 URMZero 8;
42 URMJump (8, 8, 7);
43 URMSucc 1;
44 URMZero 9;
45 URMJump (9, 9, 29);
46 URMCopy (2, 1);
47 URMZero 1;
48 URMSucc 1;
49 URMZero 3;
50 URMSucc 3;
51 URMCopy (5, 1);
52 URMZero 1;
53 URMZero 6;
54 URMJump (3, 6, 25);
55 URMZero 7;
56 URMJump (5, 7, 22);
57 URMSucc 1;
58 URMSucc 7;
59 URMZero 10;
60 URMJump (10, 10, 17);
61 URMSucc 6;
62 URMZero 11;
63 URMJump (11, 11, 15);
64 URMJump (2, 3, 29);
65 URMSucc 3;
66 URMZero 12;
67 URMJump (12, 12, 12);
68 URMZero 13;
69 URMJump (13, 13, 38)]
70 in let output_urm = urm_from_eurm input_eurm
71 in
72 Assert.is_true (output_urm = expected_urm))
73
74let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests ()
75