Commits

Anonymous committed 87ed488

+ trie tests

Comments (0)

Files changed (1)

 value trie_test_env () =
   let module Tree = Cd.Sfun.Tree(Int) in
   let the_empty = new Cd.Sfun.trie [] (new Tree.map_rw_tree) in
+  let ex1 = (the_empty#add [1;2] "1;2")#add [1;3;4] "1;3;4" in
+  let ex2 = ex1#remove [1;2] in
+  let ex3 = ex1#add [1] "1" in
+  let ex4 = ex2#add [1;3;4] "1;3;4 new" in
+  let ex5 = ex4#replace [1;3;4] "1;3;4 very new" in
   object
-    method the_empty = the_empty
-    ;
-    method ex1 = (the_empty#add [1;2] "1;2")#add [1;3;4] "1;3;4"
-    ;
+    method the_empty = the_empty;
+    method ex1 = ex1;
+    method ex2 = ex2;
+    method ex3 = ex3;
+    method ex4 = ex4;
+    method ex5 = ex5;
   end
 ;
 
     )
 ;
 
+value trie_test3 () =
+  let s = List.sort Pervasives.compare in
+  assert_equal
+    ~printer:printer_list_string
+    ( (trie_test_env ())#ex2 |>
+      string_of_int_string_trie |> s
+    )
+    ( [ "1/3/4 => 1;3;4" ] |> s
+    )
+;
 
-(*
-trie_test2
-trie_test3
-*)
+value trie_test4 () =
+  let s = List.sort Pervasives.compare in
+  assert_equal
+    ~printer:printer_list_string
+    ( (trie_test_env ())#ex3 |>
+      string_of_int_string_trie |> s
+    )
+    ( [ "1/3/4 => 1;3;4" ; "1/2 => 1;2" ; "1 => 1" ] |> s
+    )
+;
+
+value trie_test5 () =
+  assert_equal
+    ~printer:printer_list_string
+    ( (trie_test_env ())#ex4 |>
+      string_of_int_string_trie
+    )
+    ( [ "1/3/4 => 1;3;4" ; "1/3/4 => 1;3;4 new" ]
+    )
+;
+
+value trie_test6 () =
+  assert_equal
+    ( (trie_test_env ())#ex4#get_opt [1;3;4]
+    )
+    ( Some "1;3;4 new"
+    )
+;
+
+value trie_test7 () =
+  assert_equal
+    ~printer:printer_list_string
+    ( (trie_test_env ())#ex5 |>
+      string_of_int_string_trie
+    )
+    ( [ "1/3/4 => 1;3;4" ; "1/3/4 => 1;3;4 very new" ]
+    )
+;
 
 
 value suite = 
   "trie" >:::
     [ "trie_test1" >:: trie_test1
     ; "trie_test2" >:: trie_test2
+    ; "trie_test3" >:: trie_test3
+    ; "trie_test4" >:: trie_test4
+    ; "trie_test5" >:: trie_test5
+    ; "trie_test6" >:: trie_test6
+    ; "trie_test7" >:: trie_test7
     ]
 ;