Jump to content

Test a function: Difference between revisions

m
→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics
(→‎{{header|Wren}}: Improved output.)
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
Line 1,460:
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
<lang Phix>requires("0.8.2")
<!--<lang Phix>-->
 
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"0.8.2"</span><span style="color: #0000FF;">)</span>
function is_palindrome(sequence s)
return s==reverse(s)
<span style="color: #008080;">function</span> <span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #008080;">return</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">==</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
--set_test_verbosity(TEST_QUIET) -- (default, no output when third call removed)
--set_test_verbosity(TEST_SUMMARY) -- (first and last line only [w or w/o ""])
<span style="color: #000080;font-style:italic;">--set_test_verbosity(TEST_SHOW_FAILEDTEST_QUIET) -- (firstdefault, no andoutput lastwhen twothird linescall onlyremoved)
--set_test_verbosity(TEST_SHOW_ALLTEST_SUMMARY) -- (asfirst shown inand last twoline only [w or casesw/o below""])
--set_test_verbosity(TEST_SUMMARYTEST_SHOW_FAILED) -- (first and last linetwo lines only [w or w)</o ""])span>
 
<span style="color: #7060A8;">set_test_verbosity</span><span style="color: #0000FF;">(</span><span style="color: #004600;">TEST_SHOW_ALL</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (as shown in last two cases below)
--set_test_pause(-1) -- (pause on failure [default])
--set_test_pause(0) -- (disable pause on failure)
--set_test_pause(-1) -- (always pause on failure [default])
--set_test_pause(-10) -- (disable pause on failure [default])
 
set_test_module --set_test_pause("palindromes"1) -- (optional, w/o first line is omitted -- (always pause)</span>
 
<span style="color: #7060A8;">set_test_module</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"palindromes"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (optional, w/o first line is omitted)</span>
test_true(is_palindrome("abba"),"abba")
test_true(is_palindrome("abba")) -- (no desc makes success hidden...)
<span style="color: #7060A8;">test_true</span><span style="color: #0000FF;">(</span><span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"abba"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"abba"</span><span style="color: #0000FF;">)</span>
-- (...and failure somewhat laconic)
<span style="color: #7060A8;">test_true</span><span style="color: #0000FF;">(</span><span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"abba"</span><span style="color: #0000FF;">))</span> <span style="color: #000080;font-style:italic;">-- (no desc makes success hidden...)
test_false(is_palindrome("abc"),"not abc")
-- (...and failure somewhat laconic)</span>
test_true(is_palindrome("failure"),"failure")
<span style="color: #7060A8;">test_false</span><span style="color: #0000FF;">(</span><span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"abc"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"not abc"</span><span style="color: #0000FF;">)</span>
 
<span style="color: #7060A8;">test_true</span><span style="color: #0000FF;">(</span><span style="color: #000000;">is_palindrome</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"failure"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"failure"</span><span style="color: #0000FF;">)</span>
test_summary()</lang>
<span style="color: #7060A8;">test_summary</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
Note the default behaviour, if set_test_verbosity() is not invoked, is no output and carry on as normal when all tests pass.
{{out}}
7,818

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.