racket-matrix-2012/os-big-bang-testing.rkt

27 lines
1.1 KiB
Racket

#lang racket/base
;; Utilities for testing os-big-bang worlds.
(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
;; (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?.
(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"))