From 70356487f886f9d22f99fec2a2969eb897f892b7 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 2 May 2012 13:54:22 -0400 Subject: [PATCH] Test utility for os2 tests. --- os2-testing.rkt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 os2-testing.rkt diff --git a/os2-testing.rkt b/os2-testing.rkt new file mode 100644 index 0000000..9e79a05 --- /dev/null +++ b/os2-testing.rkt @@ -0,0 +1,27 @@ +#lang racket/base +;; Utilities for testing os2.rkt worlds. + +(require racket/match) +(require rackunit) +(require (only-in racket/list flatten)) +(require "os2.rkt") + +(provide check-role) + +(define (flatten-transition t) + (if (transition? t) + (apply transition (transition-state t) (flatten (transition-actions t))) + (transition t))) + +;; AddRole World SendMessage World ConsTreeOf -> Void +;; Passes the given message to the given message-handler, with the +;; given initial-w. Compares the resulting world and list of actions +;; to the expected world and list of actions using check-equal?. +(define (check-role r initial-w sent-message final-w expected-actions) + (match-define ( _ _ (handlers _ _ message-handler)) r) + (match-define ( body role) sent-message) + (define synthetic-topic (topic role body #f)) + (define result (flatten-transition ((message-handler synthetic-topic body) initial-w))) + (check-equal? result + (flatten-transition (transition final-w expected-actions)) + "Produced world-and-actions did not match expected world-and-actions"))