rs/test: Use test-case and define instead of let.

This commit is contained in:
Sergiu Ivanov 2020-05-27 23:48:22 +02:00
parent b98d00320c
commit b6f6e4e7c4

41
rs.rkt
View file

@ -87,18 +87,18 @@
(module+ test (module+ test
(test-case "Basic definitions" (test-case "Basic definitions"
(let* ([r1 (reaction (set 'x) (set 'y) (set 'z))] (define r1 (reaction (set 'x) (set 'y) (set 'z)))
[r2 (reaction (set 'x) (set) (set 'y))] (define r2 (reaction (set 'x) (set) (set 'y)))
[rs (make-immutable-hash (list (cons 'a r1) (cons 'b r2)))] (define rs (make-immutable-hash (list (cons 'a r1) (cons 'b r2))))
[s1 (set 'x 'z)] (define s1 (set 'x 'z))
[s2 (set 'x 'y)]) (define s2 (set 'x 'y))
(check-true (enabled? r1 s1)) (check-true (enabled? r1 s1))
(check-false (enabled? r1 s2)) (check-false (enabled? r1 s2))
(check-equal? (list-enabled rs s1) '(a b)) (check-equal? (list-enabled rs s1) '(a b))
(check-equal? (list-enabled rs s2) '(b)) (check-equal? (list-enabled rs s2) '(b))
(check-equal? (union-products rs '(a b)) (set 'y 'z)) (check-equal? (union-products rs '(a b)) (set 'y 'z))
(check-equal? (apply-rs rs s1) (set 'y 'z)) (check-equal? (apply-rs rs s1) (set 'y 'z))
(check-equal? (apply-rs rs s2) (set 'y))))) (check-equal? (apply-rs rs s2) (set 'y))))
;;; ==================== ;;; ====================
@ -122,28 +122,31 @@
(values a (str-triple->reaction triple)))) (values a (str-triple->reaction triple))))
(module+ test (module+ test
(test-case "ht-str-triples->rs"
(check-equal? (check-equal?
(ht-str-triples->rs #hash((a . ("x t" "y" "z")))) (ht-str-triples->rs #hash((a . ("x t" "y" "z"))))
(make-immutable-hash (list (cons 'a (reaction (set 'x 't) (set 'y) (set 'z))))))) (make-immutable-hash (list (cons 'a (reaction (set 'x 't) (set 'y) (set 'z))))))))
;;; Reads a reaction system from an Org-mode style string. ;;; Reads a reaction system from an Org-mode style string.
(define read-org-rs (compose ht-str-triples->rs read-org-variable-mapping)) (define read-org-rs (compose ht-str-triples->rs read-org-variable-mapping))
(module+ test (module+ test
(test-case "read-org-rs"
(check-equal? (read-org-rs "((\"a\" \"x t\" \"y\" \"z\") (\"b\" \"x\" \"q\" \"z\"))") (check-equal? (read-org-rs "((\"a\" \"x t\" \"y\" \"z\") (\"b\" \"x\" \"q\" \"z\"))")
(hash (hash
'a 'a
(reaction (set 'x 't) (set 'y) (set 'z)) (reaction (set 'x 't) (set 'y) (set 'z))
'b 'b
(reaction (set 'x) (set 'q) (set 'z))))) (reaction (set 'x) (set 'q) (set 'z))))))
;;; Reads a context sequence from an Org sexp corresponding to a list. ;;; Reads a context sequence from an Org sexp corresponding to a list.
(define (read-context-sequence str) (define (read-context-sequence str)
(map (compose list->set read-symbol-list) (flatten (string->any str)))) (map (compose list->set read-symbol-list) (flatten (string->any str))))
(module+ test (module+ test
(test-case "read-context-sequence"
(check-equal? (read-context-sequence "((\"x y\") (\"z\") (\"\") (\"t\"))") (check-equal? (read-context-sequence "((\"x y\") (\"z\") (\"\") (\"t\"))")
(list (set 'x 'y) (set 'z) (set) (set 't)))) (list (set 'x 'y) (set 'z) (set) (set 't)))))
;;; Converts a reaction to a triple of strings. ;;; Converts a reaction to a triple of strings.
(define/match (reaction->str-triple r) (define/match (reaction->str-triple r)
@ -158,9 +161,10 @@
(values a (reaction->str-triple r)))) (values a (reaction->str-triple r))))
(module+ test (module+ test
(test-case "rs->ht-str-triples"
(check-equal? (check-equal?
(rs->ht-str-triples (make-immutable-hash (list (cons 'a (reaction (set 'x 't) (set 'y) (set 'z)))))) (rs->ht-str-triples (make-immutable-hash (list (cons 'a (reaction (set 'x 't) (set 'y) (set 'z))))))
#hash((a . ("t x" "y" "z"))))) #hash((a . ("t x" "y" "z"))))))
;;; ============================ ;;; ============================
@ -242,13 +246,14 @@
(module+ test (module+ test
(test-case "Dynamics of reaction systems" (test-case "Dynamics of reaction systems"
(let* ([r1 (reaction (set 'x) (set 'y) (set 'z))] (define r1 (reaction (set 'x) (set 'y) (set 'z)))
[r2 (reaction (set 'x) (set) (set 'y))] (define r2 (reaction (set 'x) (set) (set 'y)))
[rs (make-immutable-hash (list (cons 'a r1) (cons 'b r2)))] (define rs (make-immutable-hash (list (cons 'a r1) (cons 'b r2))))
[dyn (dynamics rs)] (define dyn (dynamics rs))
[state1 (state (set) (list (set 'x) (set 'y) (set 'z) (set) (set 'z)))] (define state1 (state (set) (list (set 'x) (set 'y) (set 'z) (set) (set 'z))))
[sgr (dds-build-state-graph-annotated dyn (set state1))] (define sgr (dds-build-state-graph-annotated dyn (set state1)))
[ip (build-interactive-process-graph rs (list (set 'x) (set 'y) (set 'z) (set) (set 'z)))]) (define ip (build-interactive-process-graph rs (list (set 'x) (set 'y) (set 'z) (set) (set 'z))))
(check-equal? (dds-step-one-annotated dyn state1) (check-equal? (dds-step-one-annotated dyn state1)
(set (cons (set (cons
(set 'a 'b) (set 'a 'b)
@ -297,4 +302,4 @@
(list (set 'z) (set)) (list (set 'z) (set))
(list (set) (set)) (list (set) (set))
(list (set 'z) (set)) (list (set 'z) (set))
(list (set) (set))))))) (list (set) (set))))))