fix(list): add the test sorted_diff (sorted_merge l1 l2) l2 = l1

Also fixed a typo.
This commit is contained in:
favonia 2021-05-22 21:41:36 -05:00
parent c030beaf52
commit e58c5d8f3b
3 changed files with 11 additions and 3 deletions

View file

@ -771,6 +771,10 @@ let sorted_diff ~cmp l1 l2 =
Q.(triple small_nat small_nat int) (fun (n1,n2,x) -> \ Q.(triple small_nat small_nat int) (fun (n1,n2,x) -> \
let l = sorted_diff ~cmp:CCInt.compare (CCList.init n1 (fun _ -> x)) (CCList.init n2 (fun _ -> x)) in \ let l = sorted_diff ~cmp:CCInt.compare (CCList.init n1 (fun _ -> x)) (CCList.init n2 (fun _ -> x)) in \
count (CCInt.equal x) l = CCInt.max (n1 - n2) 0) count (CCInt.equal x) l = CCInt.max (n1 - n2) 0)
Q.(pair (list small_int) (list small_int)) (fun (l1,l2) -> \
let l1 = List.sort CCInt.compare l1 in \
let l2 = List.sort CCInt.compare l2 in \
l1 = sorted_diff ~cmp:CCInt.compare (sorted_merge ~cmp:CCInt.compare l1 l2) l2)
*) *)
let sort_uniq ~cmp l = List.sort_uniq cmp l let sort_uniq ~cmp l = List.sort_uniq cmp l

View file

@ -504,7 +504,9 @@ val sorted_merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
val sorted_diff : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list val sorted_diff : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
(** [sorted_diff ~cmp l1 l2] returns the elements in [l1] that are not in [l2]. (** [sorted_diff ~cmp l1 l2] returns the elements in [l1] that are not in [l2].
Both lists are assumed to be sorted with respect to [cmp] and Both lists are assumed to be sorted with respect to [cmp] and
duplicate elements are treated individually. duplicate elements are treated individually. It is the left inverse of
[sorted_merge]; that is, [sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2]
is always equal to [l1] for sorted lists [l1] and [l2].
@since NEXT_RELEASE *) @since NEXT_RELEASE *)
val sort_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list val sort_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list

View file

@ -505,9 +505,11 @@ val sorted_merge : cmp:(('a -> 'a -> int) [@keep_label]) -> 'a list -> 'a list -
the given comparison function [cmp]. *) the given comparison function [cmp]. *)
val sorted_diff : cmp:(('a -> 'a -> int) [@keep_label]) -> 'a list -> 'a list -> 'a list val sorted_diff : cmp:(('a -> 'a -> int) [@keep_label]) -> 'a list -> 'a list -> 'a list
(** [sorted_merge ~cmp l1 l2] returns the elements in [l1] that are not in [l2]. (** [sorted_diff ~cmp l1 l2] returns the elements in [l1] that are not in [l2].
Both lists are assumed to be sorted with respect to [cmp] and Both lists are assumed to be sorted with respect to [cmp] and
duplicate elements are treated individually. duplicate elements are treated individually. It is the left inverse of
[sorted_merge]; that is, [sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2]
is always equal to [l1] for sorted lists [l1] and [l2].
@since NEXT_RELEASE *) @since NEXT_RELEASE *)
val sort_uniq : cmp:(('a -> 'a -> int) [@keep_label]) -> 'a list -> 'a list val sort_uniq : cmp:(('a -> 'a -> int) [@keep_label]) -> 'a list -> 'a list