<-- Previous || Up || Next -->

Unit Test Function
Units Class

Function UnitTest( _
    ) As Integer
    ' Find units which cannot be parsed by the conversion program.

    Const strFn = "UnitTest"
    Debug.Print strFn & ": Info: Begin " & Time

    ' Assume that the definitions are valid; will reset return value to False when
    ' and if errors are found in the definitions.
    UnitTest = True

    InitializeMaybe

    Dim lngCurUnit As Long
    For lngCurUnit = 1 To GetUnitCount
        If estBE.TrueEveryNSeconds(30) Then
            Debug.Print strFn & ": Info: checking unit #" & lngCurUnit & " of " & GetUnitCount & " " & Time
        End If

        Dim strUniCode As String
        Dim strUniCodeStr As String
        Dim strUniName As String
        Dim dblUniConst As Double
        Dim strUniDef As String
        Dim strUniDefPar As String
        Dim strUniCat As String

        If Not GetUnit(lngCurUnit, strUniCode, strUniCodeStr, strUniName, dblUniConst, strUniDef, strUniDefPar, strUniCat) Then
            UnitTest = False
            Exit Function
        End If

        ' Try parsing the unit code itself.
        Dim strUnitCode As String
        strUnitCode = strUniCode
        Dim varRtn As Variant
        varRtn = ConvertMeasure(1, strUnitCode, "")
        If IsNull(varRtn) Or InStr(1, varRtn, ":", vbBinaryCompare) <> 0 Then
            Debug.Print strFn & ": Error: error parsing " & strUnitCode & "; definition: " & dblUniConst & " " & strUniDef & "; result: " & varRtn
            UnitTest = False
        End If

        ' See if the Category specified for the current unit names a Category which was previously unknown within the
        ' units table--developer should consider creating a separate Category-type unit definition for the category.
        strUnitCode = strUniCode
        varRtn = FindCategory(strUnitCode)
        If StrComp(varRtn, "unknown", vbTextCompare) = 0 Or InStr(1, varRtn, "reciprocal of ", vbTextCompare) = 1 Then
            If StrComp(strUniCat, "unknown", vbTextCompare) <> 0 Then
                Debug.Print strFn & ": Error: unknown category unit " & strUnitCode & "; definition: " & dblUniConst & " " & strUniDef & "; result: " & varRtn
                UnitTest = False
            End If
        End If

        ' Find cases where the user-specified Category does not match the actual/calculated Category.
        If StrComp(strUniCat, varRtn, vbTextCompare) <> 0 Then
            ' This is just a warning, not a fatal error.
            Debug.Print strFn & ": Warning: unit " & strUnitCode & "; user-specified category: " & strUniCat & "; calculated category: " & varRtn
        End If

        ' Try parsing the randomly-capitalized version of the unit code.
        strUnitCode = estSE.RandomCapitalize(strUniCode)
        varRtn = ConvertMeasure(1, strUnitCode, "")
        If IsNull(varRtn) Or InStr(1, varRtn, ":", vbBinaryCompare) <> 0 Then
            Debug.Print strFn & ": Error: error parsing randomly capitalized " & strUnitCode & "; definition: " & dblUniConst & " " & strUniDef & "; result: " & varRtn
            UnitTest = False
        End If
    Next lngCurUnit

    Debug.Print strFn & ": Info: End " & Time
End Function

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.