diff --git a/graph.rkt b/graph.rkt index 445ea85..a24beae 100644 --- a/graph.rkt +++ b/graph.rkt @@ -35,6 +35,7 @@ bfs bfs/generalized fewest-vertices-path dfs dfs/generalized + dag? graphviz) @@ -170,6 +171,8 @@ #:process-unvisited process-unvisited #:combine combine #:return finish)) + (define (dag? g) + (g:dag? (gg g))) ;; 10 Graphviz (define (graphviz g #:output [output #f] #:colors [colors #f]) @@ -250,6 +253,7 @@ #:combine (-> Any Any Any) #:return (-> Graph Any Any)) Any)] + [dag? (-> Graph Boolean)] ;; 10 Graphviz [graphviz (->* (Graph) @@ -349,7 +353,9 @@ '((a . 7) (b . 6) (c . 3) (d . 2))) (check-equal? (dfs/generalized (directed-graph '((a b) (a c) (b d) (c d)))) - (void))) + (void)) + (check-true (dag? (directed-graph '((a b) (b c))))) + (check-false (dag? (directed-graph '((a b) (b a)))))) (test-case "10 Graphviz" (define g (directed-graph '((a b) (b c))))