Test a function: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Improved output.) |
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
||
Line 1,460: | Line 1,460: | ||
=={{header|Phix}}== |
=={{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( |
<span style="color: #000080;font-style:italic;">--set_test_verbosity(TEST_QUIET) -- (default, no output when third call removed) |
||
set_test_verbosity( |
--set_test_verbosity(TEST_SUMMARY) -- (first and last line only [w or w/o ""]) |
||
⚫ | |||
<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(0) -- (disable pause on failure) |
|||
--set_test_pause(1) |
--set_test_pause(-1) -- (pause on failure [default]) |
||
⚫ | |||
--set_test_pause(1) -- (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> |
|||
⚫ | |||
<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") |
|||
⚫ | |||
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. |
Note the default behaviour, if set_test_verbosity() is not invoked, is no output and carry on as normal when all tests pass. |
||
{{out}} |
{{out}} |