3 Dim passCount
As Integer
4 Dim failCount
As Integer
7 Function doUnitTest() As String
8 result
= verify_stringplusdouble()
9 If failCount
<> 0 And passCount
> 0 Then
16 Function verify_stringplusdouble() as String
20 result
= "Test Results" & Chr
$(10) & "============" & Chr
$(10)
25 result
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
26 verify_stringplusdouble
= result
30 Dim testName
As String
31 testName
= "double = string + double"
32 Dim testCompute
As String
38 On Error GoTo ErrorHandler
40 testCompute
= "s = null, d = null, r = s + d"
42 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
44 testCompute
= "s = null, d = null, r = s & d"
46 TestLog_ASSERT r
= 0, testCompute
& " .The result is: " & r
48 testCompute
= "s = null, d = 20, r = s + d"
51 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
53 testCompute
= "s = null, d = 20, r = s & d"
56 TestLog_ASSERT r
= 20, testCompute
& " .The result is: " & r
62 testCompute
= "s = '10', d = null, r = s + d"
64 TestLog_ASSERT r
= 10, testCompute
& " .The result is: " & r
66 testCompute
= "s = '10', d = null, r = s & d"
68 TestLog_ASSERT r
= 100, testCompute
& " .The result is: " & r
70 testCompute
= "s = '10', d = 20, r = s + d"
73 TestLog_ASSERT r
= 30, testCompute
& " .The result is: " & r
75 testCompute
= "s = '10', d = 20, r = s & d"
78 TestLog_ASSERT r
= 1020, testCompute
& " .The result is: " & r
83 testCompute
= "s = 'abc', d = null, r = s + d"
85 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
87 testCompute
= "s = 'abc', d = null, r = s & d"
89 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
91 testCompute
= "s = 'abc', d = 20, r = s + d"
94 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
96 testCompute
= "s = 'abc', d = 20, r = s & d"
99 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
105 ' TestLog_Comment "The next compute raises error: " & testCompute
111 Dim testName
As String
112 testName
= "string = string + double"
113 Dim testCompute
As String
119 On Error GoTo ErrorHandler
121 testCompute
= "s = null, d = null, r = s + d"
123 TestLog_ASSERT r
= "-1", testCompute
& " .The result is: " & r
125 testCompute
= "s = null, d = null, r = s & d"
127 TestLog_ASSERT r
= "0", testCompute
& " .The result is: " & r
129 testCompute
= "s = null, d = 20, r = s + d"
132 TestLog_ASSERT r
= "-1", testCompute
& " .The result is: " & r
134 testCompute
= "s = null, d = 20, r = s & d"
137 TestLog_ASSERT r
= "20", testCompute
& " .The result is: " & r
143 testCompute
= "s = '10', d = null, r = s + d"
145 TestLog_ASSERT r
= "10", testCompute
& " .The result is: " & r
147 testCompute
= "s = '10', d = null, r = s & d"
149 TestLog_ASSERT r
= "100", testCompute
& " .The result is: " & r
151 testCompute
= "s = '10', d = 20, r = s + d"
154 TestLog_ASSERT r
= "30", testCompute
& " .The result is: " & r
156 testCompute
= "s = '10', d = 20, r = s & d"
159 TestLog_ASSERT r
= "1020", testCompute
& " .The result is: " & r
164 testCompute
= "s = 'abc', d = null, r = s + d"
166 TestLog_ASSERT r
= "-1", testCompute
& " .The result is: " & r
168 testCompute
= "s = 'abc', d = null, r = s & d"
170 TestLog_ASSERT r
= "abc0", testCompute
& " .The result is: " & r
172 testCompute
= "s = 'abc', d = 20, r = s + d"
175 TestLog_ASSERT r
= "-1", testCompute
& " .The result is: " & r
177 testCompute
= "s = 'abc', d = 20, r = s & d"
180 TestLog_ASSERT r
= "abc20", testCompute
& " .The result is: " & r
185 ' TestLog_Comment "The next compute raises error: " & testCompute
190 Dim testName
As String
191 testName
= "double = string + string"
192 Dim testCompute
As String
198 On Error GoTo ErrorHandler
200 testCompute
= "s = null, d = null, r = s + d"
202 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
204 testCompute
= "s = null, d = null, r = s & d"
206 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
208 testCompute
= "s = null, d = 20, r = s + d"
211 TestLog_ASSERT r
= 20, testCompute
& " .The result is: " & r
213 testCompute
= "s = null, d = 20, r = s & d"
216 TestLog_ASSERT r
= 20, testCompute
& " .The result is: " & r
222 testCompute
= "s = '10', d = null, r = s + d"
224 TestLog_ASSERT r
= 10, testCompute
& " .The result is: " & r
226 testCompute
= "s = '10', d = null, r = s & d"
228 TestLog_ASSERT r
= 10, testCompute
& " .The result is: " & r
230 testCompute
= "s = '10', d = 20, r = s + d"
233 TestLog_ASSERT r
= 1020, testCompute
& " .The result is: " & r
235 testCompute
= "s = '10', d = 20, r = s & d"
238 TestLog_ASSERT r
= 1020, testCompute
& " .The result is: " & r
243 testCompute
= "s = 'abc', d = null, r = s + d"
245 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
247 testCompute
= "s = 'abc', d = null, r = s & d"
249 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
251 testCompute
= "s = 'abc', d = 20, r = s + d"
254 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
256 testCompute
= "s = 'abc', d = 20, r = s & d"
259 TestLog_ASSERT r
= -1, testCompute
& " .The result is: " & r
264 ' TestLog_Comment "The next compute raises error: " & testCompute
287 c
= a
+ b
' c = false
311 Sub TestLog_ASSERT(assertion
As Boolean, Optional testId
As String, Optional testComment
As String)
313 If assertion
= True Then
314 passCount
= passCount
+ 1
316 Dim testMsg
As String
317 If Not IsMissing(testId
) Then
318 testMsg
= testMsg
+ " : " + testId
320 If Not IsMissing(testComment
) And Not (testComment
= "") Then
321 testMsg
= testMsg
+ " (" + testComment
+ ")"
324 result
= result
& Chr
$(10) & " Failed: " & testMsg
325 failCount
= failCount
+ 1