utils: 0-1 -> 01
Shorter and easier to type.
This commit is contained in:
parent
8e6002040a
commit
180810a2aa
2 changed files with 11 additions and 11 deletions
|
@ -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->0-1 val))) #t)))
|
||||
(string-join (hash-map s (λ (key val) (format "~a:~a" key (any->01 val))) #t)))
|
||||
|
||||
(module+ test
|
||||
(test-case "pretty-print-boolean-state"
|
||||
|
|
20
utils.rkt
20
utils.rkt
|
@ -49,8 +49,8 @@
|
|||
[cartesian-product/stream (->* () #:rest (listof stream?) stream?)]
|
||||
[boolean-power (-> number? (listof (listof boolean?)))]
|
||||
[boolean-power/stream (-> number? (stream/c (listof boolean?)))]
|
||||
[any->0-1 (-> any/c (or/c 0 1))]
|
||||
[0-1->boolean (-> (or/c 0 1) boolean?)])
|
||||
[any->01 (-> any/c (or/c 0 1))]
|
||||
[01->boolean (-> (or/c 0 1) boolean?)])
|
||||
;; Contracts
|
||||
(contract-out [variable-mapping? contract?]
|
||||
[string-variable-mapping? contract?]
|
||||
|
@ -700,18 +700,18 @@
|
|||
(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->0-1 x) (if x 1 0))
|
||||
(define (any->01 x) (if x 1 0))
|
||||
|
||||
(module+ test
|
||||
(test-case "any->0-1"
|
||||
(check-equal? (any->0-1 #t) 1)
|
||||
(check-equal? (any->0-1 #f) 0)))
|
||||
(test-case "any->01"
|
||||
(check-equal? (any->01 #t) 1)
|
||||
(check-equal? (any->01 #f) 0)))
|
||||
|
||||
;;; Converts 0 to #f and 1 to #t
|
||||
(define (0-1->boolean x)
|
||||
(define (01->boolean x)
|
||||
(case x [(0) #f] [else #t]))
|
||||
|
||||
(module+ test
|
||||
(test-case "0-1->boolean"
|
||||
(check-equal? (0-1->boolean 0) #f)
|
||||
(check-equal? (0-1->boolean 1) #t)))
|
||||
(test-case "01->boolean"
|
||||
(check-equal? (01->boolean 0) #f)
|
||||
(check-equal? (01->boolean 1) #t)))
|
||||
|
|
Loading…
Reference in a new issue