Test a function: Difference between revisions
Content added Content deleted
No edit summary |
(Add Racket entry) |
||
Line 995: | Line 995: | ||
checkException(palindroc()) # TRUE |
checkException(palindroc()) # TRUE |
||
checkTrue(palindroc("")) # Error. Uh-oh, there's a bug in the function</lang> |
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}}== |
=={{header|Retro}}== |