Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsexplain
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD 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
Verified Software
jsexplain
Commits
42afe0a0
Commit
42afe0a0
authored
9 years ago
by
Paul Iannetta
Committed by
Thomas Wood
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
update of test files
parent
516425a2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
generator/tests/calc.js
+0
-61
0 additions, 61 deletions
generator/tests/calc.js
generator/tests/calc.ml
+1
-0
1 addition, 0 deletions
generator/tests/calc.ml
generator/tests/mylist.ml
+17
-9
17 additions, 9 deletions
generator/tests/mylist.ml
generator/tests/stack.ml
+11
-7
11 additions, 7 deletions
generator/tests/stack.ml
with
29 additions
and
77 deletions
generator/tests/calc.js
deleted
100644 → 0
+
0
−
61
View file @
516425a2
Stack
=
{
var
is_empty
=
function
(
s
)
{
return
s
===
Nil
;
};
var
push
=
function
(
x
,
stack
)
{
return
{
type
:
"
Cons
"
,
value
:
x
,
stack
:
stack
};
};
var
pop
=
function
(
stack
)
{
return
(
function
()
{
switch
(
stack
.
type
)
{
case
"
Cons
"
:
var
x
=
stack
.
value
,
xs
=
stack
.
stack
;
return
x
;
case
"
Nil
"
:
return
stuck
(
"
Empty list
"
);
}
}());
};
}
var
eval_
=
function
(
expr
)
{
return
(
function
()
{
switch
(
expr
.
type
)
{
case
"
Const
"
:
var
n
=
expr
.
value
;
return
n
;
case
"
Add
"
:
var
ls
=
expr
.
left
,
rs
=
expr
.
right
;
return
eval_
(
ls
)
+
eval_
(
rs
);
case
"
Sub
"
:
var
ls
=
expr
.
left
,
rs
=
expr
.
right
;
return
eval_
(
ls
)
-
eval_
(
rs
);
case
"
Mul
"
:
var
ls
=
expr
.
left
,
rs
=
expr
.
right
;
return
eval_
(
ls
)
*
eval_
(
rs
);
case
"
Div
"
:
var
ls
=
expr
.
left
,
rs
=
expr
.
right
;
return
eval_
(
ls
)
/
eval_
(
rs
);
}
}());
};
var
print_expr
=
function
(
expr
)
{
return
(
function
()
{
switch
(
expr
.
type
)
{
case
"
Const
"
:
var
n
=
expr
.
value
;
return
to_string
(
n
);
case
"
Add
"
:
var
ls
=
expr
.
left
,
rs
=
expr
.
right
;
return
"
(
"
+
print_expr
(
ls
)
+
"
)
"
+
"
+
"
+
print_expr
(
rs
);
case
"
Sub
"
:
var
ls
=
expr
.
left
,
rs
=
expr
.
right
;
return
"
(
"
+
print_expr
(
ls
)
+
"
)
"
+
"
-
"
+
print_expr
(
rs
);
case
"
Mul
"
:
var
ls
=
expr
.
left
,
rs
=
expr
.
right
;
return
"
(
"
+
print_expr
(
ls
)
+
"
)
"
+
"
*
"
+
print_expr
(
rs
);
case
"
Div
"
:
var
ls
=
expr
.
left
,
rs
=
expr
.
right
;
return
"
(
"
+
print_expr
(
ls
)
+
"
)
"
+
"
/
"
+
print_expr
(
rs
);
}
}());
};
var
f
=
(
function
()
{
var
source
=
parse
(
"
((1972 / 29) / 2) + 8
"
);
return
print
(
print_expr
(
source
)
+
"
=
"
+
to_string
(
eval_
(
source
)));
}());
This diff is collapsed.
Click to expand it.
generator/tests/calc.ml
+
1
−
0
View file @
42afe0a0
...
...
@@ -22,5 +22,6 @@ let rec print_expr expr = match expr with
|
Div
(
ls
,
rs
)
->
"("
+
(
print_expr
ls
)
+
")"
+
" / "
+
(
print_expr
rs
)
let
f
=
let
rec
bli
=
Stack
.
C
(
1
,
Stack
.
N
)
in
let
source
=
parse
"((1972 / 29) / 2) + 8"
in
print
((
print_expr
source
)
+
" = "
+
to_string
(
eval_
source
))
This diff is collapsed.
Click to expand it.
generator/tests/mylist.ml
+
17
−
9
View file @
42afe0a0
...
...
@@ -32,10 +32,11 @@ let rec fold_right f l acc = match l with
let
rev_map
f
l
=
fold_left
(
fun
acc
x
->
Cons
(
f
x
,
acc
))
Nil
l
let
map
f
l
=
fold_right
(
fun
acc
x
->
Cons
(
f
x
,
acc
))
l
Nil
let
rev
l
=
fold_left
(
fun
acc
x
->
Cons
(
x
,
acc
))
Nil
l
let
length
l
=
fold_left
(
fun
acc
x
->
incr
acc
)
0
l
let
rec
range
i
j
acc
=
if
le
i
j
then
range
(
incr
i
)
j
(
Cons
(
i
,
acc
))
else
acc
let
rec
range
i
j
acc
=
if
i
<=
j
then
range
(
incr
i
)
j
(
Cons
(
i
,
acc
))
else
acc
(* Test *)
...
...
@@ -43,11 +44,18 @@ let list0 = Nil
let
list1
=
range
0
1
Nil
let
list2
=
range
1
5
Nil
let
sqr
x
=
mul
x
x
;;
length
list0
;;
length
list1
;;
length
list2
;;
map
sqr
list0
;;
map
sqr
list1
;;
map
sqr
list2
;;
let
sqr
x
=
mul
x
x
let
print_list
l
=
let
rec
aux
acc
l
=
match
l
with
|
Nil
->
acc
|
Cons
(
x
,
xs
)
->
print
xs
;
if
xs
===
Nil
then
aux
(
x
+
acc
)
xs
else
aux
(
x
+
","
+
acc
)
xs
in
"["
+
aux
""
(
rev
l
)
+
"]"
;;
let
f
=
1
in
print
(
length
list0
);
print
(
length
list1
);
print
(
length
list2
);
print
(
print_list
(
map
sqr
list0
));
print
(
print_list
(
map
sqr
list1
));
print
(
print_list
(
map
sqr
list2
));
This diff is collapsed.
Click to expand it.
generator/tests/stack.ml
+
11
−
7
View file @
42afe0a0
type
'
a
stack
=
|
Nil
|
Cons
[
@
f
value
,
stack
]
of
'
a
*
'
a
stack
type
stack
=
|
C
[
@
f
value
,
stack
]
of
int
*
stack
|
K
[
@
f
value
,
stack
]
of
int
*
stack
|
N
[
@
f
]
|
B
[
@
f
]
let
is_empty
s
=
s
===
N
il
let
is_empty
s
=
s
===
N
let
push
x
stack
=
C
ons
(
x
,
stack
)
let
push
x
stack
=
C
(
x
,
stack
)
let
pop
stack
=
match
stack
with
|
Cons
(
x
,
xs
)
->
x
|
Nil
->
stuck
"Empty list"
|
C
(
x
,
xs
)
->
x
|
K
(
x
,
xs
)
->
x
|
B
->
stuck
"Empty list"
|
N
->
stuck
"Empty list"
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