mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
cleanup
This commit is contained in:
parent
f699f48586
commit
507fe33086
6 changed files with 1 additions and 843 deletions
3
Makefile
3
Makefile
|
|
@ -130,7 +130,6 @@ clean-generated:
|
|||
|
||||
run-test: build
|
||||
./run_qtest.native
|
||||
./run_tests.native
|
||||
|
||||
test-all: run-test
|
||||
|
||||
|
|
@ -145,7 +144,7 @@ update_next_tag:
|
|||
zsh -c 'sed -i "s/NEXT_RELEASE/$(VERSION)/g" **/*.ml **/*.mli'
|
||||
|
||||
devel:
|
||||
./configure --enable-bench --enable-tests --enable-misc --enable-unix \
|
||||
./configure --enable-bench --enable-tests --enable-unix \
|
||||
--enable-bigarray --enable-thread --enable-advanced
|
||||
make all
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
(** Some helpers for tests *)
|
||||
|
||||
let print_int_list l =
|
||||
let b = Buffer.create 20 in
|
||||
CCList.pp CCInt.pp b l;
|
||||
Buffer.contents b
|
||||
|
||||
let print_int_int_list l =
|
||||
let b = Buffer.create 20 in
|
||||
CCList.pp (CCPair.pp CCInt.pp CCInt.pp) b l;
|
||||
Buffer.contents b
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
open OUnit
|
||||
|
||||
let suite =
|
||||
"all_tests" >:::
|
||||
[ Test_pHashtbl.suite;
|
||||
Test_puf.suite;
|
||||
Test_univ.suite;
|
||||
Test_RoseTree.suite;
|
||||
]
|
||||
|
||||
let () =
|
||||
ignore (run_test_tt_main suite);
|
||||
()
|
||||
|
|
@ -1,599 +0,0 @@
|
|||
open OUnit
|
||||
open CCFun
|
||||
|
||||
module RoseTree = Containers_misc.RoseTree
|
||||
|
||||
let format_node = Format.pp_print_int
|
||||
|
||||
let string_of_tree tree =
|
||||
CCFormat.sprintf "%a" (RoseTree.print format_node) tree
|
||||
|
||||
let assert_equal_tree expected_tree_rep tree =
|
||||
let expected_tree_rep_string =
|
||||
(String.concat "\n" expected_tree_rep) ^ "\n"
|
||||
in
|
||||
let tree_as_string = string_of_tree tree in
|
||||
assert_equal ~printer:(fun x -> x) expected_tree_rep_string tree_as_string
|
||||
|
||||
let assert_equal_zipper expected_tree_rep zipper =
|
||||
assert_equal_tree expected_tree_rep (RoseTree.Zipper.tree zipper)
|
||||
|
||||
let single_node_tree = `Node (10, [])
|
||||
|
||||
let single_tree_strings = ["10"]
|
||||
|
||||
let normal_tree =
|
||||
`Node (0, [
|
||||
`Node (1, [
|
||||
`Node (10, []) ;
|
||||
]) ;
|
||||
`Node (2, [
|
||||
`Node (20, []) ;
|
||||
`Node (21, []) ;
|
||||
]) ;
|
||||
`Node (3, [
|
||||
`Node (30, []) ;
|
||||
`Node (31, []) ;
|
||||
`Node (32, []) ;
|
||||
]) ;
|
||||
])
|
||||
|
||||
let normal_tree_strings = [
|
||||
"0" ;
|
||||
"|- 1" ;
|
||||
"| '- 10" ;
|
||||
"|- 2" ;
|
||||
"| |- 20" ;
|
||||
"| '- 21" ;
|
||||
"'- 3" ;
|
||||
" |- 30" ;
|
||||
" |- 31" ;
|
||||
" '- 32" ;
|
||||
]
|
||||
|
||||
let new_tree =
|
||||
`Node (100, [
|
||||
`Node (1000, [
|
||||
`Node (10000, []) ;
|
||||
]) ;
|
||||
`Node (1001, [
|
||||
`Node (10010, []) ;
|
||||
`Node (10012, []) ;
|
||||
]) ;
|
||||
])
|
||||
|
||||
let new_tree_strings = [
|
||||
"100" ;
|
||||
"|- 1000" ;
|
||||
"| '- 10000" ;
|
||||
"'- 1001" ;
|
||||
" |- 10010" ;
|
||||
" '- 10012" ;
|
||||
]
|
||||
|
||||
let test_print_single_node_tree () =
|
||||
let expected = single_tree_strings in
|
||||
assert_equal_tree expected single_node_tree
|
||||
|
||||
let test_print_normal_tree () =
|
||||
let expected = normal_tree_strings in
|
||||
assert_equal_tree expected normal_tree
|
||||
|
||||
let test_fold_single_node_tree () =
|
||||
let tree_double_sum = RoseTree.fold ~f:(fun value acc -> acc + value * 2) 0 single_node_tree
|
||||
in
|
||||
assert_equal 20 tree_double_sum
|
||||
|
||||
let test_fold_normal_tree () =
|
||||
let tree_sum = RoseTree.fold ~f:(fun value acc -> acc + value) 0 normal_tree
|
||||
in
|
||||
assert_equal 150 tree_sum
|
||||
|
||||
let test_base_zipper_single_node_tree () =
|
||||
let expected = single_tree_strings in
|
||||
assert_equal_zipper expected (RoseTree.Zipper.zipper single_node_tree)
|
||||
|
||||
let test_base_zipper_normal_tree () =
|
||||
let expected = normal_tree_strings in
|
||||
assert_equal_zipper expected (RoseTree.Zipper.zipper normal_tree)
|
||||
|
||||
let test_zipper_nth_child_0 () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"1" ;
|
||||
"'- 10" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_nth_child_1 () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 1
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"2" ;
|
||||
"|- 20" ;
|
||||
"'- 21" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_nth_child_2 () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 2
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"3" ;
|
||||
"|- 30" ;
|
||||
"|- 31" ;
|
||||
"'- 32" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_nth_child_does_not_exist () =
|
||||
let maybe_zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 3
|
||||
in
|
||||
assert_equal false (CCOpt.is_some maybe_zipper)
|
||||
|
||||
let test_zipper_nth_child_negative_index () =
|
||||
let maybe_zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child (-2)
|
||||
in
|
||||
assert_equal false (CCOpt.is_some maybe_zipper)
|
||||
|
||||
let test_zipper_nth_child_plus_parent_is_noop () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 2
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.parent
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = normal_tree_strings in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_left_sibling () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 2
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.left_sibling
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"2" ;
|
||||
"|- 20" ;
|
||||
"'- 21" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_left_sibling_twice () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 2
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.left_sibling
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.left_sibling
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"1" ;
|
||||
"'- 10" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_left_sibling_does_not_exist () =
|
||||
let maybe_zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 2
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.left_sibling
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.left_sibling
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.left_sibling
|
||||
in
|
||||
assert_equal false (CCOpt.is_some maybe_zipper)
|
||||
|
||||
let test_zipper_nth_child_plus_left_sibling_plus_parent_is_noop () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 2
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.left_sibling
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.parent
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = normal_tree_strings in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_right_sibling () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.right_sibling
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"2" ;
|
||||
"|- 20" ;
|
||||
"'- 21" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_right_sibling_twice () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.right_sibling
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.right_sibling
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"3" ;
|
||||
"|- 30" ;
|
||||
"|- 31" ;
|
||||
"'- 32" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_zipper_right_sibling_does_not_exist () =
|
||||
let maybe_zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.right_sibling
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.right_sibling
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.right_sibling
|
||||
in
|
||||
assert_equal false (CCOpt.is_some maybe_zipper)
|
||||
|
||||
let test_zipper_nth_child_plus_right_sibling_plus_parent_is_noop () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.right_sibling
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.parent
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = normal_tree_strings in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_parent () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.parent
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"1" ;
|
||||
"'- 10" ;
|
||||
] in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_parent_on_root () =
|
||||
let maybe_zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.parent
|
||||
in
|
||||
assert_equal false (CCOpt.is_some maybe_zipper)
|
||||
|
||||
let test_root () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.root
|
||||
in
|
||||
let expected = normal_tree_strings in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_root_on_root () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.root
|
||||
in
|
||||
let expected = normal_tree_strings in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_insert_left_sibling () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.insert_left_sibling new_tree
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.root
|
||||
in
|
||||
let expected = [
|
||||
"0" ;
|
||||
"|- 1" ;
|
||||
"| |- 100" ;
|
||||
"| | |- 1000" ;
|
||||
"| | | '- 10000" ;
|
||||
"| | '- 1001" ;
|
||||
"| | |- 10010" ;
|
||||
"| | '- 10012" ;
|
||||
"| '- 10" ;
|
||||
"|- 2" ;
|
||||
"| |- 20" ;
|
||||
"| '- 21" ;
|
||||
"'- 3" ;
|
||||
" |- 30" ;
|
||||
" |- 31" ;
|
||||
" '- 32" ;
|
||||
] in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_insert_left_sibling_focuses_on_new_tree () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.insert_left_sibling new_tree
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = new_tree_strings
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_insert_left_sibling_on_root () =
|
||||
let maybe_zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.insert_left_sibling new_tree
|
||||
in
|
||||
assert_equal false (CCOpt.is_some maybe_zipper)
|
||||
|
||||
let test_insert_right_sibling () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.insert_right_sibling new_tree
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.root
|
||||
in
|
||||
let expected = [
|
||||
"0" ;
|
||||
"|- 1" ;
|
||||
"| |- 10" ;
|
||||
"| '- 100" ;
|
||||
"| |- 1000" ;
|
||||
"| | '- 10000" ;
|
||||
"| '- 1001" ;
|
||||
"| |- 10010" ;
|
||||
"| '- 10012" ;
|
||||
"|- 2" ;
|
||||
"| |- 20" ;
|
||||
"| '- 21" ;
|
||||
"'- 3" ;
|
||||
" |- 30" ;
|
||||
" |- 31" ;
|
||||
" '- 32" ;
|
||||
] in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_insert_right_sibling_focuses_on_new_tree () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.insert_right_sibling new_tree
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = new_tree_strings
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_insert_right_sibling_on_root () =
|
||||
let maybe_zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.insert_right_sibling new_tree
|
||||
in
|
||||
assert_equal false (CCOpt.is_some maybe_zipper)
|
||||
|
||||
let test_append_child () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 2
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.append_child new_tree
|
||||
|> RoseTree.Zipper.root
|
||||
in
|
||||
let expected = [
|
||||
"0" ;
|
||||
"|- 1" ;
|
||||
"| '- 10" ;
|
||||
"|- 2" ;
|
||||
"| |- 20" ;
|
||||
"| '- 21" ;
|
||||
"'- 3" ;
|
||||
" |- 30" ;
|
||||
" |- 31" ;
|
||||
" |- 32" ;
|
||||
" '- 100" ;
|
||||
" |- 1000" ;
|
||||
" | '- 10000" ;
|
||||
" '- 1001" ;
|
||||
" |- 10010" ;
|
||||
" '- 10012" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_append_child_focuses_on_new_tree () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 2
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.append_child new_tree
|
||||
in
|
||||
let expected = new_tree_strings
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_replace () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 1
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.replace new_tree
|
||||
|> RoseTree.Zipper.root
|
||||
in
|
||||
let expected = [
|
||||
"0" ;
|
||||
"|- 1" ;
|
||||
"| '- 10" ;
|
||||
"|- 100" ;
|
||||
"| |- 1000" ;
|
||||
"| | '- 10000" ;
|
||||
"| '- 1001" ;
|
||||
"| |- 10010" ;
|
||||
"| '- 10012" ;
|
||||
"'- 3" ;
|
||||
" |- 30" ;
|
||||
" |- 31" ;
|
||||
" '- 32" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_replace_focuses_on_new_tree () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 1
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.replace new_tree
|
||||
in
|
||||
let expected = new_tree_strings in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_replace_root () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.replace new_tree
|
||||
in
|
||||
let expected = new_tree_strings in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_delete () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 1
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.delete
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.root
|
||||
in
|
||||
let expected = [
|
||||
"0" ;
|
||||
"|- 1" ;
|
||||
"| '- 10" ;
|
||||
"'- 3" ;
|
||||
" |- 30" ;
|
||||
" |- 31" ;
|
||||
" '- 32" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_delete_focuses_on_leftmost_sibling_if_possible () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 1
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.delete
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"1" ;
|
||||
"'- 10" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_delete_focuses_on_rightmost_sibling_if_no_left_sibling () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.delete
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = [
|
||||
"2" ;
|
||||
"|- 20" ;
|
||||
"'- 21" ;
|
||||
]
|
||||
in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_delete_focuses_on_parent_if_no_more_siblings () =
|
||||
let zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.nth_child 0
|
||||
|> CCOpt.get_exn
|
||||
|> RoseTree.Zipper.delete
|
||||
|> CCOpt.get_exn
|
||||
in
|
||||
let expected = ["1"] in
|
||||
assert_equal_zipper expected zipper
|
||||
|
||||
let test_delete_root () =
|
||||
let maybe_zipper = RoseTree.Zipper.zipper normal_tree
|
||||
|> RoseTree.Zipper.delete
|
||||
in
|
||||
assert_equal false (CCOpt.is_some maybe_zipper)
|
||||
|
||||
let suite =
|
||||
"test_RoseTree" >:::
|
||||
[
|
||||
"test_print_single_node_tree" >:: test_print_single_node_tree ;
|
||||
"test_print_normal_tree" >:: test_print_normal_tree ;
|
||||
"test_fold_single_node_tree" >:: test_fold_single_node_tree ;
|
||||
"test_fold_normal_tree" >:: test_fold_normal_tree ;
|
||||
"test_base_zipper_single_node_tree" >:: test_base_zipper_single_node_tree ;
|
||||
"test_base_zipper_normal_tree" >:: test_base_zipper_normal_tree ;
|
||||
"test_zipper_nth_child_0" >:: test_zipper_nth_child_0 ;
|
||||
"test_zipper_nth_child_1" >:: test_zipper_nth_child_1 ;
|
||||
"test_zipper_nth_child_2" >:: test_zipper_nth_child_2 ;
|
||||
"test_zipper_nth_child_does_not_exist" >:: test_zipper_nth_child_does_not_exist ;
|
||||
"test_zipper_nth_child_negative_index" >:: test_zipper_nth_child_negative_index ;
|
||||
"test_zipper_nth_child_plus_parent_is_noop" >:: test_zipper_nth_child_plus_parent_is_noop ;
|
||||
"test_zipper_left_sibling" >:: test_zipper_left_sibling ;
|
||||
"test_zipper_left_sibling_twice" >:: test_zipper_left_sibling_twice ;
|
||||
"test_zipper_left_sibling_does_not_exist" >:: test_zipper_left_sibling_does_not_exist ;
|
||||
"test_zipper_nth_child_plus_left_sibling_plus_parent_is_noop" >:: test_zipper_nth_child_plus_left_sibling_plus_parent_is_noop ;
|
||||
"test_zipper_right_sibling" >:: test_zipper_right_sibling ;
|
||||
"test_zipper_right_sibling_twice" >:: test_zipper_right_sibling_twice ;
|
||||
"test_zipper_right_sibling_does_not_exist" >:: test_zipper_right_sibling_does_not_exist ;
|
||||
"test_zipper_nth_child_plus_right_sibling_plus_parent_is_noop" >:: test_zipper_nth_child_plus_right_sibling_plus_parent_is_noop ;
|
||||
"test_parent" >:: test_parent ;
|
||||
"test_parent_on_root" >:: test_parent_on_root ;
|
||||
"test_root" >:: test_root ;
|
||||
"test_root_on_root" >:: test_root_on_root ;
|
||||
"test_insert_left_sibling" >:: test_insert_left_sibling ;
|
||||
"test_insert_left_sibling_focuses_on_new_tree" >:: test_insert_left_sibling_focuses_on_new_tree ;
|
||||
"test_insert_left_sibling_on_root" >:: test_insert_left_sibling_on_root ;
|
||||
"test_insert_right_sibling" >:: test_insert_right_sibling ;
|
||||
"test_insert_right_sibling_focuses_on_new_tree" >:: test_insert_right_sibling_focuses_on_new_tree ;
|
||||
"test_insert_right_sibling_on_root" >:: test_insert_right_sibling_on_root ;
|
||||
"test_append_child" >:: test_append_child ;
|
||||
"test_append_child_focuses_on_new_tree" >:: test_append_child_focuses_on_new_tree ;
|
||||
"test_replace" >:: test_replace ;
|
||||
"test_replace_focuses_on_new_tree" >:: test_replace_focuses_on_new_tree ;
|
||||
"test_replace_root" >:: test_replace_root ;
|
||||
"test_delete" >:: test_delete ;
|
||||
"test_delete_focuses_on_leftmost_sibling_if_possible" >:: test_delete_focuses_on_leftmost_sibling_if_possible ;
|
||||
"test_delete_focuses_on_rightmost_sibling_if_no_left_sibling" >:: test_delete_focuses_on_rightmost_sibling_if_no_left_sibling ;
|
||||
"test_delete_focuses_on_parent_if_no_more_siblings" >:: test_delete_focuses_on_parent_if_no_more_siblings ;
|
||||
"test_delete_root" >:: test_delete_root ;
|
||||
]
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
|
||||
open OUnit
|
||||
open Containers_misc
|
||||
|
||||
|
||||
|
||||
let test_add () =
|
||||
let h = PHashtbl.create 5 in
|
||||
PHashtbl.replace h 42 "foo";
|
||||
OUnit.assert_equal (PHashtbl.find h 42) "foo"
|
||||
|
||||
let my_list =
|
||||
[ 1, "a";
|
||||
2, "b";
|
||||
3, "c";
|
||||
4, "d";
|
||||
]
|
||||
|
||||
let my_seq = Sequence.of_list my_list
|
||||
|
||||
let test_of_seq () =
|
||||
let h = PHashtbl.create 5 in
|
||||
PHashtbl.of_seq h my_seq;
|
||||
OUnit.assert_equal (PHashtbl.find h 2) "b";
|
||||
OUnit.assert_equal (PHashtbl.find h 1) "a";
|
||||
OUnit.assert_raises Not_found (fun () -> PHashtbl.find h 42);
|
||||
()
|
||||
|
||||
let test_to_seq () =
|
||||
let h = PHashtbl.create 5 in
|
||||
PHashtbl.of_seq h my_seq;
|
||||
let l = Sequence.to_list (PHashtbl.to_seq h) in
|
||||
OUnit.assert_equal my_list (List.sort compare l)
|
||||
|
||||
let test_resize () =
|
||||
let h = PHashtbl.create 5 in
|
||||
for i = 0 to 10 do
|
||||
PHashtbl.add h i (string_of_int i);
|
||||
done;
|
||||
OUnit.assert_bool "must have been resized" (PHashtbl.length h > 5);
|
||||
()
|
||||
|
||||
let test_eq () =
|
||||
let h = PHashtbl.create 3
|
||||
~eq:(fun x y -> x mod 2 = y mod 2)
|
||||
~hash:(fun i -> i mod 2) in
|
||||
PHashtbl.add h 1 "odd";
|
||||
PHashtbl.add h 2 "even";
|
||||
OUnit.assert_equal (PHashtbl.find h 3) "odd";
|
||||
OUnit.assert_equal (PHashtbl.find h 51) "odd";
|
||||
OUnit.assert_equal (PHashtbl.find h 42) "even";
|
||||
()
|
||||
|
||||
let test_copy () =
|
||||
let h = PHashtbl.create 2 in
|
||||
PHashtbl.add h 1 "one";
|
||||
OUnit.assert_equal (PHashtbl.find h 1) "one";
|
||||
OUnit.assert_raises Not_found (fun () -> PHashtbl.find h 2);
|
||||
let h' = PHashtbl.copy h in
|
||||
PHashtbl.add h' 2 "two";
|
||||
OUnit.assert_equal (PHashtbl.find h' 1) "one";
|
||||
OUnit.assert_equal (PHashtbl.find h' 2) "two";
|
||||
OUnit.assert_equal (PHashtbl.find h 1) "one";
|
||||
OUnit.assert_raises Not_found (fun () -> PHashtbl.find h 2);
|
||||
()
|
||||
|
||||
let test_remove () =
|
||||
let h = PHashtbl.create 3 in
|
||||
PHashtbl.of_seq h my_seq;
|
||||
OUnit.assert_equal (PHashtbl.find h 2) "b";
|
||||
OUnit.assert_equal (PHashtbl.find h 3) "c";
|
||||
OUnit.assert_equal (PHashtbl.find h 4) "d";
|
||||
OUnit.assert_equal (PHashtbl.length h) 4;
|
||||
PHashtbl.remove h 2;
|
||||
OUnit.assert_equal (PHashtbl.find h 3) "c";
|
||||
OUnit.assert_equal (PHashtbl.length h) 3;
|
||||
(* test that 2 has been removed *)
|
||||
OUnit.assert_raises Not_found (fun () -> PHashtbl.find h 2)
|
||||
|
||||
let test_filter () =
|
||||
let h = PHashtbl.create 5 in
|
||||
PHashtbl.of_seq h my_seq;
|
||||
OUnit.assert_equal (PHashtbl.length h) 4;
|
||||
PHashtbl.filter (fun k _ -> (k mod 2) = 0) h;
|
||||
OUnit.assert_equal (PHashtbl.length h) 2;
|
||||
OUnit.assert_bool "4 mem" (PHashtbl.mem h 4);
|
||||
OUnit.assert_bool "2 mem" (PHashtbl.mem h 2);
|
||||
OUnit.assert_bool "1 not mem" (not (PHashtbl.mem h 1));
|
||||
OUnit.assert_bool "3 not mem" (not (PHashtbl.mem h 3));
|
||||
()
|
||||
|
||||
let test_map () =
|
||||
let h = PHashtbl.create 5 in
|
||||
PHashtbl.of_seq h my_seq;
|
||||
OUnit.assert_equal (PHashtbl.length h) 4;
|
||||
let h' = PHashtbl.map (fun k v -> String.uppercase v) h in
|
||||
OUnit.assert_equal (PHashtbl.length h') 4;
|
||||
OUnit.assert_equal (PHashtbl.find h' 1) "A";
|
||||
OUnit.assert_equal (PHashtbl.find h' 2) "B";
|
||||
OUnit.assert_equal (PHashtbl.find h' 3) "C";
|
||||
OUnit.assert_equal (PHashtbl.find h' 4) "D"
|
||||
|
||||
let suite =
|
||||
"test_pHashtbl" >:::
|
||||
[ "test_add" >:: test_add;
|
||||
"test_of_seq" >:: test_of_seq;
|
||||
"test_to_seq" >:: test_to_seq;
|
||||
"test_resize" >:: test_resize;
|
||||
"test_eq" >:: test_eq;
|
||||
"test_copy" >:: test_copy;
|
||||
"test_remove" >:: test_remove;
|
||||
"test_filter" >:: test_filter;
|
||||
"test_map" >:: test_map;
|
||||
]
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
(** Tests for persistent union find *)
|
||||
|
||||
open OUnit
|
||||
open Containers_misc
|
||||
|
||||
module P = Puf.Make(struct type t = int let get_id i = i end)
|
||||
|
||||
let rec merge_list uf l = match l with
|
||||
| [] | [_] -> uf
|
||||
| x::((y::_) as l') ->
|
||||
merge_list (P.union uf x y (x,y)) l'
|
||||
|
||||
let test_union () =
|
||||
let uf = P.create 5 in
|
||||
let uf = merge_list uf [1;2;3] in
|
||||
let uf = merge_list uf [5;6] in
|
||||
OUnit.assert_equal (P.find uf 1) (P.find uf 2);
|
||||
OUnit.assert_equal (P.find uf 1) (P.find uf 3);
|
||||
OUnit.assert_equal (P.find uf 5) (P.find uf 6);
|
||||
OUnit.assert_bool "noteq" ((P.find uf 1) <> (P.find uf 5));
|
||||
OUnit.assert_equal 10 (P.find uf 10);
|
||||
let uf = P.union uf 1 5 (1,5) in
|
||||
OUnit.assert_equal (P.find uf 2) (P.find uf 6);
|
||||
()
|
||||
|
||||
let test_iter () =
|
||||
let uf = P.create 5 in
|
||||
let uf = merge_list uf [1;2;3] in
|
||||
let uf = merge_list uf [5;6] in
|
||||
let uf = merge_list uf [10;11;12;13;2] in
|
||||
(* equiv classes *)
|
||||
let l1 = ref [] in
|
||||
P.iter_equiv_class uf 1 (fun x -> l1 := x:: !l1);
|
||||
let l2 = ref [] in
|
||||
P.iter_equiv_class uf 5 (fun x -> l2 := x:: !l2);
|
||||
OUnit.assert_equal [1;2;3;10;11;12;13] (List.sort compare !l1);
|
||||
OUnit.assert_equal [5;6] (List.sort compare !l2);
|
||||
()
|
||||
|
||||
let test_distinct () =
|
||||
let uf = P.create 5 in
|
||||
let uf = merge_list uf [1;2;3] in
|
||||
let uf = merge_list uf [5;6] in
|
||||
let uf = P.distinct uf 1 5 in
|
||||
OUnit.assert_equal None (P.inconsistent uf);
|
||||
let uf' = P.union uf 2 6 (2,6) in
|
||||
OUnit.assert_bool "inconsistent"
|
||||
(match P.inconsistent uf' with | None -> false | Some _ -> true);
|
||||
OUnit.assert_equal None (P.inconsistent uf);
|
||||
let uf = P.union uf 1 10 (1,10) in
|
||||
OUnit.assert_equal None (P.inconsistent uf);
|
||||
()
|
||||
|
||||
let test_big () =
|
||||
let uf = P.create 5 in
|
||||
let uf = ref uf in
|
||||
for i = 0 to 100_000 do
|
||||
uf := P.union !uf 1 i (1,i);
|
||||
done;
|
||||
let uf = !uf in
|
||||
let n = P.fold_equiv_class uf 1 (fun acc _ -> acc+1) 0 in
|
||||
OUnit.assert_equal ~printer:string_of_int 100_001 n;
|
||||
()
|
||||
|
||||
let test_explain () =
|
||||
let uf = P.create 5 in
|
||||
let uf = P.union uf 1 2 (1,2) in
|
||||
let uf = P.union uf 1 3 (1,3) in
|
||||
let uf = P.union uf 5 6 (5,6) in
|
||||
let uf = P.union uf 4 5 (4,5) in
|
||||
let uf = P.union uf 5 3 (5,3) in
|
||||
OUnit.assert_bool "eq" (P.find uf 1 = P.find uf 5);
|
||||
let l = P.explain uf 1 6 in
|
||||
OUnit.assert_bool "not empty explanation" (l <> []);
|
||||
(* List.iter (fun (a,b) -> Format.printf "%d, %d@." a b) l; *)
|
||||
()
|
||||
|
||||
(*
|
||||
let bench () =
|
||||
let run n =
|
||||
let uf = P.create 5 in
|
||||
let uf = ref uf in
|
||||
for i = 0 to n do
|
||||
uf := P.union !uf 1 i;
|
||||
done
|
||||
in
|
||||
let res = Bench.bench_args run
|
||||
[ "100", 100;
|
||||
"10_000", 10_000;
|
||||
]
|
||||
in Bench.summarize 1. res;
|
||||
()
|
||||
*)
|
||||
|
||||
let suite =
|
||||
"test_puf" >:::
|
||||
[ "test_union" >:: test_union;
|
||||
"test_iter" >:: test_iter;
|
||||
"test_distinct" >:: test_distinct;
|
||||
"test_big" >:: test_big;
|
||||
"test_explain" >:: test_explain;
|
||||
(* "bench" >:: bench; *)
|
||||
]
|
||||
Loading…
Add table
Reference in a new issue