RosettaCodeData/Task/Test-a-function/Nim/test-a-function-2.nim
2016-12-05 23:44:36 +01:00

26 lines
511 B
Nim

import unittest
proc reverse(s): string =
result = newString(s.len)
for i,c in s:
result[s.high - i] = c
proc isPalindrome(s): bool =
s == reverse(s)
when isMainModule:
suite "palindrome":
test "empty string":
check isPalindrome ""
test "string of length 1":
check isPalindrome "a"
test "string of length 2":
check isPalindrome "aa"
test "string of length 3":
check isPalindrome "aaa"
test "no palindrome":
check isPalindrome("foo") == false