diff options
Diffstat (limited to 'urm_test.ml')
-rw-r--r-- | urm_test.ml | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/urm_test.ml b/urm_test.ml deleted file mode 100644 index f223bf6..0000000 --- a/urm_test.ml +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
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 Reg | ||
10 | open Kaputt.Abbreviations | ||
11 | |||
12 | let () = | ||
13 | Test.add_simple_test | ||
14 | ~title:"example_urm_add_program" | ||
15 | (fun () -> | ||
16 | let input_prgm = [ | ||
17 | Zero 0; | ||
18 | Zero 3; | ||
19 | Jump (1, 3, 6); | ||
20 | Succ 0; | ||
21 | Succ 3; | ||
22 | Jump (3, 3, 2); | ||
23 | Zero 3; | ||
24 | Jump (2, 3, 11); | ||
25 | Succ 0; | ||
26 | Succ 3; | ||
27 | Jump (3, 3, 7)] | ||
28 | and input_regs = [ | ||
29 | Reg (1, 2); | ||
30 | Reg (2, 3)] | ||
31 | and expected_urm = { | ||
32 | instptr = InstPtr ([], [ | ||
33 | (0, Zero 0); | ||
34 | (1, Zero 3); | ||
35 | (2, Jump (1, 3, 6)); | ||
36 | (3, Succ 0); | ||
37 | (4, Succ 3); | ||
38 | (5, Jump (3, 3, 2)); | ||
39 | (6, Zero 3); | ||
40 | (7, Jump (2, 3, 11)); | ||
41 | (8, Succ 0); | ||
42 | (9, Succ 3); | ||
43 | (10, Jump (3, 3, 7))]); | ||
44 | regs = [ | ||
45 | Reg (1, 2); | ||
46 | Reg (2, 3)]} | ||
47 | and expected_output = [ | ||
48 | Reg (0, 5); | ||
49 | Reg (1, 2); | ||
50 | Reg (2, 3); | ||
51 | Reg (3, 3)] | ||
52 | in let output_prgm = urm_mk input_prgm input_regs | ||
53 | in let output_regs = urm_run output_prgm | ||
54 | in | ||
55 | Assert.is_true (output_prgm = expected_urm); | ||
56 | Assert.is_true ((regs_sort output_regs) = expected_output)) | ||
57 | |||
58 | let () = | ||
59 | Test.add_simple_test | ||
60 | ~title:"example_urm_factorial_program" | ||
61 | (fun () -> | ||
62 | let input_prgm = [ | ||
63 | Zero 4; | ||
64 | Jump (1, 4, 4); | ||
65 | Zero 8; | ||
66 | Jump (8, 8, 7); | ||
67 | Succ 1; | ||
68 | Zero 9; | ||
69 | Jump (9, 9, 29); | ||
70 | Copy (2, 1); | ||
71 | Zero 1; | ||
72 | Succ 1; | ||
73 | Zero 3; | ||
74 | Succ 3; | ||
75 | Copy (5, 1); | ||
76 | Zero 1; | ||
77 | Zero 6; | ||
78 | Jump (3, 6, 25); | ||
79 | Zero 7; | ||
80 | Jump (5, 7, 22); | ||
81 | Succ 1; | ||
82 | Succ 7; | ||
83 | Zero 10; | ||
84 | Jump (10, 10, 17); | ||
85 | Succ 6; | ||
86 | Zero 11; | ||
87 | Jump (11, 11, 15); | ||
88 | Jump (2, 3, 29); | ||
89 | Succ 3; | ||
90 | Zero 12; | ||
91 | Jump (12, 12, 12); | ||
92 | Zero 13; | ||
93 | Jump (13, 13, 38)] | ||
94 | and input_regs = [ | ||
95 | Reg (1, 5)] | ||
96 | and expected_urm = { | ||
97 | instptr = InstPtr ([], [ | ||
98 | (0, Zero 4); | ||
99 | (1, Jump (1, 4, 4)); | ||
100 | (2, Zero 8); | ||
101 | (3, Jump (8, 8, 7)); | ||
102 | (4, Succ 1); | ||
103 | (5, Zero 9); | ||
104 | (6, Jump (9, 9, 29)); | ||
105 | (7, Copy (2, 1)); | ||
106 | (8, Zero 1); | ||
107 | (9, Succ 1); | ||
108 | (10, Zero 3); | ||
109 | (11, Succ 3); | ||
110 | (12, Copy (5, 1)); | ||
111 | (13, Zero 1); | ||
112 | (14, Zero 6); | ||
113 | (15, Jump (3, 6, 25)); | ||
114 | (16, Zero 7); | ||
115 | (17, Jump (5, 7, 22)); | ||
116 | (18, Succ 1); | ||
117 | (19, Succ 7); | ||
118 | (20, Zero 10); | ||
119 | (21, Jump (10, 10, 17)); | ||
120 | (22, Succ 6); | ||
121 | (23, Zero 11); | ||
122 | (24, Jump (11, 11, 15)); | ||
123 | (25, Jump (2, 3, 29)); | ||
124 | (26, Succ 3); | ||
125 | (27, Zero 12); | ||
126 | (28, Jump (12, 12, 12)); | ||
127 | (29, Zero 13); | ||
128 | (30, Jump (13, 13, 38))]); | ||
129 | regs = [ | ||
130 | Reg (1, 5)]} | ||
131 | and expected_output = [ | ||
132 | Reg (1, 120); | ||
133 | Reg (2, 5); | ||
134 | Reg (3, 5); | ||
135 | Reg (4, 0); | ||
136 | Reg (5, 24); | ||
137 | Reg (6, 5); | ||
138 | Reg (7, 24); | ||
139 | Reg (8, 0); | ||
140 | Reg (10, 0); | ||
141 | Reg (11, 0); | ||
142 | Reg (12, 0); | ||
143 | Reg (13, 0)] | ||
144 | in let output_prgm = urm_mk input_prgm input_regs | ||
145 | in let output_regs = urm_run output_prgm | ||
146 | in | ||
147 | Assert.is_true (output_prgm = expected_urm); | ||
148 | Assert.is_true ((regs_sort output_regs) = expected_output)) | ||
149 | |||
150 | let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () | ||
151 | |||