From 83dd673df9bd6fa6668d28370f665f01ca771f84 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Thu, 4 Jun 2020 23:47:10 +0200 Subject: [PATCH] utils: any->boolean -> any->0-1. --- networks.rkt | 2 +- utils.rkt | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/networks.rkt b/networks.rkt index bc0dcd2..fcad756 100644 --- a/networks.rkt +++ b/networks.rkt @@ -574,7 +574,7 @@ ;;; Pretty-prints a state of the network to Boolean values 0 or 1. (define (pretty-print-boolean-state s) - (string-join (hash-map s (λ (key val) (format "~a:~a" key (any->boolean val))) #t))) + (string-join (hash-map s (λ (key val) (format "~a:~a" key (any->0-1 val))) #t))) (module+ test (test-case "pretty-print-boolean-state" diff --git a/utils.rkt b/utils.rkt index 886e26b..7d13118 100644 --- a/utils.rkt +++ b/utils.rkt @@ -49,7 +49,7 @@ [cartesian-product/stream (->* () #:rest (listof stream?) stream?)] [boolean-power (-> number? (listof (listof boolean?)))] [boolean-power/stream (-> number? (stream/c (listof boolean?)))] - [any->boolean (-> any/c boolean?)]) + [any->0-1 (-> any/c (or/c 0 1))]) ;; Contracts (contract-out [variable-mapping? contract?] [string-variable-mapping? contract?] @@ -699,9 +699,9 @@ (check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t))))) ;;; Converts any non-#f value to 1 and #f to 0. -(define (any->boolean x) (if x 1 0)) +(define (any->0-1 x) (if x 1 0)) (module+ test - (test-case "any->boolean" - (check-equal? (any->boolean #t) 1) - (check-equal? (any->boolean #f) 0))) + (test-case "any->0-1" + (check-equal? (any->0-1 #t) 1) + (check-equal? (any->0-1 #f) 0)))