functions: Add list->tbf.
This commit is contained in:
parent
db42e20f1c
commit
dd3062652f
1 changed files with 13 additions and 1 deletions
|
@ -33,7 +33,8 @@
|
|||
[tbf-θ (-> tbf? number?)]
|
||||
[vector-boolean->01 (-> (vectorof boolean?) (vectorof (or/c 0 1)))]
|
||||
[apply-tbf (-> tbf? (vectorof (or/c 0 1)) (or/c 0 1))]
|
||||
[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?)]))
|
||||
|
||||
(module+ test
|
||||
(require rackunit))
|
||||
|
@ -278,3 +279,14 @@
|
|||
(define f1 (tbf #(2 -2) 1))
|
||||
(check-equal? (tabulate/boolean (λ (x y) (apply-tbf/boolean f1 (vector x y))))
|
||||
'((#f #f #f) (#f #t #f) (#t #f #t) (#t #t #f)))))
|
||||
|
||||
;;; Converts a list of numbers to a TBF. The last element of the list
|
||||
;;; is taken to be the threshold, while the other elements are taken
|
||||
;;; to be the weights.
|
||||
(define (list->tbf lst)
|
||||
(define-values (w θ) (split-at-right lst 1))
|
||||
(tbf (list->vector w) (car θ)))
|
||||
|
||||
(module+ test
|
||||
(test-case "list->tbf"
|
||||
(check-equal? (list->tbf '(1 2 3)) (tbf #(1 2) 3))))
|
||||
|
|
Loading…
Reference in a new issue