Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
12458501
Commit
12458501
authored
Mar 03, 2014
by
Julien Lopez
Browse files
Add some tests on records
parent
2c640130
Changes
3
Hide whitespace changes
Inline
Side-by-side
tests/ocaml/misc/misc.cd
View file @
12458501
...
...
@@ -39,3 +39,15 @@ type typ = (`Empty, []) | (`Tree, (Latin1, (typ, typ)))
let visit_tree_infix (f : Latin1 -> Latin1)(tree : typ) : Latin1 = match tree with
| (`Tree, (str, (left, right))) -> visit_tree_infix f left @ f str @ visit_tree_infix f right
| (`Empty, []) -> ""
type point3d = { a=Float b=Float c=Float }
type stack3d = (`Novalue, []) | (`Stack, (point3d, stack3d))
let push (s : stack3d)(p : point3d) : stack3d = (`Stack, (p, s))
let pop (s : stack3d) : stack3d = match s with
| (`Stack, (_, rest)) -> rest
| e & (`Novalue, []) -> e
let print_stack (s : stack3d) : Latin1 = match s with
| (`Stack, (el, rest)) -> string_of el @ print_stack rest
| (`Novalue, []) -> ""
tests/ocaml/misc/misc.mli
View file @
12458501
...
...
@@ -35,3 +35,13 @@ type typ =
|
Tree
of
string
*
typ
*
typ
val
visit_tree_infix
:
(
string
->
string
)
->
typ
->
string
type
point3d
=
{
a
:
float
;
b
:
float
;
c
:
float
}
type
stack3d
=
|
Novalue
of
unit
|
Stack
of
point3d
*
stack3d
val
push
:
stack3d
->
point3d
->
stack3d
val
pop
:
stack3d
->
stack3d
val
print_stack
:
stack3d
->
string
tests/ocaml/misc/misctest.ml
View file @
12458501
...
...
@@ -112,6 +112,30 @@ let tests = "Misc" >:::
(
Misc
.
visit_tree_infix
(
fun
x
->
string_of_int
(
Misc
.
str_len
x
)
^
"~"
)
tree
);
);
"stack"
>::
(
fun
test_ctxt
->
let
p1
=
{
Misc
.
a
=
(
float_of_string
"1.2"
);
Misc
.
b
=
(
float_of_string
"0.3"
);
Misc
.
c
=
(
float_of_string
"0.5"
)
}
in
let
p2
=
{
Misc
.
a
=
(
float_of_string
"-0.2"
);
Misc
.
b
=
(
float_of_string
"0.4"
);
Misc
.
c
=
(
float_of_string
"0.7"
)
}
in
let
stack
=
Misc
.
Novalue
()
in
let
stack
=
Misc
.
push
stack
p1
in
assert_equal
~
msg
:
"Test Misc.stack.push1 failed"
"{ a=1.200000 b=0.300000 c=0.500000 }"
(
Misc
.
print_stack
stack
);
let
stack
=
Misc
.
push
stack
p2
in
assert_equal
~
msg
:
"Test Misc.stack.push2 failed"
"{ a=-0.200000 b=0.400000 c=0.700000 }{ a=1.200000 b=0.300000 c=0.500000 }"
(
Misc
.
print_stack
stack
);
let
stack
=
Misc
.
pop
stack
in
assert_equal
~
msg
:
"Test Misc.stack.pop1 failed"
"{ a=1.200000 b=0.300000 c=0.500000 }"
(
Misc
.
print_stack
stack
);
let
stack
=
Misc
.
pop
stack
in
assert_equal
~
msg
:
"Test Misc.stack.pop2 failed"
""
(
Misc
.
print_stack
stack
);
let
stack
=
Misc
.
pop
stack
in
assert_equal
~
msg
:
"Test Misc.stack.pop3 failed"
""
(
Misc
.
print_stack
stack
);
);
"misc"
>::
(
fun
test_ctxt
->
assert_equal
~
msg
:
"Test Misc.misc.1 failed"
(
Sys
.
getenv
"HOME"
)
Misc
.
home
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment