utils: Add pretty-print-set.

This commit is contained in:
Sergiu Ivanov 2020-03-01 15:15:52 +01:00
parent 1e524f167c
commit 3f24a5be8b
2 changed files with 14 additions and 1 deletions

View file

@ -107,3 +107,6 @@
(check-false (has-edge? new-gr3 'cc 'bb)) (check-false (has-edge? new-gr3 'cc 'bb))
(check-equal? (edge-weight new-gr3 'aa 'bb) 20) (check-equal? (edge-weight new-gr3 'aa 'bb) 20)
(check-equal? (edge-weight new-gr3 'bb 'cc) 22))) (check-equal? (edge-weight new-gr3 'bb 'cc) 22)))
(test-case "Pretty printing"
(check-equal? (pretty-print-set (set 'a 'b 1)) "1 a b"))

View file

@ -23,7 +23,8 @@
[update-graph (->* (graph?) [update-graph (->* (graph?)
(#:v-func (-> any/c any/c) (#:v-func (-> any/c any/c)
#:e-func (-> any/c any/c)) #:e-func (-> any/c any/c))
graph?)]) graph?)]
[pretty-print-set (-> generic-set? string?)])
;; Contracts ;; Contracts
(contract-out [variable-mapping? contract?] (contract-out [variable-mapping? contract?]
[string-variable-mapping? contract?] [string-variable-mapping? contract?]
@ -249,3 +250,12 @@
(if (unweighted-graph? gr) (if (unweighted-graph? gr)
(unweighted-graph/directed edges) (unweighted-graph/directed edges)
(weighted-graph/directed edges)))) (weighted-graph/directed edges))))
;;; ===============
;;; Pretty printing
;;; ===============
;;; Pretty print a set by listing its elements in alphabetic order.
(define (pretty-print-set s)
(string-join (sort (set-map s any->string) string<?)))