more tests for Enum

This commit is contained in:
Simon Cruanes 2013-03-19 00:48:11 +01:00
parent 101fc8a01e
commit ca5336dfb0
2 changed files with 15 additions and 2 deletions

View file

@ -170,8 +170,8 @@ let to_list enum =
let to_rev_list enum = let to_rev_list enum =
let rec fold acc gen = let rec fold acc gen =
let acc', stop = let acc', stop =
try let x = gen () in x :: acc, true try let x = gen () in x :: acc, false
with EOG -> acc, false with EOG -> acc, true
in if stop then acc' else fold acc' gen in if stop then acc' else fold acc' gen
in in
fold [] (enum ()) fold [] (enum ())

View file

@ -29,9 +29,22 @@ let test_map () =
OUnit.assert_equal ~printer:pstrlist ["9"; "10"] (Enum.to_list (Enum.drop 8 e')); 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 = let suite =
"test_enum" >::: "test_enum" >:::
[ "test_singleton" >:: test_singleton; [ "test_singleton" >:: test_singleton;
"test_iter" >:: test_iter; "test_iter" >:: test_iter;
"test_map" >:: test_map; "test_map" >:: test_map;
"test_append" >:: test_append;
"test_flatMap" >:: test_flatMap;
] ]