Test a function: Difference between revisions

Content added Content deleted
No edit summary
Line 1:
{{task|Testing}}
Using a well known testing specific library/module/suite for your language, write some tests for your language's entry in [[Palindrome]]. If your language does not have a testing specific library well known to the language's community then state this or omit the language.
 
=={{header|ACL2}}==
 
Using [http://www.ccs.neu.edu/home/cce/acl2/doublecheck.html DoubleCheck]:
 
<lang Lisp>(defun reverse-split-at-r (xs i ys)
(if (zp i)
(mv xs ys)
(reverse-split-at-r (rest xs) (1- i)
(cons (first xs) ys))))
 
(defun reverse-split-at (xs i)
(reverse-split-at-r xs i nil))
 
(defun is-palindrome (str)
(let* ((lngth (length str))
(idx (floor lngth 2)))
(mv-let (xs ys)
(reverse-split-at (coerce str 'list) idx)
(if (= (mod lngth 2) 1)
(equal (rest xs) ys)
(equal xs ys)))))
 
(include-book "testing" :dir :teachpacks)
 
(check-expect (is-palindrome "abba") t)
(check-expect (is-palindrome "mom") t)
(check-expect (is-palindrome "dennis sinned") t)
(check-expect (is-palindrome "palindrome") nil)
(check-expect (is-palindrome "racecars") nil)
 
(include-book "doublecheck" :dir :teachpacks)
 
(defrandom random-palindrome ()
(let ((chars (random-list-of (random-char))))
(coerce (append chars (reverse chars))
'string)))
 
(defproperty palindrome-test
(p :value (random-palindrome))
(is-palindrome p))</lang>
 
=={{header|Ada}}==