diff options
author | pacien | 2018-04-29 20:41:39 +0200 |
---|---|---|
committer | pacien | 2018-04-29 20:41:39 +0200 |
commit | 97a5d3600a06e2edbd6bb6faa6fa0728add0d5d3 (patch) | |
tree | a859ae11723730440de10569a2d4081e13ceab49 /src/eurm_test.ml | |
parent | 0647f37eebbefb8446fc8abfc533a23952fbb8be (diff) | |
download | urm-97a5d3600a06e2edbd6bb6faa6fa0728add0d5d3.tar.gz |
Rename URM types and fix urm_from_eurm signature
Diffstat (limited to 'src/eurm_test.ml')
-rw-r--r-- | src/eurm_test.ml | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/eurm_test.ml b/src/eurm_test.ml new file mode 100644 index 0000000..afecf9e --- /dev/null +++ b/src/eurm_test.ml | |||
@@ -0,0 +1,74 @@ | |||
1 | (* | ||
2 | * UPEM / L3 / Functional programming / Project: URM | ||
3 | * Pacien TRAN-GIRARD, Adam NAILI | ||
4 | *) | ||
5 | |||
6 | open Common | ||
7 | open Urm | ||
8 | open Eurm | ||
9 | open Kaputt.Abbreviations | ||
10 | |||
11 | let () = | ||
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 | |||
74 | let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () | ||