(defmethod rootp ((vertex basic-vertex))
;;?? this is inefficient in the same way that (zerop (length <list>)) is...
- (zerop (source-edge-count vertex)))
+ (zerop (target-edge-count vertex)))
(defmethod find-vertex-if ((graph basic-graph) fn &key key)
(deftestsuite test-change-vertex-value (test-basic-graph-properties) ())
-;;; ---------------------------------------------------------------------------
-
(addtest (test-change-vertex-value)
test-undirected
(let ((b (find-vertex graph-undirected 'b)))
(ensure (find-edge-between-vertexes graph-undirected 'a 'x))
(ensure (find-edge-between-vertexes graph-undirected 'x 'd))))
+;;;
+(deftestsuite test-rootp (cl-graph-test)
+ ((g (make-container 'graph-container
+ :default-edge-type :directed)))
+ (:setup
+ (loop for (v1 . v2) in '((a . b) (a . c) (b . d) (c . e)) do
+ (add-edge-between-vertexes g v1 v2))))
-;;; ---------------------------------------------------------------------------
-;;; test-replace-edge
-;;; ---------------------------------------------------------------------------
+(addtest (test-rootp)
+ directed-edges
+ (ensure (directed-edge-p (first-item (graph-edges g)))))
+
+(addtest(test-rootp)
+ test-source-vertex
+ (ensure (rootp (find-vertex g 'a))))
+(addtest(test-rootp)
+ test-sink-vertex
+ (ensure-null (rootp (find-vertex g 'e))))
+
+(addtest(test-rootp)
+ test-middle-vertex
+ (ensure-null (rootp (find-vertex g 'b))))
+
+
+
+