From 609d51c89e4764c0cbd422e0b172de57d5e02141 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 4 Jul 2017 16:24:54 +0200 Subject: [PATCH] bugfix in `CCList.split` --- src/core/CCList.ml | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/core/CCList.ml b/src/core/CCList.ml index fcc7a546..f044884c 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -389,44 +389,32 @@ let combine_gen l1 l2 = let split l = let rec direct i l = match l with - | [] -> ([],[]) + | [] -> [], [] | [x1, y1] -> [x1], [y1] | [x1, y1; x2, y2] -> [x1;x2], [y1;y2] | [x1, y1; x2, y2; x3, y3] -> [x1;x2;x3], [y1;y2;y3] | [x1, y1; x2, y2; x3, y3; x4, y4] -> [x1;x2;x3;x4], [y1;y2;y3;y4] - | _ when i=0 -> split_slow ([], []) l - | (x1, y1) :: - (x2, y2) :: - (x3, y3) :: - (x4, y4) :: - (x5, y5) :: l' -> + | _ when i=0 -> split_slow [] [] l + | (x1, y1) :: (x2, y2) :: (x3, y3) :: (x4, y4) :: (x5, y5) :: l' -> let rx, ry = direct (i-1) l' in x1 :: x2 :: x3 :: x4 :: x5 :: rx, y1 :: y2 :: y3 :: y4 :: y5 :: ry - and split_slow acc l = match l with - | [] -> acc - | (x1, y1) :: l' -> - let acc = x1 :: fst acc, y1 :: snd acc in - split_slow acc l' + and split_slow acc1 acc2 l = match l with + | [] -> List.rev acc1, List.rev acc2 + | (x1, x2) :: tail -> + let acc1 = x1 :: acc1 + and acc2 = x2 :: acc2 in + split_slow acc1 acc2 tail in direct direct_depth_default_ l (*$Q - (Q.(list (pair int string))) (fun l -> \ + (Q.(list_of_size Gen.(0--10_000) (pair small_int small_string))) (fun l -> \ let (l1, l2) = split l in \ List.length l1 = List.length l \ && List.length l2 = List.length l) - (Q.(list (pair string int))) (fun l -> \ - let l = ("hello", 10) :: l in \ - let (l1, l2) = split l in \ - let i = Random.int @@ List.length l in \ - let l1_x = List.nth l1 i in \ - let l2_y = List.nth l2 i in \ - let (x,y) = List.nth l i in \ - l1_x = x && l2_y = y) - - Q.(list (pair int int)) (fun l -> \ + Q.(list_of_size Gen.(0--10_000) (pair small_int small_int)) (fun l -> \ split l = List.split l) *)