summaryrefslogtreecommitdiff
path: root/tp1/graph_test.ml
blob: ac316771d4e75143c442f2a445270439e0606a2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
open Graph

let rec check l = match l with
  | [] | [_] -> true
  | s1::s2::l -> (String.length s1 <= String.length s2) && (check (s2::l))

let test_good () =
  let g = mk_graph () in
  add_node g "1"; add_node g "21"; add_node g "22"; add_node g "333";
  add_edge g "1" "21"; add_edge g "1" "22";
  add_edge g "21" "333"; add_edge g "22" "333";
  let l = topological g in
  print_string "Test: Tri topologique --> ";
  if check l then print_endline "OK" else print_endline "FAIL";
  List.iter print_endline l;
  print_newline ()

let test_cycle () =
  let g = mk_graph () in
  add_node g "1"; add_node g "2"; add_node g "3";
  add_edge g "1" "2"; add_edge g "2" "3"; add_edge g "3" "1";
  print_string "Test: Detection de cycle --> ";
  if has_cycle g then print_endline "OK" else print_endline "FAIL"
;;

test_cycle ();;
test_good ();;