fix(map_by_2): Fixed formatting

This commit is contained in:
Master Builder 2023-08-04 21:20:14 +00:00 committed by Simon Cruanes
parent 6fdbc2c88f
commit 67c46b6ce4
2 changed files with 13 additions and 8 deletions

View file

@ -114,7 +114,9 @@ let map_by_2 f seq k =
let f y = let f y =
match !r with match !r with
| None -> r := Some y | None -> r := Some y
| Some x -> r := None; k (f x y) | Some x ->
r := None;
k (f x y)
in in
seq f; seq f;
match !r with match !r with

View file

@ -351,17 +351,20 @@ let () =
(* map_by_2 tests *) (* map_by_2 tests *)
let test = OUnit.assert_equal ~printer:Q.Print.(list int) let test = OUnit.assert_equal ~printer:Q.Print.(list int)
let () = test [] (map_by_2 (fun a _ -> a) (of_list []) |> to_list) let () = test [] (map_by_2 (fun a _ -> a) (of_list []) |> to_list)
(* Test empty iterator *) (* Test empty iterator *)
let () = test [1] (map_by_2 (fun _ b -> b) (of_list [1]) |> to_list) let () = test [ 1 ] (map_by_2 (fun _ b -> b) (of_list [ 1 ]) |> to_list)
let () = test [3] (map_by_2 (fun _ b -> b) (1--3) |> drop 1 |> to_list) let () = test [ 3 ] (map_by_2 (fun _ b -> b) (1 -- 3) |> drop 1 |> to_list)
let () = test [9] (map_by_2 (fun _ b -> b) (1--9) |> drop 4 |> to_list) let () = test [ 9 ] (map_by_2 (fun _ b -> b) (1 -- 9) |> drop 4 |> to_list)
(* Odd number of elements should leave the last element in the iterator. (* Odd number of elements should leave the last element in the iterator.
For an increasing integer range [1,2k] (fun _ b -> b) returns only For an increasing integer range [1,2k] (fun _ b -> b) returns only
even numbers so this is sufficient to test that this element is left even numbers so this is sufficient to test that this element is left
in the iterator. *) in the iterator. *)
let () = test [1] (map_by_2 (fun a _ -> a) (1--2) |> to_list) let () = test [ 1 ] (map_by_2 (fun a _ -> a) (1 -- 2) |> to_list)
let () = test [2] (map_by_2 (fun _ b -> b) (1--2) |> to_list) let () = test [ 2 ] (map_by_2 (fun _ b -> b) (1 -- 2) |> to_list)
(* Test two elements *) (* Test two elements *)
let () = test [1;3;5;7;9] (map_by_2 (fun a _ -> a) (1--10) |> to_list) let () = test [ 1; 3; 5; 7; 9 ] (map_by_2 (fun a _ -> a) (1 -- 10) |> to_list)
let () = test [2;4;6;8;10] (map_by_2 (fun _ b -> b) (1--10) |> to_list) let () = test [ 2; 4; 6; 8; 10 ] (map_by_2 (fun _ b -> b) (1 -- 10) |> to_list)
(* Test more than two elements *) (* Test more than two elements *)