racket-matrix-2012/os2-testing.rkt

26 lines
1.0 KiB
Racket

#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)
(apply transition (transition-state t) (flatten (transition-actions t))))
;; AddRole World SendMessage World ConsTreeOf<Action> -> 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 (<add-role> _ _ (handlers _ _ message-handler)) r)
(match-define (<send-message> 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"))