<commit_before>open OUnit2
open Vytree

(* Destructuting a freshly made node gives us what
   we made it from *)
let test_make_node test_ctxt =
    let node = make "root" () in
    assert_equal (name_of_node node) "root";
    assert_equal (data_of_node node) ();
    assert_equal (children_of_node node) []

(* XXX: these comparisons are awkward, but this is
        probably the only way to track the problem
        down to insert if insert breaks *)

(* Inserting at single-item path adds a child to
   children list *)
let test_insert_immediate_child test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    assert_equal (children_of_node node')
                 [make "foo" ()]

(* Inserting one child after another adds it to the
   end of the children list *)
let test_insert_multiple_children test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    let node'' = insert_child () node' ["bar"] () in
    assert_equal (children_of_node node'')
                 [make "foo" (); make "bar" ()]

(* Inserting a child at a two-item path creates a tree
   two levels deep *)
let test_insert_multi_level test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"; "bar"] () in
    let bar = make "bar" () in
    let foo = make_full "foo" () [bar] in
    let root = make_full "root" () [foo] in
    assert_equal root node'

(* Inserting duplicate child fails *)
let test_insert_duplicate_child test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    assert_raises Duplicate_child (fun () -> insert_child () node' ["foo"] ())

(* list_children correctly returns a list of children names *)
let test_list_children test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    let node'' = insert_child () node' ["bar"] () in
    assert_equal (list_children node'') ["foo"; "bar"]

let suite =
    "VyConf tree tests" >::: [
        "test_make_node" >:: test_make_node;
        "test_insert_immediate_child" >:: test_insert_immediate_child;
        "test_insert_multiple_children" >:: test_insert_multiple_children;
        "test_insert_multi_level" >:: test_insert_multi_level;
        "test_insert_duplicate_child" >:: test_insert_duplicate_child;
        "test_list_children" >:: test_list_children;
    ]

let () =
  run_test_tt_main suite

<commit_msg>Add some tests for delete_child.<commit_after>open OUnit2
open Vytree

(* Destructuting a freshly made node gives us what
   we made it from *)
let test_make_node test_ctxt =
    let node = make "root" () in
    assert_equal (name_of_node node) "root";
    assert_equal (data_of_node node) ();
    assert_equal (children_of_node node) []

(* XXX: these comparisons are awkward, but this is
        probably the only way to track the problem
        down to insert if insert breaks *)

(* Inserting at single-item path adds a child to
   children list *)
let test_insert_immediate_child test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    assert_equal (children_of_node node')
                 [make "foo" ()]

(* Inserting one child after another adds it to the
   end of the children list *)
let test_insert_multiple_children test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    let node'' = insert_child () node' ["bar"] () in
    assert_equal (children_of_node node'')
                 [make "foo" (); make "bar" ()]

(* Inserting a child at a two-item path creates a tree
   two levels deep *)
let test_insert_multi_level test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"; "bar"] () in
    let bar = make "bar" () in
    let foo = make_full "foo" () [bar] in
    let root = make_full "root" () [foo] in
    assert_equal root node'

(* Inserting duplicate child fails *)
let test_insert_duplicate_child test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    assert_raises Duplicate_child (fun () -> insert_child () node' ["foo"] ())

(* list_children correctly returns a list of children names *)
let test_list_children test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    let node'' = insert_child () node' ["bar"] () in
    assert_equal (list_children node'') ["foo"; "bar"]

(* Deleting a child, well, deletes it *)
let test_delete_immediate_child test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"] () in
    let node'' = delete_child node' ["foo"] in
    assert_equal node node''

(* Deleting a child at multi-level path works *)
let test_delete_multi_level test_ctxt =
    let node = make "root" () in
    let node' = insert_child () node ["foo"; "bar"] () in
    let foo_node = insert_child () node ["foo"] () in
    let node'' = delete_child node' ["foo"; "bar"] in
    assert_equal node'' foo_node

let suite =
    "VyConf tree tests" >::: [
        "test_make_node" >:: test_make_node;
        "test_insert_immediate_child" >:: test_insert_immediate_child;
        "test_insert_multiple_children" >:: test_insert_multiple_children;
        "test_insert_multi_level" >:: test_insert_multi_level;
        "test_insert_duplicate_child" >:: test_insert_duplicate_child;
        "test_list_children" >:: test_list_children;
        "test_delete_immediate_child" >:: test_delete_immediate_child;
        "test_delete_multi_level" >:: test_delete_multi_level
    ]

let () =
  run_test_tt_main suite


{'fraction_non_alphanumeric': 0.11561721807186055, 'fraction_numerical': 0.0003557452863749555, 'mean_word_length': 3.4101960784313725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '780531', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1750, 'n_words': 577}