From 2706214e1f9ba8c62cea26055dcc9aa46fcd0c3d Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 1 May 2018 01:29:33 +0200 Subject: Add new tests --- src/eurm_test.ml | 94 +++++++++++++++++++------------------------------------- 1 file changed, 32 insertions(+), 62 deletions(-) (limited to 'src/eurm_test.ml') 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 @@ *) open Common +open Main +open Parser open Urm open Eurm -open Kaputt.Abbreviations +open Reg +open Kaputt + +let run_eurm_prgm filename regs = + let prgm = read_prgm (fun f -> eurm_program_of_lex f |> urm_from_eurm) filename + in urm_mk prgm regs |> urm_run + +let () = + Test.add_simple_test + ~title:"example_eurm_add" + (fun () -> + let output = run_eurm_prgm "../examples/add.eurm" [Reg(1, 5); Reg(2, 3)] + in Assertion.equal (regs_get output 1) (5 + 3)) + +(*let () = + Test.add_simple_test + ~title:"example_eurm_factorial" + (fun () -> + let output = run_eurm_prgm "../examples/factorial.eurm" [Reg(1, 5)] + in Assertion.equal (regs_get output 1) 120) +*) +let () = + Test.add_simple_test + ~title:"example_eurm_sum_first_integers" + (fun () -> + let output = run_eurm_prgm "../examples/sum-first-integers.eurm" [Reg(1, 51)] + in Assertion.equal (regs_get output 1) (51*(51+1)/2)) -(* let () = Test.add_simple_test - ~title:"example_eurm_factorial_conversion" + ~title:"example_eurm_sum_first_odd_integers" (fun () -> - let input_eurm = [ - Comment "Compute r1! and place the result in r1"; - ZeroPredicate (1, "r1=0"); - Goto "r1>0"; - Comment "r1 holds 0"; - Label "r1=0"; - Inc 1; - Goto "done"; - Comment "r1 holds a positive integer"; - Label "r1>0"; - Copy (2, 1); - Zero 1; - Inc 1; - Zero 3; - Inc 3; - Comment "main loop"; - Label "loop"; - Mult (1, 3); - EqPredicate (2, 3, "done"); - Inc 3; - Goto "loop"; - Label "done"; - Quit] - and expected_urm = [ - URMZero 4; - URMJump (1, 4, 4); - URMZero 8; - URMJump (8, 8, 7); - URMSucc 1; - URMZero 9; - URMJump (9, 9, 29); - URMCopy (2, 1); - URMZero 1; - URMSucc 1; - URMZero 3; - URMSucc 3; - URMCopy (5, 1); - URMZero 1; - URMZero 6; - URMJump (3, 6, 25); - URMZero 7; - URMJump (5, 7, 22); - URMSucc 1; - URMSucc 7; - URMZero 10; - URMJump (10, 10, 17); - URMSucc 6; - URMZero 11; - URMJump (11, 11, 15); - URMJump (2, 3, 29); - URMSucc 3; - URMZero 12; - URMJump (12, 12, 12); - URMZero 13; - URMJump (13, 13, 38)] - in let output_urm = urm_from_eurm input_eurm - in - Assert.is_true (output_urm = expected_urm)) + let output = run_eurm_prgm "../examples/sum-first-odd-integers.eurm" [Reg(1, 51)] + in Assertion.equal (regs_get output 1) 676) let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () - *) -- cgit v1.2.3