Test a function: Difference between revisions

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