mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
format
This commit is contained in:
parent
afb93cfc43
commit
9bef25b6e2
3 changed files with 147 additions and 161 deletions
|
|
@ -10,10 +10,11 @@ type 'a ktree = unit -> [ `Nil | `Node of 'a * 'a ktree list ]
|
||||||
let[@inline] _iter_map f xs k = xs (fun x -> k (f x))
|
let[@inline] _iter_map f xs k = xs (fun x -> k (f x))
|
||||||
|
|
||||||
let rec _gen_iter k g =
|
let rec _gen_iter k g =
|
||||||
begin match g () with
|
match g () with
|
||||||
| None -> ()
|
| None -> ()
|
||||||
| Some x -> k x; _gen_iter k g
|
| Some x ->
|
||||||
end
|
k x;
|
||||||
|
_gen_iter k g
|
||||||
|
|
||||||
module type PARTIAL_ORD = sig
|
module type PARTIAL_ORD = sig
|
||||||
type t
|
type t
|
||||||
|
|
@ -356,12 +357,10 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
equal to it. *)
|
equal to it. *)
|
||||||
let _merge_heap_iter (hs : t iter) : t =
|
let _merge_heap_iter (hs : t iter) : t =
|
||||||
let rec cons_and_merge h0 hs weights =
|
let rec cons_and_merge h0 hs weights =
|
||||||
begin match hs with
|
match hs with
|
||||||
| h1 :: hs' when weights land 1 = 0 ->
|
| h1 :: hs' when weights land 1 = 0 ->
|
||||||
cons_and_merge (merge h0 h1) hs' (weights lsr 1)
|
cons_and_merge (merge h0 h1) hs' (weights lsr 1)
|
||||||
| _ ->
|
| _ -> h0 :: hs
|
||||||
h0 :: hs
|
|
||||||
end
|
|
||||||
in
|
in
|
||||||
(* the i-th heap in this list is a merger of 2^{w_i} input heaps, each
|
(* the i-th heap in this list is a merger of 2^{w_i} input heaps, each
|
||||||
having gone through w_i merge operations, where the "weights" 2^{w_i} are
|
having gone through w_i merge operations, where the "weights" 2^{w_i} are
|
||||||
|
|
@ -371,19 +370,14 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
input heaps merged so far; adding a heap to the mergers works like binary
|
input heaps merged so far; adding a heap to the mergers works like binary
|
||||||
incrementation: *)
|
incrementation: *)
|
||||||
let count = ref 0 in
|
let count = ref 0 in
|
||||||
hs begin fun h ->
|
hs (fun h ->
|
||||||
incr count ;
|
incr count;
|
||||||
mergers := cons_and_merge h !mergers !count ;
|
mergers := cons_and_merge h !mergers !count);
|
||||||
end ;
|
|
||||||
List.fold_left merge E !mergers
|
List.fold_left merge E !mergers
|
||||||
|
|
||||||
(* To build a heap with n given values, instead of repeated insertions,
|
(* To build a heap with n given values, instead of repeated insertions,
|
||||||
it is more efficient to do pairwise merging, running in time O(n). *)
|
it is more efficient to do pairwise merging, running in time O(n). *)
|
||||||
let of_iter xs =
|
let of_iter xs = xs |> _iter_map singleton |> _merge_heap_iter
|
||||||
xs
|
|
||||||
|> _iter_map singleton
|
|
||||||
|> _merge_heap_iter
|
|
||||||
|
|
||||||
let of_list xs = of_iter (fun k -> List.iter k xs)
|
let of_list xs = of_iter (fun k -> List.iter k xs)
|
||||||
let of_seq xs = of_iter (fun k -> Seq.iter k xs)
|
let of_seq xs = of_iter (fun k -> Seq.iter k xs)
|
||||||
let of_gen xs = of_iter (fun k -> _gen_iter k xs)
|
let of_gen xs = of_iter (fun k -> _gen_iter k xs)
|
||||||
|
|
@ -401,15 +395,12 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
let of_iter_almost_sorted xs =
|
let of_iter_almost_sorted xs =
|
||||||
let sorted_chunk = ref [] in
|
let sorted_chunk = ref [] in
|
||||||
let iter_sorted_heaps k =
|
let iter_sorted_heaps k =
|
||||||
xs begin fun x ->
|
xs (fun x ->
|
||||||
begin match !sorted_chunk with
|
match !sorted_chunk with
|
||||||
| (y :: _) as ys when not (E.leq y x) ->
|
| y :: _ as ys when not (E.leq y x) ->
|
||||||
k (_of_list_rev_sorted ys) ;
|
k (_of_list_rev_sorted ys);
|
||||||
sorted_chunk := [x]
|
sorted_chunk := [ x ]
|
||||||
| ys ->
|
| ys -> sorted_chunk := x :: ys);
|
||||||
sorted_chunk := x :: ys
|
|
||||||
end ;
|
|
||||||
end ;
|
|
||||||
k (_of_list_rev_sorted !sorted_chunk)
|
k (_of_list_rev_sorted !sorted_chunk)
|
||||||
in
|
in
|
||||||
_merge_heap_iter iter_sorted_heaps
|
_merge_heap_iter iter_sorted_heaps
|
||||||
|
|
@ -420,7 +411,6 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
let add_iter h xs = merge h (of_iter xs)
|
let add_iter h xs = merge h (of_iter xs)
|
||||||
let add_seq h xs = merge h (of_seq xs)
|
let add_seq h xs = merge h (of_seq xs)
|
||||||
let add_gen h xs = merge h (of_gen xs)
|
let add_gen h xs = merge h (of_gen xs)
|
||||||
|
|
||||||
let add_iter_almost_sorted h xs = merge h (of_iter_almost_sorted xs)
|
let add_iter_almost_sorted h xs = merge h (of_iter_almost_sorted xs)
|
||||||
|
|
||||||
(** {2 Conversions to sequences} *)
|
(** {2 Conversions to sequences} *)
|
||||||
|
|
@ -494,19 +484,19 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
|
|
||||||
let rec delete_one eq x0 = function
|
let rec delete_one eq x0 = function
|
||||||
| N (_, x, l, r) as h when E.leq x x0 ->
|
| N (_, x, l, r) as h when E.leq x x0 ->
|
||||||
if eq x0 x then
|
if eq x0 x then
|
||||||
merge l r
|
merge l r
|
||||||
else begin
|
else (
|
||||||
let l' = delete_one eq x0 l in
|
let l' = delete_one eq x0 l in
|
||||||
if CCEqual.physical l' l then
|
if CCEqual.physical l' l then (
|
||||||
let r' = delete_one eq x0 r in
|
let r' = delete_one eq x0 r in
|
||||||
if CCEqual.physical r' r then
|
if CCEqual.physical r' r then
|
||||||
h
|
h
|
||||||
else
|
|
||||||
_make_node x l r'
|
|
||||||
else
|
else
|
||||||
_make_node x l' r
|
_make_node x l r'
|
||||||
end
|
) else
|
||||||
|
_make_node x l' r
|
||||||
|
)
|
||||||
| h -> h
|
| h -> h
|
||||||
|
|
||||||
let delete_all eq x0 h =
|
let delete_all eq x0 h =
|
||||||
|
|
@ -524,42 +514,40 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
much smaller than O(n) if k is asymptotically smaller than n.
|
much smaller than O(n) if k is asymptotically smaller than n.
|
||||||
*)
|
*)
|
||||||
let rec iter_subheaps eq x0 h k =
|
let rec iter_subheaps eq x0 h k =
|
||||||
begin match h with
|
match h with
|
||||||
| N (_, x, l, r) when E.leq x x0 ->
|
| N (_, x, l, r) when E.leq x x0 ->
|
||||||
let keep_x = not (eq x0 x) in
|
let keep_x = not (eq x0 x) in
|
||||||
let keep_l = iter_subheaps eq x0 l k in
|
let keep_l = iter_subheaps eq x0 l k in
|
||||||
let keep_r = iter_subheaps eq x0 r k in
|
let keep_r = iter_subheaps eq x0 r k in
|
||||||
if keep_x && keep_l && keep_r then
|
if keep_x && keep_l && keep_r then
|
||||||
true
|
true
|
||||||
else begin
|
else (
|
||||||
if keep_x then k (singleton x) ;
|
if keep_x then k (singleton x);
|
||||||
if keep_l then k l ;
|
if keep_l then k l;
|
||||||
if keep_r then k r ;
|
if keep_r then k r;
|
||||||
false
|
false
|
||||||
end
|
)
|
||||||
| _ -> true
|
| _ -> true
|
||||||
end
|
|
||||||
in
|
in
|
||||||
_merge_heap_iter (fun k -> if iter_subheaps eq x0 h k then k h)
|
_merge_heap_iter (fun k -> if iter_subheaps eq x0 h k then k h)
|
||||||
|
|
||||||
let filter p h =
|
let filter p h =
|
||||||
(* similar to [delete_all] *)
|
(* similar to [delete_all] *)
|
||||||
let rec iter_subheaps p k h =
|
let rec iter_subheaps p k h =
|
||||||
begin match h with
|
match h with
|
||||||
| E -> true
|
| E -> true
|
||||||
| N (_, x, l, r) ->
|
| N (_, x, l, r) ->
|
||||||
let keep_x = p x in
|
let keep_x = p x in
|
||||||
let keep_l = iter_subheaps p k l in
|
let keep_l = iter_subheaps p k l in
|
||||||
let keep_r = iter_subheaps p k r in
|
let keep_r = iter_subheaps p k r in
|
||||||
if keep_x && keep_l && keep_r then
|
if keep_x && keep_l && keep_r then
|
||||||
true
|
true
|
||||||
else begin
|
else (
|
||||||
if keep_x then k (singleton x) ;
|
if keep_x then k (singleton x);
|
||||||
if keep_l then k l ;
|
if keep_l then k l;
|
||||||
if keep_r then k r ;
|
if keep_r then k r;
|
||||||
false
|
false
|
||||||
end
|
)
|
||||||
end
|
|
||||||
in
|
in
|
||||||
_merge_heap_iter (fun k -> if iter_subheaps p k h then k h)
|
_merge_heap_iter (fun k -> if iter_subheaps p k h then k h)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
(tests
|
(tests
|
||||||
(ocamlopt_flags :standard -inline 1000)
|
(ocamlopt_flags :standard -inline 1000)
|
||||||
(names t_reg454)
|
(names t_reg454)
|
||||||
|
|
|
||||||
|
|
@ -8,233 +8,232 @@ include T
|
||||||
* generated by [QCheck.list].
|
* generated by [QCheck.list].
|
||||||
* QCheck defines this generator under the name [nat] but does not expose it. *)
|
* QCheck defines this generator under the name [nat] but does not expose it. *)
|
||||||
let medium_nat =
|
let medium_nat =
|
||||||
Q.make ~print:Q.Print.int ~shrink:Q.Shrink.int ~small:(fun _ -> 1)
|
Q.make ~print:Q.Print.int ~shrink:Q.Shrink.int
|
||||||
|
~small:(fun _ -> 1)
|
||||||
(fun st ->
|
(fun st ->
|
||||||
let p = Random.State.float st 1. in
|
let p = Random.State.float st 1. in
|
||||||
if p < 0.5 then Random.State.int st 10
|
if p < 0.5 then
|
||||||
else if p < 0.75 then Random.State.int st 100
|
Random.State.int st 10
|
||||||
else if p < 0.95 then Random.State.int st 1_000
|
else if p < 0.75 then
|
||||||
else Random.State.int st 10_000
|
Random.State.int st 100
|
||||||
)
|
else if p < 0.95 then
|
||||||
|
Random.State.int st 1_000
|
||||||
|
else
|
||||||
|
Random.State.int st 10_000)
|
||||||
|
|
||||||
let list_delete_first (x0 : int) (xs : int list) : int list =
|
let list_delete_first (x0 : int) (xs : int list) : int list =
|
||||||
let rec aux acc xs =
|
let rec aux acc xs =
|
||||||
begin match xs with
|
match xs with
|
||||||
| [] -> List.rev acc
|
| [] -> List.rev acc
|
||||||
| x :: xs' when x = x0 -> List.rev_append acc xs'
|
| x :: xs' when x = x0 -> List.rev_append acc xs'
|
||||||
| x :: xs' -> aux (x :: acc) xs'
|
| x :: xs' -> aux (x :: acc) xs'
|
||||||
end
|
|
||||||
in
|
in
|
||||||
aux [] xs
|
aux [] xs
|
||||||
|
|
||||||
module H = CCHeap.Make (struct
|
module H = CCHeap.Make (struct
|
||||||
type t = int
|
type t = int
|
||||||
|
|
||||||
let leq x y = x <= y
|
let leq x y = x <= y
|
||||||
end)
|
end)
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t ~name:"of_list, find_min_exn, take_exn" @@ fun () ->
|
t ~name:"of_list, find_min_exn, take_exn" @@ fun () ->
|
||||||
let h = H.of_list [ 5; 4; 3; 4; 1; 42; 0 ] in
|
let h = H.of_list [ 5; 4; 3; 4; 1; 42; 0 ] in
|
||||||
assert_equal ~printer:string_of_int 0 (H.find_min_exn h);
|
assert_equal ~printer:string_of_int 0 (H.find_min_exn h);
|
||||||
let h, x = H.take_exn h in
|
let h, x = H.take_exn h in
|
||||||
assert_equal ~printer:string_of_int 0 x;
|
assert_equal ~printer:string_of_int 0 x;
|
||||||
assert_equal ~printer:string_of_int 1 (H.find_min_exn h);
|
assert_equal ~printer:string_of_int 1 (H.find_min_exn h);
|
||||||
let h, x = H.take_exn h in
|
let h, x = H.take_exn h in
|
||||||
assert_equal ~printer:string_of_int 1 x;
|
assert_equal ~printer:string_of_int 1 x;
|
||||||
assert_equal ~printer:string_of_int 3 (H.find_min_exn h);
|
assert_equal ~printer:string_of_int 3 (H.find_min_exn h);
|
||||||
let h, x = H.take_exn h in
|
let h, x = H.take_exn h in
|
||||||
assert_equal ~printer:string_of_int 3 x;
|
assert_equal ~printer:string_of_int 3 x;
|
||||||
assert_equal ~printer:string_of_int 4 (H.find_min_exn h);
|
assert_equal ~printer:string_of_int 4 (H.find_min_exn h);
|
||||||
let h, x = H.take_exn h in
|
let h, x = H.take_exn h in
|
||||||
assert_equal ~printer:string_of_int 4 x;
|
assert_equal ~printer:string_of_int 4 x;
|
||||||
assert_equal ~printer:string_of_int 4 (H.find_min_exn h);
|
assert_equal ~printer:string_of_int 4 (H.find_min_exn h);
|
||||||
let h, x = H.take_exn h in
|
let h, x = H.take_exn h in
|
||||||
assert_equal ~printer:string_of_int 4 x;
|
assert_equal ~printer:string_of_int 4 x;
|
||||||
assert_equal ~printer:string_of_int 5 (H.find_min_exn h);
|
assert_equal ~printer:string_of_int 5 (H.find_min_exn h);
|
||||||
let h, x = H.take_exn h in
|
let h, x = H.take_exn h in
|
||||||
assert_equal ~printer:string_of_int 5 x;
|
assert_equal ~printer:string_of_int 5 x;
|
||||||
assert_equal ~printer:string_of_int 42 (H.find_min_exn h);
|
assert_equal ~printer:string_of_int 42 (H.find_min_exn h);
|
||||||
let h, x = H.take_exn h in
|
let h, x = H.take_exn h in
|
||||||
assert_equal ~printer:string_of_int 42 x;
|
assert_equal ~printer:string_of_int 42 x;
|
||||||
assert_raises ((=) H.Empty) (fun () -> H.find_min_exn h);
|
assert_raises (( = ) H.Empty) (fun () -> H.find_min_exn h);
|
||||||
assert_raises ((=) H.Empty) (fun () -> H.take_exn h);
|
assert_raises (( = ) H.Empty) (fun () -> H.take_exn h);
|
||||||
true
|
true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"of_list, to_list"
|
q ~name:"of_list, to_list" ~count:30
|
||||||
~count:30
|
|
||||||
Q.(list medium_nat)
|
Q.(list medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> H.of_list |> H.to_list |> List.sort CCInt.compare)
|
l |> H.of_list |> H.to_list |> List.sort CCInt.compare
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"of_list, to_list_sorted"
|
q ~name:"of_list, to_list_sorted" ~count:30
|
||||||
~count:30
|
|
||||||
Q.(list medium_nat)
|
Q.(list medium_nat)
|
||||||
(fun l ->
|
(fun l -> l |> H.of_list |> H.to_list_sorted = (l |> List.sort CCInt.compare))
|
||||||
(l |> H.of_list |> H.to_list_sorted)
|
|
||||||
= (l |> List.sort CCInt.compare))
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(* The remaining tests assume the correctness of
|
(* The remaining tests assume the correctness of
|
||||||
[of_list], [to_list], [to_list_sorted]. *)
|
[of_list], [to_list], [to_list_sorted]. *)
|
||||||
|
|
||||||
q ~name:"size"
|
q ~name:"size" ~count:30
|
||||||
~count:30
|
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l -> l |> H.of_list |> H.size = (l |> List.length))
|
||||||
(l |> H.of_list |> H.size)
|
|
||||||
= (l |> List.length))
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"insert"
|
q ~name:"insert"
|
||||||
Q.(pair medium_nat (list medium_nat))
|
Q.(pair medium_nat (list medium_nat))
|
||||||
(fun (x, l) ->
|
(fun (x, l) ->
|
||||||
(l |> H.of_list |> H.insert x |> H.to_list_sorted)
|
l |> H.of_list |> H.insert x |> H.to_list_sorted
|
||||||
= ((x::l) |> List.sort CCInt.compare))
|
= (x :: l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"merge"
|
q ~name:"merge"
|
||||||
Q.(pair (list medium_nat) (list medium_nat))
|
Q.(pair (list medium_nat) (list medium_nat))
|
||||||
(fun (l1, l2) ->
|
(fun (l1, l2) ->
|
||||||
(H.merge (H.of_list l1) (H.of_list l2) |> H.to_list_sorted)
|
H.merge (H.of_list l1) (H.of_list l2)
|
||||||
= ((l1@l2) |> List.sort CCInt.compare))
|
|> H.to_list_sorted
|
||||||
|
= (l1 @ l2 |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"add_list"
|
q ~name:"add_list"
|
||||||
Q.(pair (list medium_nat) (list medium_nat))
|
Q.(pair (list medium_nat) (list medium_nat))
|
||||||
(fun (l1, l2) ->
|
(fun (l1, l2) ->
|
||||||
(H.add_list (H.of_list l1) l2 |> H.to_list_sorted)
|
H.add_list (H.of_list l1) l2
|
||||||
= ((l1@l2) |> List.sort CCInt.compare))
|
|> H.to_list_sorted
|
||||||
|
= (l1 @ l2 |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"delete_one"
|
q ~name:"delete_one"
|
||||||
Q.(pair medium_nat (list medium_nat))
|
Q.(pair medium_nat (list medium_nat))
|
||||||
(fun (x, l) ->
|
(fun (x, l) ->
|
||||||
(l |> H.of_list |> H.delete_one (=) x |> H.to_list_sorted)
|
l |> H.of_list |> H.delete_one ( = ) x |> H.to_list_sorted
|
||||||
= (l |> list_delete_first x |> List.sort CCInt.compare))
|
= (l |> list_delete_first x |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"delete_all"
|
q ~name:"delete_all"
|
||||||
Q.(pair medium_nat (list medium_nat))
|
Q.(pair medium_nat (list medium_nat))
|
||||||
(fun (x, l) ->
|
(fun (x, l) ->
|
||||||
(l |> H.of_list |> H.delete_all (=) x |> H.to_list_sorted)
|
l |> H.of_list |> H.delete_all ( = ) x |> H.to_list_sorted
|
||||||
= (l |> List.filter ((<>) x) |> List.sort CCInt.compare))
|
= (l |> List.filter (( <> ) x) |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"filter"
|
q ~name:"filter"
|
||||||
Q.(list medium_nat)
|
Q.(list medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
let p = (fun x -> x mod 2 = 0) in
|
let p x = x mod 2 = 0 in
|
||||||
let l' = l |> H.of_list |> H.filter p |> H.to_list in
|
let l' = l |> H.of_list |> H.filter p |> H.to_list in
|
||||||
List.for_all p l' && List.length l' = List.length (List.filter p l))
|
List.for_all p l' && List.length l' = List.length (List.filter p l))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t ~name:"physical equality" @@ fun () ->
|
t ~name:"physical equality" @@ fun () ->
|
||||||
let h = H.of_list [ 5; 4; 3; 4; 1; 42; 0 ] in
|
let h = H.of_list [ 5; 4; 3; 4; 1; 42; 0 ] in
|
||||||
assert_bool "physical equality of merge with left empty"
|
assert_bool "physical equality of merge with left empty"
|
||||||
(CCEqual.physical h (H.merge H.empty h)) ;
|
(CCEqual.physical h (H.merge H.empty h));
|
||||||
assert_bool "physical equality of merge with right empty"
|
assert_bool "physical equality of merge with right empty"
|
||||||
(CCEqual.physical h (H.merge h H.empty)) ;
|
(CCEqual.physical h (H.merge h H.empty));
|
||||||
assert_bool "physical equality of delete_one with element lesser than min"
|
assert_bool "physical equality of delete_one with element lesser than min"
|
||||||
(CCEqual.physical h (H.delete_one (=) (-999) h)) ;
|
(CCEqual.physical h (H.delete_one ( = ) (-999) h));
|
||||||
assert_bool "physical equality of delete_one with element between min and max"
|
assert_bool "physical equality of delete_one with element between min and max"
|
||||||
(CCEqual.physical h (H.delete_one (=) 2 h)) ;
|
(CCEqual.physical h (H.delete_one ( = ) 2 h));
|
||||||
assert_bool "physical equality of delete_one with element greater than max"
|
assert_bool "physical equality of delete_one with element greater than max"
|
||||||
(CCEqual.physical h (H.delete_one (=) 999 h)) ;
|
(CCEqual.physical h (H.delete_one ( = ) 999 h));
|
||||||
assert_bool "physical equality of delete_all with element lesser than min"
|
assert_bool "physical equality of delete_all with element lesser than min"
|
||||||
(CCEqual.physical h (H.delete_all (=) (-999) h)) ;
|
(CCEqual.physical h (H.delete_all ( = ) (-999) h));
|
||||||
assert_bool "physical equality of delete_all with element between min and max"
|
assert_bool "physical equality of delete_all with element between min and max"
|
||||||
(CCEqual.physical h (H.delete_all (=) 2 h)) ;
|
(CCEqual.physical h (H.delete_all ( = ) 2 h));
|
||||||
assert_bool "physical equality of delete_all with element greater than max"
|
assert_bool "physical equality of delete_all with element greater than max"
|
||||||
(CCEqual.physical h (H.delete_all (=) 999 h)) ;
|
(CCEqual.physical h (H.delete_all ( = ) 999 h));
|
||||||
assert_bool "physical equality of filter"
|
assert_bool "physical equality of filter"
|
||||||
(CCEqual.physical h (H.filter (fun _ -> true) h)) ;
|
(CCEqual.physical h (H.filter (fun _ -> true) h));
|
||||||
true
|
true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"fold"
|
q ~name:"fold"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l -> l |> H.of_list |> H.fold ( + ) 0 = (l |> List.fold_left ( + ) 0))
|
||||||
(l |> H.of_list |> H.fold (+) 0)
|
|
||||||
= (l |> List.fold_left (+) 0))
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"of_iter"
|
q ~name:"of_iter"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> CCList.to_iter |> H.of_iter |> H.to_list_sorted)
|
l |> CCList.to_iter |> H.of_iter |> H.to_list_sorted
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"of_seq"
|
q ~name:"of_seq"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> CCList.to_seq |> H.of_seq |> H.to_list_sorted)
|
l |> CCList.to_seq |> H.of_seq |> H.to_list_sorted
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"of_gen"
|
q ~name:"of_gen"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> CCList.to_gen |> H.of_gen |> H.to_list_sorted)
|
l |> CCList.to_gen |> H.of_gen |> H.to_list_sorted
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"to_iter"
|
q ~name:"to_iter"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> H.of_list |> H.to_iter |> CCList.of_iter |> List.sort CCInt.compare)
|
l |> H.of_list |> H.to_iter |> CCList.of_iter |> List.sort CCInt.compare
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"to_seq"
|
q ~name:"to_seq"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> H.of_list |> H.to_seq |> CCList.of_seq |> List.sort CCInt.compare)
|
l |> H.of_list |> H.to_seq |> CCList.of_seq |> List.sort CCInt.compare
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"to_gen"
|
q ~name:"to_gen"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> H.of_list |> H.to_gen |> CCList.of_gen |> List.sort CCInt.compare)
|
l |> H.of_list |> H.to_gen |> CCList.of_gen |> List.sort CCInt.compare
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"to_iter_sorted"
|
q ~name:"to_iter_sorted"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> H.of_list |> H.to_iter_sorted |> Iter.to_list)
|
l |> H.of_list |> H.to_iter_sorted |> Iter.to_list
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"to_seq_sorted"
|
q ~name:"to_seq_sorted"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> H.of_list |> H.to_seq_sorted |> CCList.of_seq |> List.sort CCInt.compare)
|
l |> H.of_list |> H.to_seq_sorted |> CCList.of_seq
|
||||||
|
|> List.sort CCInt.compare
|
||||||
= (l |> List.sort CCInt.compare))
|
= (l |> List.sort CCInt.compare))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"to_string with default sep"
|
q ~name:"to_string with default sep"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> H.of_list |> H.to_string string_of_int)
|
l |> H.of_list |> H.to_string string_of_int
|
||||||
= (l |> List.sort CCInt.compare |> List.map string_of_int |> String.concat ","))
|
= (l |> List.sort CCInt.compare |> List.map string_of_int
|
||||||
|
|> String.concat ","))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"to_string with space as sep"
|
q ~name:"to_string with space as sep"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
(l |> H.of_list |> H.to_string ~sep:" " string_of_int)
|
l |> H.of_list
|
||||||
= (l |> List.sort CCInt.compare |> List.map string_of_int |> String.concat " "))
|
|> H.to_string ~sep:" " string_of_int
|
||||||
|
= (l |> List.sort CCInt.compare |> List.map string_of_int
|
||||||
|
|> String.concat " "))
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~name:"Make_from_compare"
|
q ~name:"Make_from_compare"
|
||||||
Q.(list_of_size Gen.small_nat medium_nat)
|
Q.(list_of_size Gen.small_nat medium_nat)
|
||||||
(fun l ->
|
(fun l ->
|
||||||
let module H' = Make_from_compare (CCInt) in
|
let module H' = Make_from_compare (CCInt) in
|
||||||
(l |> H'.of_list |> H'.to_list_sorted)
|
l |> H'.of_list |> H'.to_list_sorted = (l |> List.sort CCInt.compare))
|
||||||
= (l |> List.sort CCInt.compare))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue