Compare commits

..

No commits in common. "cec1ff51b65476d50ad24aa232861f34c1d5d4d0" and "82b1150444e8d7e912277343f556d12e4b3c7239" have entirely different histories.

View File

@ -20,58 +20,29 @@
(module graph-wrapper racket (module graph-wrapper racket
(require (prefix-in g: graph)) (require (prefix-in g: graph))
(provide graph? has-vertex? has-edge? (provide graph?
directed-graph directed-graph
has-edge?
graphviz) graphviz)
;; Wrap the opaque graph structure coming from the generic
;; graph library.
(struct graph (g)) (struct graph (g))
(define (has-vertex? g v)
(g:has-vertex? (graph-g g) v))
(define (has-edge? g u v)
(g:has-edge? (graph-g g) u v))
;; 2 Graph constructors
;; 2.2 Weighted graphs
(define (directed-graph es [ws #f]) (define (directed-graph es [ws #f])
(graph (g:directed-graph es ws))) (graph (g:directed-graph es ws)))
(define (has-edge? g u v)
;; 10 Graphviz (g:has-edge? (graph-g g) u v))
(define (graphviz g #:output [output #f] #:colors [colors #f]) (define (graphviz g #:output [output #f] #:colors [colors #f])
(g:graphviz (graph-g g) #:output output #:colors colors))) (g:graphviz (graph-g g) #:output output #:colors colors)))
(require/typed 'graph-wrapper
(require/typed/provide 'graph-wrapper
[#:opaque Graph graph?] [#:opaque Graph graph?]
[has-vertex? (-> Graph Any Boolean)]
[has-edge? (-> Graph Any Any Boolean)]
;; 2 Graph constructors
;; 2.2 Weighted graphs
[directed-graph (->* ((Listof (List Any Any))) ((Listof Any)) Graph)] [directed-graph (->* ((Listof (List Any Any))) ((Listof Any)) Graph)]
[has-edge? (-> Graph Any Any Boolean)]
;; 10 Graphviz
[graphviz (->* (Graph) [graphviz (->* (Graph)
(#:output Output-Port (#:output Output-Port
#:colors (HashTable Any Natural)) #:colors (HashTable Any Natural))
String)]) String)])
(define g (directed-graph '((a b) (b c))))
(module+ test (has-edge? g 'a 'c)
;; The goal of the tests is to check that all of the provided (graphviz g)
;; functions can be invoked without errors. The tests do not check
;; whether the results make sense.
(require typed/rackunit)
(test-case "1 Generic Graph Interface"
(define g (directed-graph '((a b) (b c))))
(check-true (has-edge? g 'a 'c))
(check-true (has-vertex? g 'a)))
(test-case "10 Graphviz"
(define g (directed-graph '((a b) (b c))))
(graphviz g)))