aboutsummaryrefslogtreecommitdiff
path: root/src/eurm_test.ml
blob: cfb1e694e6034547281891bce511cfd22eee394f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(*
 * UPEM / L3 / Functional programming / Project: URM
 * Pacien TRAN-GIRARD, Adam NAILI
 *)

open Common
open Main
open Parser
open Urm
open Eurm
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_sum_first_odd_integers"
    (fun () ->
       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 ()