[racket] Tests before of to define the function

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Jul 10 17:00:04 EDT 2013

On Jul 10, 2013, at 4:55 PM, Juan Francisco Cantero Hurtado <iam at juanfra.info> wrote:

> In Beginning Student mode I can to define a test before of the function:
> 
> (check-expect (double 2) 4)
> (define (double n)
>    (* n 2))
> 
> In #lang racket, the next code fails:
> 
> (require rackunit)
> (check-equal? (double 2) 4)
> (define (double n)
>    (* n 2))
> 
> Is it possible to write the tests before of the functions in racket, like in BS?
> 
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users


#lang racket 

(module+ test ;; I like to specify dependencies for test submodules in a test submodule: 
 (require rackunit))

;; N -> N
;; double the given number

(module+ test
 (check-equal? (double 2) 4)
 (check-equal? (double 2) 3))
 
(define (double n)
 (* n 2))

Posted on the users mailing list.