;; ;; FILE: rackunit-example.rkt ;; AUTHOR: Eugene Wallingford ;; UPDATED: 2011/02/02 ;; COMMENT: A program that uses the rackunit module to define ;; unit tests for function. ;; #lang racket ; -- The following expression says that this file requires ; -- functions exported by the rackunit module. The name ; -- "rackunit" is not quoted like a string, which indicates ; -- that is in Racket's standard path. require is similar ; -- to "import" in Python and Java. (require rackunit) ; -- The rest of the file is like any other program file, except ; -- that it can use names exported by the file that we required. ; -- Here, I define a simple function. (define square (lambda (n) (* n n))) ; -- Among the functions that the rackunit module provides is ; -- check-equal?, which compares the result of an evaluation ; -- to an expected value. We can use it to check whether ; -- our function behaves as expected. (check-equal? (square 1) 1) (check-equal? (square 7) 49) (check-equal? (square 9) 81) ; -- We can use rackunit to define automated tests for the ; -- functions we write. We will use rackunit tests for most ; -- of our code and homework assignments this semester.