bn-tests: Restructure.
Also make the names of test cases correspond to the names of the sections in bn.
This commit is contained in:
parent
f0a7c270e9
commit
58e40e44ad
1 changed files with 31 additions and 32 deletions
63
bn-tests.rkt
63
bn-tests.rkt
|
@ -7,38 +7,37 @@
|
||||||
;;; This test case sets up the following Boolean network:
|
;;; This test case sets up the following Boolean network:
|
||||||
;;; x1 = x1 AND NOT x2
|
;;; x1 = x1 AND NOT x2
|
||||||
;;; x2 = NOT x2
|
;;; x2 = NOT x2
|
||||||
(test-begin
|
(test-case "Basic definitions"
|
||||||
(test-case "Simple two-variable Boolean network"
|
(let* ([f1 (λ ([s : State])
|
||||||
(let* ([f1 (λ ([s : State])
|
(let ([x1 (hash-ref s 'x1)]
|
||||||
(let ([x1 (hash-ref s 'x1)]
|
[x2 (hash-ref s 'x2)])
|
||||||
[x2 (hash-ref s 'x2)])
|
(and x1 (not x2))))]
|
||||||
(and x1 (not x2))))]
|
[f2 (λ ([s : State])
|
||||||
[f2 (λ ([s : State])
|
(let ([x2 (hash-ref s 'x2)])
|
||||||
(let ([x2 (hash-ref s 'x2)])
|
(not x2)))]
|
||||||
(not x2)))]
|
[bn (make-bn-funcs `((x1 . ,f1) (x2 . ,f2)))])
|
||||||
[bn (make-bn-funcs `((x1 . ,f1) (x2 . ,f2)))])
|
|
||||||
|
|
||||||
(test-case "One-step syncronous update"
|
(test-case "One-step syncronous update"
|
||||||
(let* ([s (make-state '((x1 . #t) (x2 . #f)))]
|
(let* ([s (make-state '((x1 . #t) (x2 . #f)))]
|
||||||
[new-s (update bn s '(x2 x1))])
|
[new-s (update bn s '(x2 x1))])
|
||||||
(check-equal? (hash-ref new-s 'x1) #t)
|
(check-equal? (hash-ref new-s 'x1) #t)
|
||||||
(check-equal? (hash-ref new-s 'x2) #t)
|
(check-equal? (hash-ref new-s 'x2) #t)
|
||||||
(check-equal? (length (hash-keys new-s)) 2)))
|
(check-equal? (length (hash-keys new-s)) 2)))
|
||||||
|
|
||||||
(test-case "One-step asynchronous update"
|
(test-case "One-step asynchronous update"
|
||||||
(let* ([s (make-state '((x1 . #f) (x2 . #f)))]
|
(let* ([s (make-state '((x1 . #f) (x2 . #f)))]
|
||||||
[new-s (update bn s '(x2 x1))])
|
[new-s (update bn s '(x2 x1))])
|
||||||
(check-equal? (hash-ref new-s 'x1) #f)
|
(check-equal? (hash-ref new-s 'x1) #f)
|
||||||
(check-equal? (hash-ref new-s 'x2) #t)
|
(check-equal? (hash-ref new-s 'x2) #t)
|
||||||
(check-equal? (length (hash-keys new-s)) 2)))
|
(check-equal? (length (hash-keys new-s)) 2)))))
|
||||||
|
|
||||||
(test-case "Constructing networks from forms"
|
(test-case "Syntactic description of Boolean networks"
|
||||||
(let ([s (make-state '((x . #t) (y . #f)))]
|
(let ([s (make-state '((x . #t) (y . #f)))]
|
||||||
[f (update-func-form->update-func '(and x y))])
|
[f (update-func-form->update-func '(and x y))])
|
||||||
(check-equal? (f s) #f))
|
(check-equal? (f s) #f))
|
||||||
(let ([bn1 (bn-form->bn (make-hash '((a . (and a b)) (b . (not b)))))]
|
(let ([bn1 (bn-form->bn (make-hash '((a . (and a b)) (b . (not b)))))]
|
||||||
[bn2 (make-bn-forms '((a . (and a b))
|
[bn2 (make-bn-forms '((a . (and a b))
|
||||||
(b . (not b))))]
|
(b . (not b))))]
|
||||||
[s (make-state '((a . #t) (b . #t)))])
|
[s (make-state '((a . #t) (b . #t)))])
|
||||||
(check-equal? ((hash-ref bn1 'a) s) #t)
|
(check-equal? ((hash-ref bn1 'a) s) #t)
|
||||||
(check-equal? ((hash-ref bn2 'a) s) #t))))))
|
(check-equal? ((hash-ref bn2 'a) s) #t)))
|
||||||
|
|
Loading…
Reference in a new issue