utils: any->boolean -> any->0-1.

This commit is contained in:
Sergiu Ivanov 2020-06-04 23:47:10 +02:00
parent 458868ea21
commit 83dd673df9
2 changed files with 6 additions and 6 deletions

View File

@ -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"

View File

@ -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)))