3 Dim passCount
As Integer
4 Dim failCount
As Integer
7 Function doUnitTest() As String
8 result
= verify_testPartition()
9 If failCount
<> 0 And passCount
> 0 Then
16 Function verify_testPartition() as String
20 result
= "Test Results" & Chr
$(10) & "============" & Chr
$(10)
23 Dim testName
As String
25 testName
= "Test Partition function"
26 On Error GoTo errorHandler
28 retStr
= Partition(20, 0, 98, 5)
30 TestLog_ASSERT retStr
= "20:24", "the number 20 occurs in the range:" & retStr
32 retStr
= Partition(20, 0, 99, 1)
34 TestLog_ASSERT retStr
= " 20: 20", "the number 20 occurs in the range:" & retStr
36 retStr
= Partition(120, 0, 99, 5)
38 TestLog_ASSERT retStr
= "100: ", "the number 120 occurs in the range:" & retStr
40 retStr
= Partition(-5, 0, 99, 5)
42 TestLog_ASSERT retStr
= " : -1", "the number -5 occurs in the range:" & retStr
44 retStr
= Partition(2, 0, 5, 2)
46 TestLog_ASSERT retStr
= " 2: 3", "the number 2 occurs in the range:" & retStr
47 result
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
48 verify_testPartition
= result
51 TestLog_ASSERT (false), "vertify_testPartion failed, hit error handler"
54 Sub TestLog_ASSERT(assertion
As Boolean, Optional testId
As String, Optional testComment
As String)
56 If assertion
= True Then
57 passCount
= passCount
+ 1
60 If Not IsMissing(testId
) Then
61 testMsg
= testMsg
+ " : " + testId
63 If Not IsMissing(testComment
) And Not (testComment
= "") Then
64 testMsg
= testMsg
+ " (" + testComment
+ ")"
67 result
= result
& Chr
$(10) & " Failed: " & testMsg
68 failCount
= failCount
+ 1