aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpacien2018-05-01 01:29:33 +0200
committerpacien2018-05-01 01:29:33 +0200
commit2706214e1f9ba8c62cea26055dcc9aa46fcd0c3d (patch)
tree7c23f6a87434288bd88cdb7b7eadc867c9443281 /src
parent58e4fa622c441a9b832f0656580204a9f5b23e1d (diff)
downloadurm-2706214e1f9ba8c62cea26055dcc9aa46fcd0c3d.tar.gz
Add new tests
Diffstat (limited to 'src')
-rw-r--r--src/eurm_test.ml94
-rw-r--r--src/main.mli6
-rw-r--r--src/makefile7
-rw-r--r--src/urm_test.ml160
4 files changed, 69 insertions, 198 deletions
diff --git a/src/eurm_test.ml b/src/eurm_test.ml
index a3ef5a8..a86a1b2 100644
--- a/src/eurm_test.ml
+++ b/src/eurm_test.ml
@@ -4,73 +4,43 @@
4 *) 4 *)
5 5
6open Common 6open Common
7open Main
8open Parser
7open Urm 9open Urm
8open Eurm 10open Eurm
9open Kaputt.Abbreviations 11open Reg
12open Kaputt
13
14let run_eurm_prgm filename regs =
15 let prgm = read_prgm (fun f -> eurm_program_of_lex f |> urm_from_eurm) filename
16 in urm_mk prgm regs |> urm_run
17
18let () =
19 Test.add_simple_test
20 ~title:"example_eurm_add"
21 (fun () ->
22 let output = run_eurm_prgm "../examples/add.eurm" [Reg(1, 5); Reg(2, 3)]
23 in Assertion.equal (regs_get output 1) (5 + 3))
24
25(*let () =
26 Test.add_simple_test
27 ~title:"example_eurm_factorial"
28 (fun () ->
29 let output = run_eurm_prgm "../examples/factorial.eurm" [Reg(1, 5)]
30 in Assertion.equal (regs_get output 1) 120)
31*)
32let () =
33 Test.add_simple_test
34 ~title:"example_eurm_sum_first_integers"
35 (fun () ->
36 let output = run_eurm_prgm "../examples/sum-first-integers.eurm" [Reg(1, 51)]
37 in Assertion.equal (regs_get output 1) (51*(51+1)/2))
10 38
11(*
12let () = 39let () =
13 Test.add_simple_test 40 Test.add_simple_test
14 ~title:"example_eurm_factorial_conversion" 41 ~title:"example_eurm_sum_first_odd_integers"
15 (fun () -> 42 (fun () ->
16 let input_eurm = [ 43 let output = run_eurm_prgm "../examples/sum-first-odd-integers.eurm" [Reg(1, 51)]
17 Comment "Compute r1! and place the result in r1"; 44 in Assertion.equal (regs_get output 1) 676)
18 ZeroPredicate (1, "r1=0");
19 Goto "r1>0";
20 Comment "r1 holds 0";
21 Label "r1=0";
22 Inc 1;
23 Goto "done";
24 Comment "r1 holds a positive integer";
25 Label "r1>0";
26 Copy (2, 1);
27 Zero 1;
28 Inc 1;
29 Zero 3;
30 Inc 3;
31 Comment "main loop";
32 Label "loop";
33 Mult (1, 3);
34 EqPredicate (2, 3, "done");
35 Inc 3;
36 Goto "loop";
37 Label "done";
38 Quit]
39 and expected_urm = [
40 URMZero 4;
41 URMJump (1, 4, 4);
42 URMZero 8;
43 URMJump (8, 8, 7);
44 URMSucc 1;
45 URMZero 9;
46 URMJump (9, 9, 29);
47 URMCopy (2, 1);
48 URMZero 1;
49 URMSucc 1;
50 URMZero 3;
51 URMSucc 3;
52 URMCopy (5, 1);
53 URMZero 1;
54 URMZero 6;
55 URMJump (3, 6, 25);
56 URMZero 7;
57 URMJump (5, 7, 22);
58 URMSucc 1;
59 URMSucc 7;
60 URMZero 10;
61 URMJump (10, 10, 17);
62 URMSucc 6;
63 URMZero 11;
64 URMJump (11, 11, 15);
65 URMJump (2, 3, 29);
66 URMSucc 3;
67 URMZero 12;
68 URMJump (12, 12, 12);
69 URMZero 13;
70 URMJump (13, 13, 38)]
71 in let output_urm = urm_from_eurm input_eurm
72 in
73 Assert.is_true (output_urm = expected_urm))
74 45
75let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () 46let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests ()
76 *)
diff --git a/src/main.mli b/src/main.mli
new file mode 100644
index 0000000..73ba84e
--- /dev/null
+++ b/src/main.mli
@@ -0,0 +1,6 @@
1(*
2 * UPEM / L3 / Functional programming / Project: URM
3 * Pacien TRAN-GIRARD, Adam NAILI
4 *)
5
6val read_prgm : (string list -> 'a list) -> string -> 'a list
diff --git a/src/makefile b/src/makefile
index 6aceab8..f061b74 100644
--- a/src/makefile
+++ b/src/makefile
@@ -6,9 +6,10 @@ SOURCES = \
6 parser.mli parser.ml \ 6 parser.mli parser.ml \
7 instptr.mli instptr.ml \ 7 instptr.mli instptr.ml \
8 reg.mli reg.ml \ 8 reg.mli reg.ml \
9 urm.mli urm.ml urm_test.ml \ 9 urm.mli urm.ml \
10 eurm.mli eurm.ml eurm_test.ml \ 10 eurm.mli eurm.ml \
11 main.ml 11 main.mli main.ml \
12 urm_test.ml eurm_test.ml
12 13
13OCAMLMAKEFILE = /usr/share/ocamlmakefile/OCamlMakefile 14OCAMLMAKEFILE = /usr/share/ocamlmakefile/OCamlMakefile
14include $(OCAMLMAKEFILE) 15include $(OCAMLMAKEFILE)
diff --git a/src/urm_test.ml b/src/urm_test.ml
index bf620e0..c64da3b 100644
--- a/src/urm_test.ml
+++ b/src/urm_test.ml
@@ -4,148 +4,42 @@
4 *) 4 *)
5 5
6open Common 6open Common
7open Instptr 7open Main
8open Parser
8open Urm 9open Urm
9open Reg 10open Reg
10open Kaputt.Abbreviations 11open Kaputt
12
13let run_urm_prgm filename regs =
14 let prgm = read_prgm (urm_program_of_lex) filename
15 in urm_mk prgm regs |> urm_run
11 16
12let () = 17let () =
13 Test.add_simple_test 18 Test.add_simple_test
14 ~title:"example_urm_add_program" 19 ~title:"example_urm_add"
15 (fun () -> 20 (fun () ->
16 let input_prgm = [ 21 let output = run_urm_prgm "../examples/add.urm" [Reg(1, 5); Reg(2, 3)]
17 URMZero 0; 22 in Assertion.equal (regs_get output 1) (5 + 3))
18 URMZero 3;
19 URMJump (1, 3, 6);
20 URMSucc 0;
21 URMSucc 3;
22 URMJump (3, 3, 2);
23 URMZero 3;
24 URMJump (2, 3, 11);
25 URMSucc 0;
26 URMSucc 3;
27 URMJump (3, 3, 7)]
28 and input_regs = [
29 Reg (1, 2);
30 Reg (2, 3)]
31 and expected_urm = {
32 instptr = InstPtr ([], [
33 (0, URMZero 0);
34 (1, URMZero 3);
35 (2, URMJump (1, 3, 6));
36 (3, URMSucc 0);
37 (4, URMSucc 3);
38 (5, URMJump (3, 3, 2));
39 (6, URMZero 3);
40 (7, URMJump (2, 3, 11));
41 (8, URMSucc 0);
42 (9, URMSucc 3);
43 (10, URMJump (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 23
58let () = 24let () =
59 Test.add_simple_test 25 Test.add_simple_test
60 ~title:"example_urm_factorial_program" 26 ~title:"example_urm_factorial"
61 (fun () -> 27 (fun () ->
62 let input_prgm = [ 28 let output = run_urm_prgm "../examples/factorial.urm" [Reg(1, 5)]
63 URMZero 4; 29 in Assertion.equal (regs_get output 1) 120)
64 URMJump (1, 4, 4);
65 URMZero 8;
66 URMJump (8, 8, 7);
67 URMSucc 1;
68 URMZero 9;
69 URMJump (9, 9, 29);
70 URMCopy (2, 1);
71 URMZero 1;
72 URMSucc 1;
73 URMZero 3;
74 URMSucc 3;
75 URMCopy (5, 1);
76 URMZero 1;
77 URMZero 6;
78 URMJump (3, 6, 25);
79 URMZero 7;
80 URMJump (5, 7, 22);
81 URMSucc 1;
82 URMSucc 7;
83 URMZero 10;
84 URMJump (10, 10, 17);
85 URMSucc 6;
86 URMZero 11;
87 URMJump (11, 11, 15);
88 URMJump (2, 3, 29);
89 URMSucc 3;
90 URMZero 12;
91 URMJump (12, 12, 12);
92 URMZero 13;
93 URMJump (13, 13, 38)]
94 and input_regs = [
95 Reg (1, 5)]
96 and expected_urm = {
97 instptr = InstPtr ([], [
98 (0, URMZero 4);
99 (1, URMJump (1, 4, 4));
100 (2, URMZero 8);
101 (3, URMJump (8, 8, 7));
102 (4, URMSucc 1);
103 (5, URMZero 9);
104 (6, URMJump (9, 9, 29));
105 (7, URMCopy (2, 1));
106 (8, URMZero 1);
107 (9, URMSucc 1);
108 (10, URMZero 3);