Jump to content

Test a function: Difference between revisions

Add Racket entry
No edit summary
(Add Racket entry)
Line 995:
checkException(palindroc()) # TRUE
checkTrue(palindroc("")) # Error. Uh-oh, there's a bug in the function</lang>
 
=={{header|Racket}}==
 
Racket has a built-in unit testing library. Tests can be specified next to function implementations or in a testing submodule.
 
<lang lisp>
#lang racket
(module+ test (require rackunit))
 
;; from the Palindrome entry
(define (palindromb str)
(let* ([lst (string->list (string-downcase str))]
[slst (remove* '(#\space) lst)])
(string=? (list->string (reverse slst)) (list->string slst))))
 
;; this test module is not loaded unless it is
;; specifically requested for testing, allowing internal
;; unit test specification
(module+ test
(check-true (palindromb "racecar"))
(check-true (palindromb "avoova"))
(check-false (palindromb "potato")))
</lang>
 
=={{header|Retro}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.