2012-02-15 15:33:53 +00:00
|
|
|
#lang racket/base
|
2012-02-15 16:39:31 +00:00
|
|
|
;; Utilities for testing os-big-bang worlds.
|
2012-02-15 15:33:53 +00:00
|
|
|
|
|
|
|
(require racket/match)
|
|
|
|
(require rackunit)
|
|
|
|
(require "os-big-bang.rkt")
|
|
|
|
|
|
|
|
(provide check-message-handler)
|
|
|
|
|
|
|
|
(define (flatten-transition t)
|
|
|
|
(if (transition? t)
|
|
|
|
(transition (transition-state t) (transition-actions t)) ;; autoflattens
|
|
|
|
(transition t '()))) ;; wrap for convenient comparison
|
|
|
|
|
2012-02-15 16:39:31 +00:00
|
|
|
;; (on-message ...) World Any World ListOf<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?.
|
2012-02-15 15:33:53 +00:00
|
|
|
(define (check-message-handler mh initial-w message final-w expected-actions)
|
|
|
|
(match-define (on-message pattern handler) mh)
|
|
|
|
(check-true (pattern message) "Message-handler pattern did not match message provided")
|
|
|
|
(define v (match (handler message initial-w)
|
|
|
|
[(? transition? t) t]
|
|
|
|
[new-w (transition new-w '())]))
|
|
|
|
(check-equal? (flatten-transition v) (transition final-w expected-actions)
|
|
|
|
"Produced world-and-actions did not match expected world-and-actions"))
|