Test a function: Difference between revisions

Content added Content deleted
(First program updated to work with Nim 1.6: added missing parameter types. Changed "reverse" to "reversed".)
(Actually do the changes indicated in previous edit.)
Line 1,257: Line 1,257:
=={{header|Nim}}==
=={{header|Nim}}==
Using assertions (No output means all tests were correct, only works with debug builds!):
Using assertions (No output means all tests were correct, only works with debug builds!):
<lang nim>proc reverse(s): string =
<lang nim>proc reversed(s: string): string =
result = newString(s.len)
result = newString(s.len)
for i, c in s:
for i, c in s:
result[s.high - i] = c
result[s.high - i] = c


proc isPalindrome(s): bool =
proc isPalindrome(s: string): bool =
s == reverse(s)
s == reversed(s)


when isMainModule:
when isMainModule: