Jump to content

Test a function: Difference between revisions

Added UNIX Shell solution
m (omissions)
(Added UNIX Shell solution)
Line 1,247:
<pre>palindrome.test: Total 3 Passed 3 Skipped 0 Failed 0</pre>
Note that only a small fraction of the features of the testing framework are demonstrated here. In particular, it does not show off management of conditional execution, the application of setup and cleanup code, and how these things are assembled into a whole test suite for a large system.
 
=={{header|UNIX Shell}}==
<lang sh>#!/bin/bash
 
is_palindrome() {
local s1=$1
local s2=$(echo $1 | tr -d "[ ,!:;.'\"]" | tr '[A-Z]' '[a-z]')
 
if [[ $s2 = $(echo $s2 | rev) ]]
then
echo "[$s1] is a palindrome"
else
echo "[$s1] is NOT a palindrome"
fi
}
 
 
is_palindrome "A man, a plan, a canal, Panama!"
is_palindrome "Madam, I'm Adam"
is_palindrome "1 on 1"</a>
 
{{omit from|GUISS}}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.