mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
more tests for Enum
This commit is contained in:
parent
101fc8a01e
commit
ca5336dfb0
2 changed files with 15 additions and 2 deletions
4
enum.ml
4
enum.ml
|
|
@ -170,8 +170,8 @@ let to_list enum =
|
|||
let to_rev_list enum =
|
||||
let rec fold acc gen =
|
||||
let acc', stop =
|
||||
try let x = gen () in x :: acc, true
|
||||
with EOG -> acc, false
|
||||
try let x = gen () in x :: acc, false
|
||||
with EOG -> acc, true
|
||||
in if stop then acc' else fold acc' gen
|
||||
in
|
||||
fold [] (enum ())
|
||||
|
|
|
|||
|
|
@ -29,9 +29,22 @@ let test_map () =
|
|||
OUnit.assert_equal ~printer:pstrlist ["9"; "10"] (Enum.to_list (Enum.drop 8 e'));
|
||||
()
|
||||
|
||||
let test_append () =
|
||||
let e = (1 -- 5) @@ (6 -- 10) in
|
||||
OUnit.assert_equal [10;9;8;7;6;5;4;3;2;1] (Enum.to_rev_list e);
|
||||
()
|
||||
|
||||
let test_flatMap () =
|
||||
let e = 1 -- 3 in
|
||||
let e' = e >>= (fun x -> x -- (x+1)) in
|
||||
OUnit.assert_equal [1;2;2;3;3;4] (Enum.to_list e');
|
||||
()
|
||||
|
||||
let suite =
|
||||
"test_enum" >:::
|
||||
[ "test_singleton" >:: test_singleton;
|
||||
"test_iter" >:: test_iter;
|
||||
"test_map" >:: test_map;
|
||||
"test_append" >:: test_append;
|
||||
"test_flatMap" >:: test_flatMap;
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue