diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-05-11 16:54:38 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-05-11 16:54:38 +0600 |
commit | cfb1d2c4385554325e9e23ab43745d5d8fc4e7e9 (patch) | |
tree | 438057ac909adcb36a633749ec922244d4996e83 | |
parent | f5b79e1f0c86bcd151d41d1dba31bfdf3e84c140 (diff) | |
download | vyconf-cfb1d2c4385554325e9e23ab43745d5d8fc4e7e9.tar.gz vyconf-cfb1d2c4385554325e9e23ab43745d5d8fc4e7e9.zip |
Add vytree insertion load test.
-rw-r--r-- | _oasis | 8 | ||||
-rw-r--r-- | test/vytree_load_test.ml | 56 |
2 files changed, 64 insertions, 0 deletions
@@ -97,6 +97,14 @@ Executable "util_test" Install: false BuildDepends: oUnit, vyconf, xml-light +Executable "vytree_load_test" + Path: test + MainIs: vytree_load_test.ml + Build$: flag(tests) + CompiledObject: best + Install: false + BuildDepends: vyconf + Test "vytree_test" Run$: flag(tests) TestTools: vytree_test diff --git a/test/vytree_load_test.ml b/test/vytree_load_test.ml new file mode 100644 index 0000000..ce85459 --- /dev/null +++ b/test/vytree_load_test.ml @@ -0,0 +1,56 @@ +let max = 9999 + +(* Path length *) +let max_depth = 100 + +(* Number of children *) +let max_children = 1000 + +(* Number of paths *) +let max_paths = 1000 + +let val_of x = + match x with + | Some x -> x + | None -> failwith "No value here" + +let insert_full tree path data = + let rec aux tree path basepath data = + match path with + | [] -> tree + | p :: ps -> + let basepath = basepath @ [p] in + let tree = Vytree.insert tree basepath data in + aux tree ps basepath data + in + let existent_path = Vytree.get_existent_path tree path in + let rest = val_of @@ Vylist.complement path existent_path in + aux tree rest existent_path () + +let rec add_many_children t n basepath data = + if n >= 0 then + let t = Vytree.insert t (basepath @ [(string_of_int n)]) () in + add_many_children t (n - 1) basepath data + else t + +let rec random_path n xs = + if n >= 0 then (string_of_int (Random.int max)) :: (random_path (n-1) xs) + else xs + +let rec do_inserts tree child n = + if n >= 0 then + let p = random_path max_depth [] in + let tree = insert_full tree (child :: p) () in + do_inserts tree child (n - 1) + else tree + +let tree = Vytree.make () "root" + +(* Add a hundred children *) +let tree = add_many_children tree max_children [] () + +(* Use the last child to ensure that the child list is traversed + to the end every time *) +let name = List.nth (Vytree.list_children tree) (max_children - 1) + +let _ = do_inserts tree name max_paths |