diff --git a/networks-tests.rkt b/networks-tests.rkt index 91aefbd..ee75421 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -224,12 +224,13 @@ (let ([f1 (stream-first (enumerate-boolean-functions 1))] [f1/list (stream-first (enumerate-boolean-functions/list 1))]) (check-false (f1 #f)) (check-false (f1 #t)) - (check-false (f1/list '(#f))) (check-false (f1/list '(#t)))) + (check-false (f1/list '(#f))) (check-false (f1/list '(#t))))) - (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)]) - (check-true (f #f #f)) (check-false (f #f #t)) (check-true (f #t #f)) (check-false (f #t #t))) - (let ([f (random-boolean-function/list 2)]) - (check-false (f '(#f #f))) (check-true (f '(#f #t))) - (check-true (f '(#t #f))) (check-false (f '(#t #t))))) +(test-case "Random Boolean 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)]) + (check-true (f #f #f)) (check-false (f #f #t)) (check-true (f #t #f)) (check-false (f #t #t))) + (let ([f (random-boolean-function/list 2)]) + (check-false (f '(#f #f))) (check-true (f '(#f #t))) + (check-true (f '(#t #f))) (check-false (f '(#t #t))))) diff --git a/networks.rkt b/networks.rkt index fd2509c..b5b3f16 100644 --- a/networks.rkt +++ b/networks.rkt @@ -477,6 +477,11 @@ (define (enumerate-boolean-functions/list n) (stream-map table->function/list (enumerate-boolean-tables n))) + +;;; ===================================== +;;; Random Boolean functions and networks +;;; ===================================== + ;;; Generates a random truth table for a Boolean function of arity n. (define (random-boolean-table n) (define/match (num->bool x) [(0) #f] [(1) #t])