Test a function: Difference between revisions
Content added Content deleted
m (→{{header|zkl}}: tweak) |
m (→{{header|zkl}}: update) |
||
Line 1,629: | Line 1,629: | ||
text==text.reverse(); |
text==text.reverse(); |
||
}</lang> |
}</lang> |
||
<lang zkl>tester:=TheVault.Test.UnitTester.UnitTester(); |
<lang zkl>tester:=TheVault.Test.UnitTester.UnitTester(__FILE__); |
||
// spaces make this not a palindrome |
|||
tester.testRun(pali.fp("red rum sir is murder"), Void,False,__LINE__);</lang> |
|||
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. |
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}} |
||
Line 1,638: | Line 1,639: | ||
</pre> |
</pre> |
||
A test file: |
A test file: |
||
<lang zkl>tester:=TheVault.Test.UnitTester.UnitTester(); |
<lang zkl>tester:=TheVault.Test.UnitTester.UnitTester(__FILE__); |
||
fcn pali(text){ |
fcn pali(text){ |
||
if (text.len()<2) return(False); |
if (text.len()<2) return(False); |
||
Line 1,649: | Line 1,650: | ||
tester.stats(); |
tester.stats(); |
||
returnClass(tester);</lang> |
returnClass(tester);</lang> |
||
<lang zkl>zkl |
<lang zkl>zkl paliTest.zkl</lang> |
||
{{output}} |
{{output}} |
||
<pre> |
<pre> |
||
======== Unit Test 1 =====paliTest.zkl==6======== |
|||
Test 1 passed! |
Test 1 passed! |
||
======== Unit Test 2 =====paliTest.zkl==7======== |
|||
Result and expected result are different: False True |
Result and expected result are different: False True |
||
Test 2 failed. I hate it when that happens (line |
Test 2 failed. I hate it when that happens (line 7). |
||
======== Unit Test 3 =====paliTest.zkl==8======== |
|||
Test 3 passed! |
Test 3 passed! |
||
3 tests completed. |
3 tests completed. |
||
Line 1,664: | Line 1,665: | ||
</pre> |
</pre> |
||
If you had a collection of files to test: |
If you had a collection of files to test: |
||
<lang zkl>zkl Test.testThemAll -- |
<lang zkl>zkl Test.testThemAll -- paliTest.zkl</lang> |
||
{{output}} |
{{output}} |
||
<pre> |
<pre> |
||
Line 1,671: | Line 1,672: | ||
---------|00:00:00|---------- |
---------|00:00:00|---------- |
||
----------------------------- |
----------------------------- |
||
paliTest.zkl |
|||
3 tests completed. |
3 tests completed. |
||
Passed test(s): 2 (of 3) |
Passed test(s): 2 (of 3) |