From a3967d8bf837adbf1562ee22962f4f4e47f3ad19 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 2 Mar 2020 23:59:37 +0100 Subject: [PATCH] utils: Move pretty-print-modalities as pretty-print-set-sets from networks. --- networks-tests.rkt | 1 - networks.rkt | 8 +------- utils-tests.rkt | 3 ++- utils.rkt | 8 ++++++++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/networks-tests.rkt b/networks-tests.rkt index 0283262..89e9e7a 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -112,7 +112,6 @@ (test-case "Dynamics of networks" (check-equal? (pretty-print-state (st '((a . #f) (b . 3) (c . 4)))) "a:#f b:3 c:4") - (check-equal? (pretty-print-modalities (list (set 'a) (set 'b 'a))) "{a}{a b}") (check-equal? (pretty-print-boolean-state (st '((a . #f) (b . #t) (c . #t)))) "a:0 b:1 c:1") (let ([vars '(a b c)]) (check-equal? (make-asyn vars) (set (set 'a) (set 'b) (set 'c))) diff --git a/networks.rkt b/networks.rkt index 364db94..3b60fa3 100644 --- a/networks.rkt +++ b/networks.rkt @@ -47,7 +47,6 @@ [dds-build-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) graph?)] [dds-build-n-step-state-graph-annotated (-> dynamics? (set/c state? #:kind 'dont-care) number? graph?)] [pretty-print-state (-> state? string?)] - [pretty-print-modalities (-> (listof modality?) string?)] [any->boolean (-> any/c boolean?)] [pretty-print-boolean-state (-> state? string?)] [pretty-print-state-graph-with (-> graph? (-> state? string?) graph?)] @@ -340,15 +339,10 @@ (define (pretty-print-boolean-state s) (string-join (hash-map s (λ (key val) (format "~a:~a" key (any->boolean val))) #t))) -;;; Pretty-prints a list of modalities, as suitable for showing on -;;; state graphs. -(define (pretty-print-modalities ms) - (string-join (for/list ([m ms]) (format "{~a}" (pretty-print-set m))) "")) - ;;; Given a state graph and a pretty-printer for states build a new ;;; state graph with pretty-printed vertices and edges. (define (pretty-print-state-graph-with gr pprinter) - (update-graph gr #:v-func pprinter #:e-func pretty-print-modalities)) + (update-graph gr #:v-func pprinter #:e-func pretty-print-set-sets)) ;;; Pretty prints a state graph with pretty-print-state. (define (pretty-print-state-graph gr) diff --git a/utils-tests.rkt b/utils-tests.rkt index 73525bf..4a5c2ef 100644 --- a/utils-tests.rkt +++ b/utils-tests.rkt @@ -64,7 +64,8 @@ (check-equal? (read-symbol-list "a b c") '(a b c)) (check-equal? (drop-first-last "(a b)") "a b") (check-equal? (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't))) - '("y x" "z" "" "t"))) + '("y x" "z" "" "t")) + (check-equal? (pretty-print-set-sets (set (set 'a 'b) (set 'c))) "{a b}{c}")) (test-case "Additional graph utilities" (let* ([gr1 (directed-graph '((a b) (b c)))] diff --git a/utils.rkt b/utils.rkt index 670d541..b2c3161 100644 --- a/utils.rkt +++ b/utils.rkt @@ -22,6 +22,7 @@ [read-symbol-list (-> string? (listof symbol?))] [drop-first-last (-> string? string?)] [list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))] + [pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)] [update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)] [update-graph (->* (graph?) (#:v-func (-> any/c any/c) @@ -238,6 +239,13 @@ (define (list-sets->list-strings lst) (map (compose drop-first-last any->string set->list) lst)) +;;; Pretty-prints a set of sets of symbols. +;;; +;;; Typically used for pretty-printing the annotations on the edges of +;;; the state graph. +(define (pretty-print-set-sets ms) + (string-join (for/list ([m ms]) (format "{~a}" (pretty-print-set m))) "")) + ;;; ========================== ;;; Additional graph utilities