Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alphaLib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
POTTIER Francois
alphaLib
Commits
c5cbb050
Commit
c5cbb050
authored
8 years ago
by
POTTIER Francois
Browse files
Options
Downloads
Patches
Plain Diff
The beginning of a more serious test suite.
parent
6fbe4f5f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
demos/basic/Main.ml
+114
-13
114 additions, 13 deletions
demos/basic/Main.ml
with
114 additions
and
13 deletions
demos/basic/Main.ml
+
114
−
13
View file @
c5cbb050
...
@@ -2,9 +2,120 @@ open Printf
...
@@ -2,9 +2,120 @@ open Printf
open
AlphaLib
open
AlphaLib
open
Term
open
Term
open
TermGenerator
open
TermGenerator
module
T
=
Toolbox
.
Make
(
Term
)
module
T
=
Toolbox
.
Make
(
Term
)
open
T
open
T
(* [interval i j] constructs a list representation of the semi-open interval
[i..j). *)
let
rec
interval
i
j
:
int
list
=
if
i
<
j
then
i
::
interval
(
i
+
1
)
j
else
[]
(* [init i j f] constructs a list of the values [f i] up to [f (j - 1)]. *)
let
init
i
j
(
f
:
int
->
'
a
)
:
'
a
list
=
List
.
map
f
(
interval
i
j
)
(* A non-hygienic printer of arbitrary terms. This printer shows the internal
identity of atoms, using [Atom.show]. *)
let
nhprint
oc
t
=
Print
.
term
oc
(
show_term
t
)
(* A hygienic printer of closed terms. This printer uses [export]. *)
let
hprint
oc
t
=
Print
.
term
oc
(
export_term
KitExport
.
empty
t
)
(* Test parameters. *)
let
number
=
1000
let
size
=
1000
let
atoms
=
100
(* A collection of closed raw terms. *)
let
closed_raw_terms
:
raw_term
list
=
printf
"Generating random closed raw terms...
\n
%!"
;
init
0
number
(
fun
_i
->
generate_raw
size
)
(* Import them, so as to obtain a collection of closed nominal terms. *)
let
closed_nominal_terms
:
nominal_term
list
=
printf
"Importing these raw terms...
\n
%!"
;
List
.
map
(
import_term
KitImport
.
empty
)
closed_raw_terms
let
on_closed_nominal_terms
f
=
List
.
iter
f
closed_nominal_terms
(* The closed terms should be closed and well-formed. *)
let
()
=
printf
"Checking closedness and well-formedness...
\n
%!"
;
on_closed_nominal_terms
(
fun
t
->
assert
(
closed_term
t
);
assert
(
Atom
.
Set
.
is_empty
(
fa_term
t
));
assert
(
wf_term
t
)
)
(* A collection of random (non-closed, non-well-formed) nominal terms. *)
let
arbitrary_nominal_terms
:
nominal_term
list
=
printf
"Generating random nominal terms...
\n
%!"
;
init
0
number
(
fun
_i
->
generate_nominal
atoms
size
)
let
on_arbitrary_nominal_terms
f
=
List
.
iter
f
arbitrary_nominal_terms
(* Copy them, so as to obtain well-formed (although non-closed) nominal terms. *)
let
wf_nominal_terms
:
nominal_term
list
=
printf
"Copying these terms...
\n
%!"
;
List
.
map
copy_term
arbitrary_nominal_terms
let
on_wf_nominal_terms
f
=
List
.
iter
f
wf_nominal_terms
(* These terms should be well-formed. *)
let
()
=
printf
"Checking well-formedness...
\n
%!"
;
on_wf_nominal_terms
(
fun
t
->
assert
(
wf_term
t
)
)
(* The size computation should succeed. *)
let
()
=
printf
"Computing sizes...
\n
%!"
;
on_wf_nominal_terms
(
fun
t
->
ignore
(
size_term
t
:
int
)
)
(* [fa] and [occurs] should be consistent with each other. *)
let
()
=
printf
"Comparing fa and occurs...
\n
%!"
;
on_arbitrary_nominal_terms
(
fun
t
->
let
atoms
=
fa_term
t
in
Atom
.
Set
.
iter
(
fun
a
->
if
not
(
occurs_term
a
t
)
then
begin
printf
"Atom %a does not occur in term %a"
Atom
.
print
a
nhprint
t
end
;
assert
(
occurs_term
a
t
);
(* slow *)
)
atoms
)
(* Sample terms. *)
(* Sample terms. *)
let
x
=
let
x
=
...
@@ -48,18 +159,6 @@ let closed_samples = [
...
@@ -48,18 +159,6 @@ let closed_samples = [
let
evaluate
f
=
let
evaluate
f
=
List
.
iter
f
samples
List
.
iter
f
samples
(* A non-hygienic term printer. This printer shows the real (internal) identity
of atoms, using [Atom.show]. *)
let
nhprint
oc
t
=
Print
.
term
oc
(
show_term
t
)
(* A hygienic term printer. This printer uses [export]. *)
let
hprint
oc
t
=
(* works for closed terms only, as of now *)
Print
.
term
oc
(
export_term
KitExport
.
empty
t
)
let
()
=
let
()
=
printf
"Testing size...
\n
"
;
printf
"Testing size...
\n
"
;
[
[
...
@@ -142,6 +241,7 @@ let () =
...
@@ -142,6 +241,7 @@ let () =
evaluate
print_wf
;
evaluate
print_wf
;
print_wf
(
TApp
(
id
,
id
))
print_wf
(
TApp
(
id
,
id
))
(*
let () =
let () =
for _i = 0 to 9 do
for _i = 0 to 9 do
let t = import_term KitImport.empty (generate_raw 15) in
let t = import_term KitImport.empty (generate_raw 15) in
...
@@ -155,3 +255,4 @@ let () =
...
@@ -155,3 +255,4 @@ let () =
let t = generate_nominal (* atoms: *) 5 (* size: *) 15 in
let t = generate_nominal (* atoms: *) 5 (* size: *) 15 in
printf "generate_nominal() = %a\n%!" nhprint t
printf "generate_nominal() = %a\n%!" nhprint t
done
done
*)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment