1ExecuteAFile (PATH_TO_CURRENT_BF + "TestTools.ibf"); 2runATest (); 3 4 5function getTestName () { 6 return "assert"; 7} 8 9 10function runTest () { 11 ASSERTION_BEHAVIOR = 1; /* print warning to console and go to the end of the execution list */ 12 testResult = TRUE; 13 14 15 //--------------------------------------------------------------------------------------------------------- 16 // SIMPLE FUNCTIONALITY 17 //--------------------------------------------------------------------------------------------------------- 18 // Assert is used for unit testing. The expression must evaluate to a Numeric, and it will fail if it returns 0 (a numerical false). Non-numeric expressions will cause an execution terminating error. 19 // If the assert passes, it will return nothing. The batch file will gleefully move on and execute subsequent commands. 20 // If the assert fails, it will greet the respective batch file executor with a generic (if error_statement is missing) or a custom error message. It will state what is in the error_statement. The executor will then either choose to move on, or halt the script from processing. 21 22 // Passes with any non zero numeric value 23 assert(1, "assert didn't work as expected, it shouldn't fail with value of 1"); 24 assert(0.01, "assert didn't work as expected, it shouldn't fail with value of 0.01"); 25 assert(100, "assert didn't work as expected, it shouldn't fail with value of 100"); 26 assert(-1, "assert didn't work as expected, it shouldn't fail with value of -1"); 27 28 //--------------------------------------------------------------------------------------------------------- 29 // ERROR HANDLING 30 //--------------------------------------------------------------------------------------------------------- 31 list1 = {'key1':'val1', 'key2':'val2'}; 32 matrix1 = {{0.3,0.4}}; 33 Topology T1 = ((1,4),(3,4),5); 34 Tree TT1 = ((1,2),(3,4),5); 35 36 assert (runCommandWithSoftErrors ('assert(list1);', "did not evaluate to a Number in call to assert"), "Failed error checking for assert returning a list"); 37 assert (runCommandWithSoftErrors ('assert(matrix1);', "did not evaluate to a Number in call to assert"), "Failed error checking for assert returning a matrix"); 38 assert (runCommandWithSoftErrors ('assert(T1);', "did not evaluate to a Number in call to assert"), "Failed error checking for assert returning a topology"); 39 assert (runCommandWithSoftErrors ('assert(TT1);', "did not evaluate to a Number in call to assert"), "Failed error checking for assert returning a tree"); 40 41 testResult = 1; 42 43 return testResult; 44} 45