diff --git a/networks-tests.rkt b/networks-tests.rkt index b52b5fd..2dacb7a 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -208,7 +208,7 @@ #hash((a . #f) (b . #t)) #hash((a . #t) (b . #t))) (set (set 'a))))) -(test-case "Functions" +(test-case "Tabulating functions and networks" (check-equal? (tabulate/domain-list (λ (x y) (and x y)) '((#f #t) (#f #t))) '((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t))) (check-equal? (tabulate (λ (x y) (and x y)) '(#f #t) '(#f #t)) @@ -216,7 +216,9 @@ (check-equal? (tabulate/boolean (lambda (x y) (and x y))) '((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t))) (let ([func (λ (st) (not (hash-ref st 'a)))]) - (check-equal? (tabulate-state/boolean func '(a)) '((a f) (#f #t) (#t #f)))) + (check-equal? (tabulate-state/boolean func '(a)) '((a f) (#f #t) (#t #f))))) + +(test-case "Constructing functions" (check-equal? (boolean-power 2) '((#f #f) (#f #t) (#t #f) (#t #t))) (check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t))) (let ([negation (table->function '((#t #f) (#f #t)))] @@ -228,7 +230,7 @@ (check-false (f1 #f)) (check-false (f1 #t)) (check-false (f1/list '(#f))) (check-false (f1/list '(#t))))) -(test-case "Random Boolean functions and networks" +(test-case "Random functions and networks" (random-seed 0) (check-equal? (random-boolean-table 2) '((#f #f #t) (#f #t #t) (#t #f #f) (#t #t #f))) (let ([f (random-boolean-function 2)]) diff --git a/networks.rkt b/networks.rkt index 7cc012f..0af22d9 100644 --- a/networks.rkt +++ b/networks.rkt @@ -404,9 +404,9 @@ (list->set (build-all-boolean-states (hash-keys (dynamics-network dyn)))))) -;;; ========= -;;; Functions -;;; ========= +;;; ================================= +;;; Tabulating functions and networks +;;; ================================= ;;; Given a function and a list of domains for each of its arguments, ;;; in order, produces a list of lists giving the values of arguments @@ -446,6 +446,11 @@ (define (tabulate-state/boolean func args #:headers [headers #t]) (tabulate-state func (make-boolean-domains args) #:headers headers)) + +;;; ====================== +;;; Constructing functions +;;; ====================== + ;;; Given a table like the one produced by the tabulate functions, ;;; creates a function which has this behaviour. ;;; @@ -504,9 +509,9 @@ (stream-map table->function/list (enumerate-boolean-tables n))) -;;; ===================================== -;;; Random Boolean functions and networks -;;; ===================================== +;;; ============================= +;;; Random functions and networks +;;; ============================= ;;; Generates a random truth table for a Boolean function of arity n. (define (random-boolean-table n)