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
2c640130
Commit
2c640130
authored
Mar 03, 2014
by
Julien Lopez
Browse files
Add some tests on variant types
parent
31b36113
Changes
3
Hide whitespace changes
Inline
Side-by-side
tests/ocaml/misc/misc.cd
View file @
2c640130
...
...
@@ -15,6 +15,11 @@ let map_complex (f : (Float,Float)->Float)(c : { x = Float; y = Float })
type t = (`A, t) | (`B, (t,t)) | (`C, Int)
let pp (x : t) : Latin1 = string_of x
let find (x : t)(el : Int) : Bool = match x with
| (`C, i) -> (i = el)
| (`A, a) -> find a el
| (`B, (a, b)) -> find a el || find b el
let exists = Sys.file_exists
let i = consts.j
...
...
@@ -28,3 +33,9 @@ let str_len = String.length
(*let [] = Unix.sleep 1*)
let listmap = List.map with { Int Int }
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, []) -> ""
tests/ocaml/misc/misc.mli
View file @
2c640130
type
cduce_int
=
Big_int
.
big_int
val
f
:
(
char
->
char
)
->
(
string
->
string
)
val
x
:
char
ref
...
...
@@ -9,10 +11,11 @@ val diag : float -> complex
val
map_complex
:
(
float
*
float
->
float
)
->
complex
->
float
type
t
=
A
of
t
|
B
of
t
*
t
|
C
of
int
val
pp
:
t
->
string
val
find
:
t
->
int
->
bool
val
i
:
int
val
exists
:
string
->
bool
...
...
@@ -25,6 +28,10 @@ val unix_write : Unix.file_descr -> string -> int -> int -> int
val
str_len
:
string
->
int
type
cduce_int
=
Big_int
.
big_int
val
listmap
:
(
cduce_int
->
cduce_int
)
->
cduce_int
list
->
cduce_int
list
type
typ
=
|
Empty
of
unit
|
Tree
of
string
*
typ
*
typ
val
visit_tree_infix
:
(
string
->
string
)
->
typ
->
string
tests/ocaml/misc/misctest.ml
View file @
2c640130
...
...
@@ -16,7 +16,7 @@ let norm (x,y) = sqrt(x *. x +. y *. y);;
let
mod_float
(
x
,
y
)
=
x
-.
float_of_int
(
int_of_float
(
x
/.
y
))
*.
y
let
tests
=
"
A
"
>:::
let
tests
=
"
Misc
"
>:::
[
"f"
>::
(
fun
test_ctxt
->
assert_equal
~
msg
:
"Test Misc.f.1 failed"
"Hello!"
(
Misc
.
f
id
"Hello!"
);
...
...
@@ -33,7 +33,8 @@ let tests = "A" >:::
);
"re"
>::
(
fun
test_ctxt
->
assert_equal
~
msg
:
"Test Misc.re.1 failed"
0
.
2
(
Misc
.
re
{
Misc
.
x
=
0
.
2
;
Misc
.
y
=
0
.
8
})
assert_equal
~
msg
:
"Test Misc.re.1 failed"
0
.
2
(
Misc
.
re
{
Misc
.
x
=
0
.
2
;
Misc
.
y
=
0
.
8
})
);
"diag"
>::
(
fun
test_ctxt
->
...
...
@@ -58,8 +59,15 @@ let tests = "A" >:::
"(`B,((`C,3),(`A,(`C,2))))"
(
Misc
.
pp
(
Misc
.
B
(
Misc
.
C
(
3
)
,
Misc
.
A
(
Misc
.
C
(
2
)))));
);
"find"
>::
(
fun
test_ctxt
->
let
exp
=
Misc
.
A
(
Misc
.
B
(
Misc
.
C
(
3
)
,
Misc
.
A
(
Misc
.
C
(
7
))))
in
assert_equal
~
msg
:
"Test Misc.find.1 failed"
true
(
Misc
.
find
exp
3
);
assert_equal
~
msg
:
"Test Misc.find.2 failed"
false
(
Misc
.
find
exp
5
);
);
"exists"
>::
(
fun
test_ctxt
->
assert_equal
~
msg
:
"Test Misc.exists.1 failed"
false
(
Misc
.
exists
"toto.tmp"
);
assert_equal
~
msg
:
"Test Misc.exists.1 failed"
false
(
Misc
.
exists
"toto.tmp"
);
let
file
=
bracket_tmpfile
test_ctxt
in
match
file
with
|
(
name
,
_
)
->
assert_equal
~
msg
:
"Test Misc.exists.2 failed"
true
(
Misc
.
exists
name
);
...
...
@@ -68,7 +76,8 @@ let tests = "A" >:::
"str_len"
>::
(
fun
test_ctxt
->
let
str
=
"This is an example."
in
assert_equal
~
msg
:
"Test Misc.str_len.1 failed"
19
(
Misc
.
str_len
str
);
assert_equal
~
msg
:
"Test Misc.str_len.2 failed"
23
(
Misc
.
str_len
(
str
^
"hack"
));
assert_equal
~
msg
:
"Test Misc.str_len.2 failed"
23
(
Misc
.
str_len
(
str
^
"hack"
));
);
"unix_write"
>::
(
fun
test_ctxt
->
...
...
@@ -76,7 +85,8 @@ let tests = "A" >:::
assert_equal
~
msg
:
"Test Misc.unix_write.easy failed"
(
String
.
length
h
)
(
Misc
.
unix_write
Unix
.
stderr
h
0
(
String
.
length
h
));
assert_equal
~
msg
:
"Test Misc.unix_write.hard failed"
(
Misc
.
str_len
Misc
.
home
)
(
Misc
.
unix_write
Misc
.
stdin
Misc
.
home
0
(
Misc
.
str_len
Misc
.
home
))
(
Misc
.
str_len
Misc
.
home
)
(
Misc
.
unix_write
Misc
.
stdin
Misc
.
home
0
(
Misc
.
str_len
Misc
.
home
))
);
"listmap"
>::
(
fun
test_ctxt
->
...
...
@@ -93,8 +103,18 @@ let tests = "A" >:::
test_each
lst
[
bioi
20
;
bioi
40
;
bioi
60
];
);
"visit_tree_infix"
>::
(
fun
test_ctxt
->
let
tree
=
Misc
.
Tree
(
"first"
,
Misc
.
Empty
()
,
Misc
.
Tree
(
" second"
,
Misc
.
Empty
()
,
Misc
.
Empty
()
))
in
assert_equal
~
msg
:
"Test Misc.visit_tree_infix.1 failed"
"first second"
(
Misc
.
visit_tree_infix
(
fun
x
->
x
)
tree
);
assert_equal
~
msg
:
"Test Misc.visit_tree_infix.2 failed"
"5~7~"
(
Misc
.
visit_tree_infix
(
fun
x
->
string_of_int
(
Misc
.
str_len
x
)
^
"~"
)
tree
);
);
"misc"
>::
(
fun
test_ctxt
->
assert_equal
~
msg
:
"Test Misc.misc.1 failed"
(
Sys
.
getenv
"HOME"
)
Misc
.
home
;
assert_equal
~
msg
:
"Test Misc.misc.1 failed"
(
Sys
.
getenv
"HOME"
)
Misc
.
home
;
assert_equal
~
msg
:
"Test Misc.misc.2 failed"
2
Misc
.
i
;
);
...
...
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