diff --git a/utils-tests.rkt b/utils-tests.rkt index 593ada8..62140e1 100644 --- a/utils-tests.rkt +++ b/utils-tests.rkt @@ -107,3 +107,6 @@ (check-false (has-edge? new-gr3 'cc 'bb)) (check-equal? (edge-weight new-gr3 'aa 'bb) 20) (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")) diff --git a/utils.rkt b/utils.rkt index 90ea98b..86782e6 100644 --- a/utils.rkt +++ b/utils.rkt @@ -23,7 +23,8 @@ [update-graph (->* (graph?) (#:v-func (-> any/c any/c) #:e-func (-> any/c any/c)) - graph?)]) + graph?)] + [pretty-print-set (-> generic-set? string?)]) ;; Contracts (contract-out [variable-mapping? contract?] [string-variable-mapping? contract?] @@ -249,3 +250,12 @@ (if (unweighted-graph? gr) (unweighted-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