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