dds/bn-tests.rkt

34 lines
1.1 KiB
Racket
Raw Normal View History

2020-02-15 13:57:49 +01:00
#lang typed/racket
;;; Tests for dds/bn.
(require typed/rackunit "bn.rkt")
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
(test-begin
(test-case "Simple two-variable Boolean network"
(let* ([f1 (λ ([s : State])
(let ([x1 (hash-ref s 'x1)]
[x2 (hash-ref s 'x2)])
(and x1 (not x2))))]
[f2 (λ ([s : State])
(let ([x2 (hash-ref s 'x2)])
(not x2)))]
2020-02-15 21:00:20 +01:00
[bn (make-bn `((x1 . ,f1) (x2 . ,f2)))])
2020-02-15 20:30:46 +01:00
(test-case "One-step syncronous update"
2020-02-15 21:01:28 +01:00
(let* ([s (make-state '((x1 . #t) (x2 . #f)))]
2020-02-15 20:30:46 +01:00
[new-s (update bn s '(x2 x1))])
(check-equal? (hash-ref new-s 'x1) #t)
(check-equal? (hash-ref new-s 'x2) #t)
(check-equal? (length (hash-keys new-s)) 2)))
(test-case "One-step asynchronous update"
2020-02-15 21:01:28 +01:00
(let* ([s (make-state '((x1 . #f) (x2 . #f)))]
2020-02-15 20:30:46 +01:00
[new-s (update bn s '(x2 x1))])
(check-equal? (hash-ref new-s 'x1) #f)
(check-equal? (hash-ref new-s 'x2) #t)
(check-equal? (length (hash-keys new-s)) 2))))))