mostly maintenance in maintaining internal conventions... a few more tests as well
[cl-graph.git] / unit-tests / tests-in-progress.lisp
1 (in-package cl-graph)
2
3 (defun foo ()
4   (let ((graph (cl-graph:make-graph 'cl-graph:graph-container 
5                                     :vertex-test #'equal)))
6     (cl-graph:add-vertex graph "a")
7     (cl-graph:add-vertex graph "b")
8     (cl-graph:add-vertex graph "c")
9     (cl-graph:add-vertex graph "d")
10     (cl-graph:add-vertex graph "e")
11     (cl-graph:add-edge-between-vertexes graph "a" "b" :edge-type :directed)
12     (cl-graph:add-edge-between-vertexes graph "b" "c" :edge-type :directed)
13     (cl-graph:add-edge-between-vertexes graph "c" "a" :edge-type :directed)
14     (cl-graph:add-edge-between-vertexes graph "d" "e" :edge-type :directed)
15     graph))
16
17 (loop for component in 
18      (cl-graph:find-connected-components (foo)) 
19      for index from 1 do
20      (format t "~&Component ~D (~d node~:p and ~d edge~:p)" 
21              index (vertex-count component) (edge-count component))
22      (iterate-edges component (lambda (edge)
23                                 (format t "~&  ~a to ~a" 
24                                         (source-vertex edge) 
25                                         (target-vertex edge))))
26      (format t "~%"))
27
28
29 (defun mk-graph ()
30     (let ((graph (cl-graph:make-graph 'cl-graph:graph-container
31                                     :vertex-test #'equal)))
32     (cl-graph:add-vertex graph "a")
33     (cl-graph:add-vertex graph "b")
34     (cl-graph:add-vertex graph "c")
35     (cl-graph:add-vertex graph "d")
36     (cl-graph:add-vertex graph "e")
37     (cl-graph:add-edge-between-vertexes graph "a" "b" :edge-type :directed)
38     (cl-graph:add-edge-between-vertexes graph "b" "c" :edge-type :directed)
39     (cl-graph:add-edge-between-vertexes graph "c" "a" :edge-type :directed)
40     (cl-graph:add-edge-between-vertexes graph "d" "e" :edge-type :directed)
41     graph))
42
43 (mk-graph)
44
45 (setf *g* (mk-graph))
46
47 (mapcar (lambda (v)
48           (list v (cl-graph:in-cycle-p *g* v)))
49         (cl-graph:vertexes *g*))
50
51 (car (cl-graph:vertexes *g*))