Test a function: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Add Fortran.) |
m (→{{header|zkl}}: tweak) |
||
Line 1,626: | Line 1,626: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
<lang zkl>fcn pali(text){ |
<lang zkl>fcn pali(text){ |
||
if (text.len() |
if (text.len()<2) return(False); |
||
text==text.reverse(); |
|||
[0..text.len()/2].filter1('wrap(n){text[n] != text[-n-1]}) : |
|||
return(_ == False); |
|||
}</lang> |
}</lang> |
||
<lang zkl>tester:=TheVault.Test.UnitTester.UnitTester(); |
<lang zkl>tester:=TheVault.Test.UnitTester.UnitTester(); |
||
tester.testRun(pali.fp("red rum sir is murder"), Void,False);</lang> |
tester.testRun(pali.fp("red rum sir is murder"), Void,False); // spaces make this not a palindrome</lang> |
||
Need to create a closure so the unit test is what runs the test function and can catch any errors the test function throws. |
Need to create a closure (.fp) so the unit test is what runs the test function and can catch any errors the test function throws. |
||
{{output}} |
{{output}} |
||
<pre> |
<pre> |
||
Line 1,641: | Line 1,640: | ||
<lang zkl>tester:=TheVault.Test.UnitTester.UnitTester(); |
<lang zkl>tester:=TheVault.Test.UnitTester.UnitTester(); |
||
fcn pali(text){ |
fcn pali(text){ |
||
if (text.len() |
if (text.len()<2) return(False); |
||
text==text.reverse(); |
|||
[0..text.len()/2].filter1('wrap(n){text[n] != text[-n-1]}) : |
|||
return(_ == False); |
|||
} |
} |
||
tester.testRun(pali.fp("red rum sir is murder"-" "), Void,True,__LINE__); |
tester.testRun(pali.fp("red rum sir is murder" - " "), Void,True,__LINE__); |
||
tester.testRun(pali.fp("red rum sir is murder"), Void,True,__LINE__); // |
tester.testRun(pali.fp("red rum sir is murder"), Void,True,__LINE__); //bad test |
||
tester.testSrc("var R=(1+2)",Void,Void,3,__LINE__); // you can test source too |
tester.testSrc("var R=(1+2)",Void,Void,3,__LINE__); // you can test source too |
||