From 983380b063dd3ad71bb6ddd9cfb583dd4fd2e2d0 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 2 Sep 2022 16:32:52 +0200 Subject: [PATCH] Implement the method step. --- dynamics.rkt | 3 ++- networks.rkt | 42 +++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/dynamics.rkt b/dynamics.rkt index 34f3a8d..f897137 100644 --- a/dynamics.rkt +++ b/dynamics.rkt @@ -10,7 +10,8 @@ (super-new) (: step (-> State (Listof State))) - (define/abstract/error (step st)) + (define/public (step st) + (map (inst cdr Modality State) (step/annotated st))) (: step/annotated (-> State (Listof (Pairof Modality State)))) (define/abstract/error (step/annotated st)) diff --git a/networks.rkt b/networks.rkt index fc68bd4..6a92b0c 100644 --- a/networks.rkt +++ b/networks.rkt @@ -529,24 +529,32 @@ (cons m (update network s m)))))) (module+ test - (test-case "dynamics%" - (define n1 : (Network Boolean) - (forms->boolean-network (hash 'x '(not y) - 'y 'x - 'z '(and y z)))) - (define syn : Mode '((x y z))) - (define asyn : Mode '((x) (y) (z))) - (define dyn-syn (new (inst dynamics% Boolean) [network n1] [mode syn])) - (define dyn-asyn (new (inst dynamics% Boolean) [network n1] [mode asyn])) + (let* ([n1 : (Network Boolean) + (forms->boolean-network (hash 'x '(not y) + 'y 'x + 'z '(and y z)))] + [syn : Mode '((x y z))] + [asyn : Mode '((x) (y) (z))] + [dyn-syn (new (inst dynamics% Boolean) [network n1] [mode syn])] + [dyn-asyn (new (inst dynamics% Boolean) [network n1] [mode asyn])] + [s1 (hash 'x #f 'y #f 'z #f)]) + (test-case "dynamics%" + (check-equal? (send dyn-syn step/annotated s1) + '(((x y z) . #hash((x . #t) (y . #f) (z . #f))))) + (check-equal? (send dyn-asyn step/annotated s1) + '(((x) . #hash((x . #t) (y . #f) (z . #f))) + ((y) . #hash((x . #f) (y . #f) (z . #f))) + ((z) . #hash((x . #f) (y . #f) (z . #f)))))) - (define s1 (hash 'x #f 'y #f 'z #f)) - (check-equal? (send dyn-syn step/annotated s1) - '(((x y z) . #hash((x . #t) (y . #f) (z . #f))))) - (check-equal? (send dyn-asyn step/annotated s1) - '(((x) . #hash((x . #t) (y . #f) (z . #f))) - ((y) . #hash((x . #f) (y . #f) (z . #f))) - ((z) . #hash((x . #f) (y . #f) (z . #f))))) - )) + (test-case "dynamics%:step" + (check-equal? (send dyn-syn step s1) + '(#hash((x . #t) (y . #f) (z . #f)))) + (check-equal? (send dyn-asyn step s1) + '(#hash((x . #t) (y . #f) (z . #f)) + #hash((x . #f) (y . #f) (z . #f)) + #hash((x . #f) (y . #f) (z . #f))))) + ) + ) ) (require 'typed)