mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
updated tests , with tests on heaps
This commit is contained in:
parent
fc590bfb27
commit
2e19b5eb1a
2 changed files with 32 additions and 2 deletions
|
|
@ -2,11 +2,41 @@
|
||||||
|
|
||||||
open OUnit
|
open OUnit
|
||||||
|
|
||||||
|
let print_int_list l =
|
||||||
|
let b = Buffer.create 20 in
|
||||||
|
Format.bprintf b "@[<h>[%a]@]"
|
||||||
|
(Sequence.pp_seq ~sep:", " Format.pp_print_int)
|
||||||
|
(Sequence.of_list l);
|
||||||
|
Buffer.contents b
|
||||||
|
|
||||||
let test_empty () =
|
let test_empty () =
|
||||||
let h = Heap.empty ~compare:(fun x y -> x - y) in
|
let h = Heap.empty ~cmp:(fun x y -> x - y) in
|
||||||
OUnit.assert_bool "is_empty empty" (Heap.is_empty h)
|
OUnit.assert_bool "is_empty empty" (Heap.is_empty h)
|
||||||
|
|
||||||
|
let test_sort () =
|
||||||
|
let h = Heap.empty ~cmp:(fun x y -> x - y) in
|
||||||
|
(* Heap sort *)
|
||||||
|
let l = [3;4;2;1;6;5;0;7;10;9;8] in
|
||||||
|
Heap.of_seq h (Sequence.of_list l);
|
||||||
|
let l' = Sequence.to_list (Heap.to_seq h) in
|
||||||
|
OUnit.assert_equal ~printer:print_int_list l' [0;1;2;3;4;5;6;7;8;9;10]
|
||||||
|
|
||||||
|
let test_remove () =
|
||||||
|
let h = Heap.empty ~cmp:(fun x y -> x - y) in
|
||||||
|
let l = [3;4;2;1;6;5;0;7;10;9;8] in
|
||||||
|
Heap.of_seq h (Sequence.of_list l);
|
||||||
|
(* check pop *)
|
||||||
|
OUnit.assert_equal (Heap.pop h) 0;
|
||||||
|
OUnit.assert_equal (Heap.pop h) 1;
|
||||||
|
OUnit.assert_equal (Heap.pop h) 2;
|
||||||
|
OUnit.assert_equal (Heap.pop h) 3;
|
||||||
|
(* check that elements have been removed *)
|
||||||
|
let l' = Sequence.to_list (Heap.to_seq h) in
|
||||||
|
OUnit.assert_equal ~printer:print_int_list l' [4;5;6;7;8;9;10]
|
||||||
|
|
||||||
let suite =
|
let suite =
|
||||||
"test_heaps" >:::
|
"test_heaps" >:::
|
||||||
[ "test_empty" >:: test_empty;
|
[ "test_empty" >:: test_empty;
|
||||||
|
"test_sort" >:: test_sort;
|
||||||
|
"test_remove" >:: test_remove;
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ open OUnit
|
||||||
let suite =
|
let suite =
|
||||||
"all_tests" >:::
|
"all_tests" >:::
|
||||||
[ Test_pHashtbl.suite;
|
[ Test_pHashtbl.suite;
|
||||||
(* Test_heap.suite; *)
|
Test_heap.suite;
|
||||||
]
|
]
|
||||||
|
|
||||||
let _ =
|
let _ =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue