rs: Add list-enabled.
This commit is contained in:
parent
0cb57196c5
commit
d7e189eef0
2 changed files with 17 additions and 6 deletions
14
rs-tests.rkt
14
rs-tests.rkt
|
@ -5,8 +5,12 @@
|
|||
(require typed/rackunit "rs.rkt")
|
||||
|
||||
(test-case "Basic definitions"
|
||||
(let ([r (reaction (set 'a) (set 'b) (set 'c))]
|
||||
[s1 (set 'a 'c)]
|
||||
[s2 (set 'a 'b)])
|
||||
(check-true (enabled? r s1))
|
||||
(check-false (enabled? r s2))))
|
||||
(let* ([r1 (reaction (set 'x) (set 'y) (set 'z))]
|
||||
[r2 (reaction (set 'x) (set) (set 'y))]
|
||||
[rs (make-immutable-hash (list (cons 'a r1) (cons 'b r2)))]
|
||||
[s1 (set 'x 'z)]
|
||||
[s2 (set 'x 'y)])
|
||||
(check-true (enabled? r1 s1))
|
||||
(check-false (enabled? r1 s2))
|
||||
(check-equal? (list-enabled rs s1) '(a b))
|
||||
(check-equal? (list-enabled rs s2) '(b))))
|
||||
|
|
9
rs.rkt
9
rs.rkt
|
@ -10,7 +10,7 @@
|
|||
;; Type names
|
||||
Species ReactionSystem
|
||||
;; Functions
|
||||
enabled?)
|
||||
enabled? list-enabled)
|
||||
|
||||
;;; =================
|
||||
;;; Basic definitions
|
||||
|
@ -35,3 +35,10 @@
|
|||
;;; A reaction system is a dictionary mapping reaction names to
|
||||
;;; reactions.
|
||||
(define-type ReactionSystem (HashTable Symbol reaction))
|
||||
|
||||
;;; Returns the list of reaction names enabled on a given set.
|
||||
(: list-enabled (-> ReactionSystem (Setof Symbol) (Listof Symbol)))
|
||||
(define (list-enabled rs s)
|
||||
(for/list ([(name reaction) (in-hash rs)]
|
||||
#:when (enabled? reaction s))
|
||||
name))
|
||||
|
|
Loading…
Reference in a new issue