On May 22, 2015, at 8:19 AM, Robby Findler <ro...@eecs.northwestern.edu> wrote:

> Contracts mediate boundaries between parts of your program and sometimes 
> tests should go across the boundary (to help test the contracts) and 
> sometimes they should go inside (to test internal functions). You have to 
> pick one or the other with a given test module tho. 

Wouldn’t just this:
(module+ test
  (require (submod “..”))
  ; tests here
  )

Allow both of those things?

#lang racket
(provide
 (contract-out
   ; convert a fahrenheit temperature to a celsius
  [fahrenheit->celsius (-> (and/c number? (>=/c -459.67)) number?)]))
(define (fahrenheit->celsius f)
  (multiply-by-5/9 (- f 32)))
(define (multiply-by-5/9 x) ; not provided
  (* 5/9 x))
(module+ test
  (require rackunit (submod "..")) ; the (submod "..") makes it enforce the 
contracts
  (check-equal? (fahrenheit->celsius -40) -40)
  (check-equal? (fahrenheit->celsius 32) 0)
  (check-equal? (fahrenheit->celsius 212) 100)
  ;; this checks that it raises a contract-error
  (check-exn exn:fail:contract?
             (λ () (fahrenheit->celsius -500)))
  ;; this checks the internal unprovided function
  (check-equal? (multiply-by-5/9 18) 10)
  )


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to