Test Script Specification

Write a program to ensure the correct operation of GetPaddedStringFromLong. Test the following conditions:

Public Sub Test_GetPaddedStringFromLong()

    Dim iLoopCount As Integer  ' Loop count variable
    Dim lTestValue As Long     ' Parameter to be sent
    Dim sReply As String       ' Reply from function

    On Error GoTo Error_Test_GetPaddedStringFromLong

    ' Initialize variables.
    lTestValue = 1&

    ' Send initial debug message.
    Debug.Print "Starting test series for " & _
        "sPuFooGetPaddedStringFromLong at " & Now

    ' Test the length of each reply from an initial
    ' single numeric value (i.e., < 10), increasing in
    ' magnitude by a factor of 10 up to the billion
    ' range (i.e., 1 significant number and 9 zeros).
    ' =================================================

     For iLoopCount = 1 To 10

        ' Make a call to the function being tested.
        sReply = sPuFooGetPaddedStringFromLong(lTestValue)

        ' Check that the length is 10.
        If Len(sReply) <> 10 Then
            Debug.Print "Reply was wrong size on iteration " _
                & iLoopCount & "(" & sReply & ")"
        Else
            Debug.Print "Iteration " & iLoopCount & ": " _
                & sReply
        End If

        ' Increase of test parm by factor of 10
        If iLoopCount < 10 Then lTestValue = lTestValue * 10&

    Next

    ' Test for a zero value parameter.
    ' ===============================================
    
    ' Make a call to the function being tested.
    sReply = sPuFooGetPaddedStringFromLong(0&)
    
    ' Check that the reply is what we expect.
    If sReply <> "0000000000" Then
        Debug.Print "Zero check test failed (value:" & sReply & ")"
    Else
        Debug.Print "Zero check test succeeded"
    End If

    ' Test for negative value.
    ' ===============================================

    ' Make a call to the function being tested.
    sReply = sPuFooGetPaddedStringFromLong(-1&)

    If sReply <> "0000000000" Then
        Debug.Print "Negative value test failed (" _
            & sReply & ")"
    Else
        Debug.Print "Negative value test succeeded"
    End If

    ' Print end of sequence message.
    Debug.Print "Test_GetPaddedStringFromLong complete"

    GoTo Exit_Test_GetPaddedStringFromLong

Error_Test_GetPaddedStringFromLong:

    Debug.Print "Test_GetPaddedStringFromLong error: " _
        & Err.Description
    Err.Clear
    GoTo Exit_Test_GetPaddedStringFromLong

Exit_Test_GetPaddedStringFromLong:
    ' Common function exit point

End Sub

In the output from the test script, I have deliberately chosen two different styles of reporting the results of the run. The iteration test actually prints the results of each function call in the debug window to allow for a visual inspection of the returned data. However, for the two subsequent tests a more simple failed/succeeded message is displayed. Use either approach as necessary.

As an aside, you might notice that the test script is actually longer than the code that is being tested. Welcome to the world of professional software development! Now when you use your time-honored method of estimating how long a programming task will last and then doubling it, you won’t feel so guilty.