• Class Numeric Assertion - debugged

    By Andrew Magerman 1 decade ago

    Tony, the NumericAssertion class has now been debugged. The problem links around to the unfortunate choice of

    RESULT_PASSED = 0 (i.e. False)

    and

    RESULT_FAILED = -1 (i.e. True)

    The function AssertNotEqual should be changed as well as follows:

    '/**
    ' * The assert not equals, calls the assert equals and checks the return value
    ' */
        Function AssertNotEqual(v1 As Variant, v2 As Variant) As Integer
            AssertNotEqual = RESULT_FAILED
            If (AssertEqual(v1,v2)) = RESULT_FAILED Then
                AssertNotEqual = RESULT_PASSED
            End If    
        End Function

    All the best,

    Andrew Magerman (andrew.magerman@magerman.com)

     

    '/**
    ' * Numeric assertion class, interprets object and check depending on numeric object type
    ' * such as Integer, Long, Double, Single and Currency.
    ' */
    Class NumericAssertion As AbstractAssertion
        ' REM updated by Andrew Magerman on 2011-05-10    
        Function AssertEqual(val1 As Variant, val2 As Variant) As Integer
            AssertEqual = RESULT_FAILED
            On Error Goto StoreError
            Select Case Datatype(val1)
                Case 2: 'V_INTEGER
                Dim int1 As Integer
                Dim int2 As Integer
                int1 = Cint(val1)
                int2 = Cint(val2)
                If (int1=int2) Then
                    AssertEqual = RESULT_PASSED
                End If
                Case 3: 'V_LONG
                Dim long1 As Long
                Dim long2 As Long
                long1 = Clng(val1)
                long2 = Clng(val2)
                If (long1 = long2) Then
                    AssertEqual = RESULT_PASSED
                End If            
                Case 4: 'V_SINGLE
                Dim sing1 As Single
                Dim sing2 As Single
                sing1 = Csng(val1)
                sing2 = Csng(val2)
                If (sing1 = sing2) Then
                    AssertEqual = RESULT_PASSED
                End If
                Case 5: 'V_DOUBLE
                Dim dbl1 As Double
                Dim dbl2 As Double
                dbl1 = Cdbl(val1)
                dbl2 = Cdbl(val2)
                If (dbl1 = dbl2) Then
                    AssertEqual = RESULT_PASSED
                End If
                Case 6: 'V_CURRENCY
                Dim cur1 As Currency
                Dim cur2 As Currency
                cur1 = Ccur(val1)
                cur2 = Ccur(val2)
                If (cur1 = cur2) Then
                    AssertEqual = RESULT_PASSED
                End If
            End Select
           
            Exit Function
    StoreError:
            m_error = Error
            AssertEqual=RESULT_FAILED
            Exit Function
        End Function
        
    End Class