diff --git a/rs-tests.rkt b/rs-tests.rkt index 9601a08..a8231ae 100644 --- a/rs-tests.rkt +++ b/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)))) diff --git a/rs.rkt b/rs.rkt index 50e9e53..a9af363 100644 --- a/rs.rkt +++ b/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))