Guest User

Untitled

a guest
Jul 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. open Printf
  2. open OUnit
  3.  
  4. module OrderedInt = struct
  5. type t = int
  6. let compare = compare
  7. end
  8.  
  9. module G = Graph.Make (OrderedInt)
  10. module DSL = Graph.MakeDSL (G)
  11.  
  12. open DSL
  13.  
  14. let test_graph _ =
  15. let g = (G.empty false) +> (1, 2) +> (1, 5) +> (1, 6)
  16. +> (2, 5) +> (2, 3) +> (3, 4)
  17. +> (5, 4) in
  18. let parent = G.bfs 1 g in
  19. assert_equal ~msg:"parent(2)" (Hashtbl.find parent 2) 1 ;
  20. assert_equal ~msg:"parent(3)" (Hashtbl.find parent 3) 2 ;
  21. assert_equal ~msg:"parent(4)" (Hashtbl.find parent 4) 5 ;
  22. assert_equal ~msg:"parent(5)" (Hashtbl.find parent 5) 1 ;
  23. assert_equal ~msg:"parent(6)" (Hashtbl.find parent 6) 1
  24.  
  25. let suite = "Graph" >::: [
  26. "graph" >:: test_graph
  27. ]
  28.  
  29. let _ = run_test_tt_main suite
Add Comment
Please, Sign In to add comment