functions: Add tbf-tabulate.
This commit is contained in:
parent
7d825d0a83
commit
47532e3905
1 changed files with 15 additions and 1 deletions
|
@ -36,7 +36,8 @@
|
||||||
[apply-tbf/boolean (-> tbf? (vectorof boolean?) boolean?)]
|
[apply-tbf/boolean (-> tbf? (vectorof boolean?) boolean?)]
|
||||||
[list->tbf (-> (cons/c number? (cons/c number? (listof number?))) tbf?)]
|
[list->tbf (-> (cons/c number? (cons/c number? (listof number?))) tbf?)]
|
||||||
[read-tbfs (-> (listof (listof number?)) (listof tbf?))]
|
[read-tbfs (-> (listof (listof number?)) (listof tbf?))]
|
||||||
[read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))]))
|
[read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))]
|
||||||
|
[tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))]))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require rackunit))
|
(require rackunit))
|
||||||
|
@ -317,3 +318,16 @@
|
||||||
(test-case "read-org-tbfs"
|
(test-case "read-org-tbfs"
|
||||||
(check-equal? (read-org-tbfs "((1 2 1) (1 0 1))")
|
(check-equal? (read-org-tbfs "((1 2 1) (1 0 1))")
|
||||||
(list (tbf '#(1 2) 1) (tbf '#(1 0) 1)))))
|
(list (tbf '#(1 2) 1) (tbf '#(1 0) 1)))))
|
||||||
|
|
||||||
|
;;; Tabulates a TBF.
|
||||||
|
(define (tbf-tabulate tbf)
|
||||||
|
(define ins (apply
|
||||||
|
cartesian-product
|
||||||
|
(make-list (vector-length (tbf-w tbf)) '(0 1))))
|
||||||
|
(for/list ([in ins])
|
||||||
|
(append in (list (apply-tbf tbf (list->vector in))))))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "tbf-tabulate"
|
||||||
|
(check-equal? (tbf-tabulate (tbf #(1 2) 1))
|
||||||
|
'((0 0 0) (0 1 1) (1 0 0) (1 1 1)))))
|
||||||
|
|
Loading…
Reference in a new issue