mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 19:25:30 -05:00
bugfix: take would fail on 0
This commit is contained in:
parent
4ae9e77db3
commit
81d7315000
2 changed files with 9 additions and 1 deletions
|
|
@ -336,9 +336,9 @@ let take n seq k =
|
||||||
let count = ref 0 in
|
let count = ref 0 in
|
||||||
try
|
try
|
||||||
seq (fun x ->
|
seq (fun x ->
|
||||||
|
if !count = n then raise ExitSequence;
|
||||||
incr count;
|
incr count;
|
||||||
k x;
|
k x;
|
||||||
if !count = n then raise ExitSequence
|
|
||||||
)
|
)
|
||||||
with ExitSequence -> ()
|
with ExitSequence -> ()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,13 @@ let test_int_range () =
|
||||||
OUnit.assert_equal ~printer:pp_ilist [] S.(to_list (10 --^ 60));
|
OUnit.assert_equal ~printer:pp_ilist [] S.(to_list (10 --^ 60));
|
||||||
()
|
()
|
||||||
|
|
||||||
|
let test_take () =
|
||||||
|
let l = S.(to_list (take 0 (of_list [1]))) in
|
||||||
|
OUnit.assert_equal ~printer:pp_ilist [] l;
|
||||||
|
let l = S.(to_list (take 5 (of_list [1;2;3;4;5;6;7;8;9;10]))) in
|
||||||
|
OUnit.assert_equal ~printer:pp_ilist [1;2;3;4;5] l;
|
||||||
|
()
|
||||||
|
|
||||||
let suite =
|
let suite =
|
||||||
"test_sequence" >:::
|
"test_sequence" >:::
|
||||||
[ "test_empty" >:: test_empty;
|
[ "test_empty" >:: test_empty;
|
||||||
|
|
@ -217,4 +224,5 @@ let suite =
|
||||||
"test_unfoldr" >:: test_unfoldr;
|
"test_unfoldr" >:: test_unfoldr;
|
||||||
"test_hashtbl" >:: test_hashtbl;
|
"test_hashtbl" >:: test_hashtbl;
|
||||||
"test_int_range" >:: test_int_range;
|
"test_int_range" >:: test_int_range;
|
||||||
|
"test_take" >:: test_take;
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue