Skip to content

Commit

Permalink
test_component not using Random anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
backtracking committed Aug 31, 2023
1 parent d37c5bf commit 4ad137f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
32 changes: 16 additions & 16 deletions tests/dune
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,22 @@

;; Rules for the test_components test

;; (rule
;; (with-stdout-to
;; test_components.output
;; (run ./test_components.exe)))

;; (rule
;; (alias runtest)
;; (action
;; (progn
;; (diff test_components.expected test_components.output)
;; (echo "test_components: all tests succeeded.\n"))))

;; (executable
;; (name test_components)
;; (modules test_components)
;; (libraries graph))
(rule
(with-stdout-to
test_components.output
(run ./test_components.exe)))

(rule
(alias runtest)
(action
(progn
(diff test_components.expected test_components.output)
(echo "test_components: all tests succeeded.\n"))))

(executable
(name test_components)
(modules test_components)
(libraries graph))

;; rules for the dot test

Expand Down
16 changes: 7 additions & 9 deletions tests/test_components.expected
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
7 components
4 components
0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 1
5 -> 1
6 -> 4
7 -> 1
8 -> 5
9 -> 6
2 -> 0
3 -> 2
4 -> 2
5 -> 3
6 -> 2
7 -> 0
21 changes: 11 additions & 10 deletions tests/test_components.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ module C = Components.Undirected(Pack.Graph)

open Pack.Graph

(* FIXME: do not use Random here, as OCaml 5.0 seems to generate a
different graph *)
(* 0 -- 2 -- 7 1 3 -- 4 5
\ /
6
component: 0 1 2 3
*)

let () =
Random.init 42;
let g = Rand.graph ~v:10 ~e:3 () in
let g = create () in
let v = Array.init 8 V.create in
Array.iter (add_vertex g) v;
let add i j = add_edge g v.(i) v.(j) in
add 0 2; add 7 2; add 3 4; add 4 6; add 3 6;
let n, f = C.components g in
printf "%d components@." n;
iter_vertex (fun v -> printf "%d -> %d@." (V.label v) (f v)) g


(*
Local Variables:
compile-command: "ocaml -I .. graph.cma test_components.ml"
End:
*)

0 comments on commit 4ad137f

Please sign in to comment.