This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocamllex_menhir_example_test.ml
86 lines (82 loc) · 2.83 KB
/
ocamllex_menhir_example_test.ml
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(*
SPDX-FileCopyrightText: Copyright 2023 Roland Csaszar
SPDX-License-Identifier: MIT
Project: OCaml-Buck-2-Examples, ocamllex_menhir_example
File: ocamllex_menhir_example_test.ml
Date: 08.Oct.2023
============================================================================= *)
open Ocamllex_menhir_example.Interpreter
let () =
let open Alcotest in
let open QCheck_alcotest in
run
"Interpreter Tests"
[ ( "Fixed terms and results"
, [ test_case "1 - 1 = 0" `Quick (fun () ->
(check int) "same ints" 0 (interp_env "1 - 1" |> int_of_string))
; test_case "2.0 * 1.75 - 4.5 = -1.0" `Quick (fun () ->
(check (float 0.00001))
"same floats"
(-1.0)
(interp_env "2.0 * 1.75 - 4.5" |> float_of_string))
; test_case "let a = 5.21 in a - 0.21 = 5.0" `Quick (fun () ->
(check (float 0.00001))
"same floats"
5.0
(interp_env "let a = 5.21 in a - 0.21" |> float_of_string))
] )
; ( "Generated Terms"
, [ to_alcotest
~colors:true
~verbose:true
~long:true
QCheck2.(
Test.make
~name:"n - m"
~count:100
~print:Print.(pair int int)
Gen.(tup2 nat nat)
(fun (n, m) ->
let term = string_of_int n ^ "-" ^ string_of_int m in
n - m = (interp_env term |> int_of_string)))
; to_alcotest
~colors:true
~verbose:true
~long:true
QCheck2.(
Test.make
~name:"n + m"
~count:100
~print:Print.(pair int int)
Gen.(tup2 nat nat)
(fun (n, m) ->
let term = string_of_int n ^ "+" ^ string_of_int m in
n + m = (interp_env term |> int_of_string)))
; to_alcotest
~colors:true
~verbose:true
~long:true
QCheck2.(
Test.make
~name:"n * m"
~count:100
~print:Print.(pair int int)
Gen.(tup2 nat nat)
(fun (n, m) ->
let term = string_of_int n ^ "*" ^ string_of_int m in
n * m = (interp_env term |> int_of_string)))
; to_alcotest
~colors:true
~verbose:true
~long:true
QCheck2.(
Test.make
~name:"n / m"
~count:100
~print:Print.(pair int int)
Gen.(tup2 nat Gen.(int_range 1 156845))
(fun (n, m) ->
let term = string_of_int n ^ "/" ^ string_of_int m in
n / m = (interp_env term |> int_of_string)))
] )
]