3 Dim passCount
As Integer
4 Dim failCount
As Integer
7 Function doUnitTest() As String
8 result
= verify_testDateDiff()
9 If failCount
<> 0 Or passCount
= 0 Then
18 Function verify_testDateDiff() As String
23 result
= "Test Results" & Chr
$(10) & "============" & Chr
$(10)
25 Dim testName
As String
28 testName
= "Test DateDiff function"
29 On Error GoTo errorHandler
32 date1
= DateDiff("yyyy", "22/11/2003", "22/11/2013")
33 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
36 date1
= DateDiff("q", "22/11/2003", "22/11/2013")
37 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
40 date1
= DateDiff("m", "22/11/2003", "22/11/2013")
41 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
44 date1
= DateDiff("y", "22/11/2003", "22/11/2013")
45 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
48 date1
= DateDiff("d", "22/11/2003", "22/11/2013")
49 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
52 date1
= DateDiff("w", "22/11/2003", "22/11/2013")
53 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
56 date1
= DateDiff("ww", "22/11/2003", "22/11/2013")
57 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
60 date1
= DateDiff("h", "22/11/2003", "22/11/2013")
61 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
64 date1
= DateDiff("n", "22/11/2012", "22/11/2013")
65 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
68 date1
= DateDiff("s", "22/10/2013", "22/11/2013")
69 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
72 date1
= DateDiff("d", "22/11/2003", "22/11/2013", vbFriday
)
73 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
76 date1
= DateDiff("d", "22/11/2003", "22/11/2013", vbMonday
)
77 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
80 date1
= DateDiff("d", "22/12/2003", "22/11/2013", vbSaturday
)
81 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
84 date1
= DateDiff("d", "22/10/2003", "22/11/2013", vbSunday
)
85 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
88 date1
= DateDiff("d", "22/11/2003", "22/11/2013", vbThursday
)
89 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
92 date1
= DateDiff("d", "22/11/2003", "22/11/2013", vbTuesday
)
93 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
96 date1
= DateDiff("d", "22/11/2003", "22/11/2013", vbFriday
, vbFirstJan1
)
97 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
100 date1
= DateDiff("d", "22/11/2003", "22/11/2013", vbThursday
, vbFirstFourDays
)
101 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
104 date1
= DateDiff("d", "22/11/2003", "22/11/2013", vbSunday
, vbFirstFullWeek
)
105 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
108 date1
= DateDiff("d", "22/11/2003", "22/11/2013", vbSaturday
, vbFirstFullWeek
)
109 TestLog_ASSERT date1
= date2
, "the return DateDiff is: " & date1
111 result
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
112 verify_testDateDiff
= result
116 TestLog_ASSERT (False), testName
& ": hit error handler"
119 Sub TestLog_ASSERT(assertion
As Boolean, Optional testId
As String, Optional testComment
As String)
121 If assertion
= True Then
122 passCount
= passCount
+ 1
124 Dim testMsg
As String
125 If Not IsMissing(testId
) Then
126 testMsg
= testMsg
+ " : " + testId
128 If Not IsMissing(testComment
) And Not (testComment
= "") Then
129 testMsg
= testMsg
+ " (" + testComment
+ ")"
132 result
= result
& Chr
$(10) & " Failed: " & testMsg
133 failCount
= failCount
+ 1