Skip to content

Commit

Permalink
chore: move to ounit2
Browse files Browse the repository at this point in the history
see if that fixes the windows build.
  • Loading branch information
c-cube committed Jun 10, 2022
1 parent 977e0c9 commit 58ac755
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 151 deletions.
2 changes: 1 addition & 1 deletion containers.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ depends: [
"either" # compat
"qtest" { with-test }
"qcheck" { >= "0.14" & with-test }
"ounit" { with-test }
"ounit2" { with-test }
"iter" { with-test }
"gen" { with-test }
"csexp" { with-test }
Expand Down
18 changes: 9 additions & 9 deletions src/core/CCHeap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ end
(*$R
let h = H.of_list [5;3;4;1;42;0] in
let h, x = H.take_exn h in
OUnit.assert_equal ~printer:string_of_int 0 x;
OUnit2.assert_equal ~printer:string_of_int 0 x;
let h, x = H.take_exn h in
OUnit.assert_equal ~printer:string_of_int 1 x;
OUnit2.assert_equal ~printer:string_of_int 1 x;
let h, x = H.take_exn h in
OUnit.assert_equal ~printer:string_of_int 3 x;
OUnit2.assert_equal ~printer:string_of_int 3 x;
let h, x = H.take_exn h in
OUnit.assert_equal ~printer:string_of_int 4 x;
OUnit2.assert_equal ~printer:string_of_int 4 x;
let h, x = H.take_exn h in
OUnit.assert_equal ~printer:string_of_int 5 x;
OUnit2.assert_equal ~printer:string_of_int 5 x;
let h, x = H.take_exn h in
OUnit.assert_equal ~printer:string_of_int 42 x;
OUnit.assert_raises H.Empty (fun () -> H.take_exn h);
OUnit2.assert_equal ~printer:string_of_int 42 x;
OUnit2.assert_raises H.Empty (fun () -> H.take_exn h);
*)

(*$QR & ~count:30
Q.(list_of_size Gen.(return 1_000) int) (fun l ->
(* put elements into a heap *)
let h = H.of_iter (Iter.of_list l) in
OUnit.assert_equal 1_000 (H.size h);
OUnit2.assert_equal 1_000 (H.size h);
let l' = extract_list h in
is_sorted l'
)
Expand All @@ -70,7 +70,7 @@ end
(* put elements into a heap *)
let h = H.of_iter (Iter.of_list l) in
let h = H.filter (fun x->x mod 2=0) h in
OUnit.assert_bool "all odd"
OUnit2.assert_bool "all odd"
(H.to_iter h |> Iter.for_all (fun x -> x mod 2 = 0));
let l' = extract_list h in
is_sorted l'
Expand Down
39 changes: 22 additions & 17 deletions src/core/CCIO.ml
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,14 @@ let read_all ?(size=1024) ic = read_all_ ~op:Ret_string ~size ic
(*$R
let s = String.make 200 'y' in
let s = Printf.sprintf "a\nb\n %s\nlast line\n" s in
OUnit.bracket_tmpfile ~prefix:"test_containers" ~mode:[Open_creat; Open_trunc]
(fun (name, oc) ->
File.with_temp ~prefix:"test_containers" ~suffix:""
(fun name ->
with_out name @@ fun oc ->
output_string oc s;
flush oc;
let s' = with_in name read_all in
OUnit.assert_equal ~printer:(fun s->s) s s'
) ()
OUnit2.assert_equal ~printer:(fun s->s) s s'
)
*)


Expand Down Expand Up @@ -237,25 +238,27 @@ let write_lines_l oc l =
(*$QR
Q.(list_of_size Gen.(0 -- 40) printable_string) (fun l ->
let l' = ref [] in
OUnit.bracket_tmpfile ~prefix:"test_containers" ~mode:[Open_creat; Open_trunc]
(fun (name, oc) ->
File.with_temp ~prefix:"test_containers" ~suffix:""
(fun name ->
with_out name @@ fun oc ->
write_lines_l oc l;
flush oc;
l' := with_in name read_lines_l;
) ();
);
String.concat "\n" l = String.concat "\n" !l'
)
*)

(*$QR
Q.(list_of_size Gen.(0 -- 40) printable_string) (fun l ->
let l' = ref [] in
OUnit.bracket_tmpfile ~prefix:"test_containers" ~mode:[Open_creat; Open_trunc]
(fun (name, oc) ->
File.with_temp ~prefix:"test_containers" ~suffix:""
(fun name ->
with_out name @@ fun oc ->
write_lines oc (Gen.of_list l);
flush oc;
l' := with_in name (fun ic -> read_lines_gen ic |> Gen.to_list);
) ();
);
String.concat "\n" l = String.concat "\n" !l'
)
*)
Expand Down Expand Up @@ -288,16 +291,18 @@ let copy_into ?(bufsize=4_096) ic oc : unit =
(*$QR
Q.(list_of_size Gen.(0 -- 40) printable_string) (fun l ->
let s = ref "" in
OUnit.bracket_tmpfile ~prefix:"test_containers1" ~mode:[Open_creat; Open_trunc]
(fun (name1, oc1) ->
File.with_temp ~prefix:"test_containers1" ~suffix:""
(fun name1 ->
with_out name1 @@ fun oc1 ->
write_gen ~sep:"" oc1 (Gen.of_list l);
flush oc1;
OUnit.bracket_tmpfile ~prefix:"test_containers2" ~mode:[Open_creat; Open_trunc]
(fun (name2, oc2) ->
File.with_temp ~prefix:"test_containers2" ~suffix:""
(fun name2 ->
with_out name2 @@ fun oc2 ->
CCIO.with_in name1 (fun ic1 -> copy_into ic1 oc2);
flush oc2;
s := with_in name2 read_all;) ();
) ();
s := with_in name2 read_all;);
);
String.concat "" l = !s
)
*)
Expand Down Expand Up @@ -390,7 +395,7 @@ module File = struct
else gen_singleton (`File, d)

(*$R
OUnit.assert_bool "walk categorizes files"
OUnit2.assert_bool "walk categorizes files"
(File.walk "."
|> Gen.for_all
(function
Expand Down
2 changes: 1 addition & 1 deletion src/core/CCList.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ let join ~join_row s1 s2 : _ t =
if string_of_int i = j then Some (string_of_int i ^ " = " ^ j) else None
in
let s = join ~join_row s1 s2 in
OUnit.assert_equal ["1 = 1"; "2 = 2"] s;
OUnit2.assert_equal ["1 = 1"; "2 = 2"] s;
*)

let join_by (type a) ?(eq=Stdlib.(=)) ?(hash=Hashtbl.hash) f1 f2 ~merge c1 c2 =
Expand Down
26 changes: 13 additions & 13 deletions src/core/CCVector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ let[@inline] clear v =

(*$R
let v = of_iter Iter.(1 -- 10) in
OUnit.assert_equal 10 (size v);
OUnit2.assert_equal 10 (size v);
clear v;
OUnit.assert_equal 0 (size v);
OUnit.assert_bool "empty_after_clear" (Iter.is_empty (to_iter v));
OUnit2.assert_equal 0 (size v);
OUnit2.assert_bool "empty_after_clear" (Iter.is_empty (to_iter v));
*)

let clear_and_reset v =
Expand All @@ -187,9 +187,9 @@ let clear_and_reset v =
push v ("hello"^"world");
Weak.set a 0 (Some (get v 0));
Gc.full_major(); Gc.compact();
OUnit.assert_bool "is alive" (Weak.check a 0);
OUnit2.assert_bool "is alive" (Weak.check a 0);
Gc.full_major(); Gc.compact();
OUnit.assert_equal None (Weak.get a 0);
OUnit2.assert_equal None (Weak.get a 0);
*)

let[@inline] is_empty v = v.size = 0
Expand Down Expand Up @@ -295,9 +295,9 @@ let append a b =
let a = of_iter Iter.(1 -- 5) in
let b = of_iter Iter.(6 -- 10) in
append a b;
OUnit.assert_equal 10 (size a);
OUnit.assert_equal (Iter.to_array Iter.(1 -- 10)) (to_array a);
OUnit.assert_equal (Iter.to_array Iter.(6 -- 10)) (to_array b);
OUnit2.assert_equal 10 (size a);
OUnit2.assert_equal (Iter.to_array Iter.(1 -- 10)) (to_array a);
OUnit2.assert_equal (Iter.to_array Iter.(6 -- 10)) (to_array b);
*)

let[@inline] get v i =
Expand Down Expand Up @@ -525,12 +525,12 @@ let[@inline] copy v = {

(*$R
let v = of_iter Iter.(1 -- 100) in
OUnit.assert_equal 100 (size v);
OUnit2.assert_equal 100 (size v);
let v' = copy v in
OUnit.assert_equal 100 (size v');
OUnit2.assert_equal 100 (size v');
clear v';
OUnit.assert_bool "empty" (is_empty v');
OUnit.assert_bool "not_empty" (not (is_empty v));
OUnit2.assert_bool "empty" (is_empty v');
OUnit2.assert_bool "not_empty" (not (is_empty v));
*)

(*$QR
Expand All @@ -551,7 +551,7 @@ let truncate v n =
(*$R
let v = of_iter Iter.(1 -- 10) in
truncate v 5;
OUnit.assert_equal [1;2;3;4;5] (to_list v);
OUnit2.assert_equal [1;2;3;4;5] (to_list v);
*)

(*$QR
Expand Down
32 changes: 16 additions & 16 deletions src/data/CCDeque.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ let peek_front d = match peek_front_opt d with
(*$R
let d = of_iter Iter.(1 -- 10) in
let printer = pint in
OUnit.assert_equal ~printer 1 (peek_front d);
OUnit2.assert_equal ~printer 1 (peek_front d);
push_front d 42;
OUnit.assert_equal ~printer 42 (peek_front d);
OUnit.assert_equal ~printer 42 (take_front d);
OUnit.assert_equal ~printer 1 (take_front d);
OUnit.assert_equal ~printer 2 (take_front d);
OUnit.assert_equal ~printer 3 (take_front d);
OUnit.assert_equal ~printer 10 (peek_back d);
OUnit2.assert_equal ~printer 42 (peek_front d);
OUnit2.assert_equal ~printer 42 (take_front d);
OUnit2.assert_equal ~printer 1 (take_front d);
OUnit2.assert_equal ~printer 2 (take_front d);
OUnit2.assert_equal ~printer 3 (take_front d);
OUnit2.assert_equal ~printer 10 (peek_back d);
*)

let peek_back_opt d =
Expand All @@ -159,14 +159,14 @@ let peek_back d = match peek_back_opt d with
(*$R
let d = of_iter Iter.(1 -- 10) in
let printer = pint in
OUnit.assert_equal ~printer 1 (peek_front d);
OUnit2.assert_equal ~printer 1 (peek_front d);
push_back d 42;
OUnit.assert_equal ~printer 42 (peek_back d);
OUnit.assert_equal ~printer 42 (take_back d);
OUnit.assert_equal ~printer 10 (take_back d);
OUnit.assert_equal ~printer 9 (take_back d);
OUnit.assert_equal ~printer 8 (take_back d);
OUnit.assert_equal ~printer 1 (peek_front d);
OUnit2.assert_equal ~printer 42 (peek_back d);
OUnit2.assert_equal ~printer 42 (take_back d);
OUnit2.assert_equal ~printer 10 (take_back d);
OUnit2.assert_equal ~printer 9 (take_back d);
OUnit2.assert_equal ~printer 8 (take_back d);
OUnit2.assert_equal ~printer 1 (peek_front d);
*)

let take_back_node_ n = match n.cell with
Expand Down Expand Up @@ -365,7 +365,7 @@ let iter f d =
let d = of_iter Iter.(1 -- 5) in
let s = Iter.from_iter (fun k -> iter k d) in
let l = Iter.to_list s in
OUnit.assert_equal ~printer:plist [1;2;3;4;5] l;
OUnit2.assert_equal ~printer:plist [1;2;3;4;5] l;
*)

let append_front ~into q = iter (push_front into) q
Expand Down Expand Up @@ -411,7 +411,7 @@ let length d = d.size

(*$R
let d = of_iter Iter.(1 -- 10) in
OUnit.assert_equal ~printer:pint 10 (length d)
OUnit2.assert_equal ~printer:pint 10 (length d)
*)

type 'a iter = ('a -> unit) -> unit
Expand Down
14 changes: 7 additions & 7 deletions src/data/CCFQueue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let empty : type a. a t = Shallow Zero

(*$R
let q = empty in
OUnit.assert_bool "is_empty" (is_empty q)
OUnit2.assert_bool "is_empty" (is_empty q)
*)

exception Empty
Expand Down Expand Up @@ -95,7 +95,7 @@ let rec snoc : type a. a t -> a -> a t
let q = tail q in
let q = List.fold_left snoc q [6;7;8] in
let l = Iter.to_list (to_iter q) in
OUnit.assert_equal ~printer:pp_ilist [2;3;4;5;6;7;8] l
OUnit2.assert_equal ~printer:pp_ilist [2;3;4;5;6;7;8] l
*)

let rec take_front_exn : 'a. 'a t -> ('a *'a t)
Expand Down Expand Up @@ -124,11 +124,11 @@ let rec take_front_exn : 'a. 'a t -> ('a *'a t)
(*$R
let q = of_list [1;2;3;4] in
let x, q = take_front_exn q in
OUnit.assert_equal 1 x;
OUnit2.assert_equal 1 x;
let q = List.fold_left snoc q [5;6;7] in
OUnit.assert_equal 2 (first_exn q);
OUnit2.assert_equal 2 (first_exn q);
let x, q = take_front_exn q in
OUnit.assert_equal 2 x;
OUnit2.assert_equal 2 x;
*)

let take_front q =
Expand Down Expand Up @@ -363,7 +363,7 @@ let append q1 q2 =
let q2 = of_iter (Iter.of_list [5;6;7;8]) in
let q = append q1 q2 in
let l = Iter.to_list (to_iter q) in
OUnit.assert_equal ~printer:pp_ilist [1;2;3;4;5;6;7;8] l
OUnit2.assert_equal ~printer:pp_ilist [1;2;3;4;5;6;7;8] l
*)

let add_seq_front seq q =
Expand Down Expand Up @@ -443,7 +443,7 @@ let rec fold : 'a 'b. ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
(*$R
let q = of_iter (Iter.of_list [1;2;3;4]) in
let n = fold (+) 0 q in
OUnit.assert_equal 10 n;
OUnit2.assert_equal 10 n;
*)

let iter f q = to_iter q f
Expand Down
Loading

0 comments on commit 58ac755

Please sign in to comment.