Test a function: Difference between revisions

Same changes for the second program.
(Actually do the changes indicated in previous edit.)
(Same changes for the second program.)
Line 1,256:
 
=={{header|Nim}}==
Using assertions (Nono output means all tests were correct,; this only works with debug builds!):
<lang nim>proc reversed(s: string): string =
result = newString(s.len)
Line 1,276:
assert(not isPalindrome("abab"))</lang>
 
Using the unittest“unittest” module:
<lang nim>import unittest
 
proc reversereversed(s: string): string =
result = newString(s.len)
for i, c in s:
result[s.high - i] = c
 
proc isPalindrome(s: string): bool =
s == reversereversed(s)
 
when isMainModule:
Line 1,303:
test "no palindrome":
check isPalindrome("foo") == false</lang>
 
Output:
{{out}}:
<pre>[OK] empty string
 
Anonymous user