2020-02-20 00:56:30 +01:00
|
|
|
#lang racket
|
2020-02-15 13:57:49 +01:00
|
|
|
|
2020-02-20 00:56:30 +01:00
|
|
|
;;; Tests for dds/networks.
|
2020-02-15 13:57:49 +01:00
|
|
|
|
2020-02-20 15:56:48 +01:00
|
|
|
(require rackunit graph "networks.rkt")
|
2020-02-15 13:57:49 +01:00
|
|
|
|
2020-02-15 20:30:46 +01:00
|
|
|
;;; This test case sets up the following Boolean network:
|
|
|
|
;;; x1 = x1 AND NOT x2
|
|
|
|
;;; x2 = NOT x2
|
2020-02-18 12:20:32 +01:00
|
|
|
(test-case "Basic definitions"
|
2020-02-20 00:56:30 +01:00
|
|
|
(let* ([f1 (λ (s)
|
2020-02-18 12:20:32 +01:00
|
|
|
(let ([x1 (hash-ref s 'x1)]
|
|
|
|
[x2 (hash-ref s 'x2)])
|
|
|
|
(and x1 (not x2))))]
|
2020-02-20 00:56:30 +01:00
|
|
|
[f2 (λ (s)
|
2020-02-18 12:20:32 +01:00
|
|
|
(let ([x2 (hash-ref s 'x2)])
|
|
|
|
(not x2)))]
|
2020-02-20 00:56:30 +01:00
|
|
|
[bn (make-network-from-functions `((x1 . ,f1) (x2 . ,f2)))])
|
2020-02-15 20:30:46 +01:00
|
|
|
|
2020-02-18 12:20:32 +01:00
|
|
|
(test-case "One-step syncronous update"
|
|
|
|
(let* ([s (make-state '((x1 . #t) (x2 . #f)))]
|
|
|
|
[new-s (update bn s '(x2 x1))])
|
2020-02-23 09:25:08 +01:00
|
|
|
(check-equal? s #hash((x1 . #t) (x2 . #f)))
|
|
|
|
(check-equal? new-s #hash((x1 . #t) (x2 . #t)))))
|
2020-02-15 20:30:46 +01:00
|
|
|
|
2020-02-18 12:20:32 +01:00
|
|
|
(test-case "One-step asynchronous update"
|
|
|
|
(let* ([s (make-state '((x1 . #f) (x2 . #f)))]
|
|
|
|
[new-s (update bn s '(x2 x1))])
|
2020-02-23 09:25:08 +01:00
|
|
|
(check-equal? s #hash((x1 . #f) (x2 . #f)))
|
|
|
|
(check-equal? new-s #hash((x1 . #f) (x2 . #t)))))))
|
2020-02-18 11:41:16 +01:00
|
|
|
|
2020-02-18 12:20:32 +01:00
|
|
|
(test-case "Syntactic description of Boolean networks"
|
|
|
|
(let ([s (make-state '((x . #t) (y . #f)))]
|
2020-02-20 00:56:30 +01:00
|
|
|
[f (update-function-form->update-function '(and x y))])
|
2020-02-18 12:20:32 +01:00
|
|
|
(check-equal? (f s) #f))
|
2020-02-20 00:56:30 +01:00
|
|
|
(let ([bn1 (network-form->network (make-hash '((a . (and a b)) (b . (not b)))))]
|
|
|
|
[bn2 (make-network-from-forms '((a . (and a b))
|
|
|
|
(b . (not b))))]
|
|
|
|
[bn3 (nn '((a . (and a b))
|
2020-02-18 12:36:26 +01:00
|
|
|
(b . (not b))))]
|
2020-02-18 12:39:11 +01:00
|
|
|
[s (st '((a . #t) (b . #t)))])
|
2020-02-18 12:20:32 +01:00
|
|
|
(check-equal? ((hash-ref bn1 'a) s) #t)
|
2020-02-18 12:36:26 +01:00
|
|
|
(check-equal? ((hash-ref bn2 'a) s) #t)
|
|
|
|
(check-equal? ((hash-ref bn3 'a) s) #t)))
|
2020-02-20 15:17:32 +01:00
|
|
|
|
|
|
|
(test-case "Inferring interaction graphs"
|
2020-02-20 15:56:48 +01:00
|
|
|
(let* ([n #hash((a . (+ a b c))
|
|
|
|
(b . (- b c)))]
|
|
|
|
[ig (build-interaction-graph n)])
|
2020-02-20 15:17:32 +01:00
|
|
|
(check-true (set=? (list-interactions n 'a) '(a b)))
|
2020-02-20 15:56:48 +01:00
|
|
|
(check-true (set=? (list-interactions n 'b) '(b)))
|
|
|
|
(check-true (has-vertex? ig 'a))
|
|
|
|
(check-true (has-vertex? ig 'b))
|
|
|
|
(check-false (has-vertex? ig 'c))
|
|
|
|
(check-true (has-edge? ig 'a 'a))
|
|
|
|
(check-true (has-edge? ig 'b 'a))
|
|
|
|
(check-true (has-edge? ig 'b 'b))
|
|
|
|
(check-false (has-edge? ig 'c 'b))
|
2020-02-22 22:27:40 +01:00
|
|
|
(check-false (has-edge? ig 'c 'a)))
|
|
|
|
|
2020-02-23 09:25:08 +01:00
|
|
|
(check-equal? (build-all-states #hash((a . (#t #f)) (b . (1 2 3))))
|
|
|
|
'(#hash((a . #t) (b . 1))
|
|
|
|
#hash((a . #t) (b . 2))
|
|
|
|
#hash((a . #t) (b . 3))
|
|
|
|
#hash((a . #f) (b . 1))
|
|
|
|
#hash((a . #f) (b . 2))
|
|
|
|
#hash((a . #f) (b . 3))))
|
|
|
|
(check-equal? (make-boolean-domains '(a b))
|
|
|
|
#hash((a . (#f #t)) (b . (#f #t))))
|
2020-02-23 00:04:19 +01:00
|
|
|
|
2020-02-23 01:00:09 +01:00
|
|
|
(let* ([n #hash((a . (not b)) (b . a))]
|
|
|
|
[doms (make-boolean-domains '(a b))]
|
|
|
|
[sig (build-signed-interaction-graph n doms)])
|
2020-02-23 00:04:19 +01:00
|
|
|
(check-equal? (get-interaction-sign n doms 'a 'b) '+)
|
2020-02-23 01:00:09 +01:00
|
|
|
(check-equal? (get-interaction-sign n doms 'b 'a) '-)
|
|
|
|
|
|
|
|
(check-true (has-vertex? sig 'a))
|
|
|
|
(check-true (has-vertex? sig 'b))
|
|
|
|
(check-false (has-vertex? sig 'c))
|
|
|
|
(check-false (has-edge? sig 'a 'a))
|
|
|
|
(check-true (has-edge? sig 'b 'a))
|
|
|
|
(check-false (has-edge? sig 'b 'b))
|
|
|
|
(check-false (has-edge? sig 'c 'b))
|
|
|
|
(check-false (has-edge? sig 'c 'a))
|
|
|
|
(check-equal? (edge-weight sig 'a 'b) 1)
|
|
|
|
(check-equal? (edge-weight sig 'b 'a) -1)))
|