aboutsummaryrefslogtreecommitdiff
path: root/src/eurm_test.ml
diff options
context:
space:
mode:
authorpacien2018-05-01 01:29:33 +0200
committerpacien2018-05-01 01:29:33 +0200
commit2706214e1f9ba8c62cea26055dcc9aa46fcd0c3d (patch)
tree7c23f6a87434288bd88cdb7b7eadc867c9443281 /src/eurm_test.ml
parent58e4fa622c441a9b832f0656580204a9f5b23e1d (diff)
downloadurm-2706214e1f9ba8c62cea26055dcc9aa46fcd0c3d.tar.gz
Add new tests
Diffstat (limited to 'src/eurm_test.ml')
-rw-r--r--src/eurm_test.ml94
1 files changed, 32 insertions, 62 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 *)