Skip to content

Maybe incorrect behaviour of Assert.AreEqual #6130

Open
@FullValueRider

Description

@FullValueRider

Rubberduck version information

Version 2.5.9.6291
OS: Microsoft Windows NT 10.0.22631.0, x64
Host Product: Microsoft Office x64
Host Version: 16.0.16529.20154
Host Executable: EXCEL.EXE

Description
Due to serveral copypasta typos on my part an 'Assert.AreEqual' test was passed variants containing a 10 item array and a 4 item array respectively. The assertion passed. I only noted the error when I transferred the VBA code to twinbasic.

The background to this is that I have revised the Test method template to produce a method that can be used in both VBA and twinBasic without the need for a unit tester.

This is the code leading to the error above.

'@TestMethod("ArrayInfo")
Public Sub Test02a_IsArray()

    #If twinbasic Then
        myProcedureName = CurrentProcedureName
        myComponentName = CurrentComponentName
    #Else
        myProcedureName = ErrEx.LiveCallstack.ProcedureName
        myComponentName = ErrEx.LiveCallstack.ModuleName
    #End If

    On Error GoTo TestFail
    'Arrange
    Dim myExpected As Variant: myExpected = Array(False, True, True, True, True, True, True, False, False, False)

    Dim myResult As Variant
    ReDim myResult(0 To 9)
    'act
    Dim myEMptyArray As Variant: myEMptyArray = Array()
    Dim myListArray As Variant: myListArray = Array(1, 2, 3, 4, 5)
    Dim myTableArray As Variant: myTableArray = MakeTableArray(3, 3)
    Dim my3dArray As Variant: my3dArray = Make3DArray(3, 3, 3)
    
    myResult(0) = ArrayInfo.IsArray(myEMptyArray)
    myResult(1) = ArrayInfo.IsArray(myListArray)
    myResult(2) = ArrayInfo.IsArray(myTableArray)
    myResult(3) = ArrayInfo.IsArray(my3dArray)
    
    myResult(1) = ArrayInfo.IsArray(myListArray, m_ListArray)
    myResult(2) = ArrayInfo.IsArray(myTableArray, m_TableArray)
    myResult(3) = ArrayInfo.IsArray(my3dArray, m_MDArray)
    
    myResult(1) = ArrayInfo.IsArray(myListArray, m_TableArray)
    myResult(2) = ArrayInfo.IsArray(myTableArray, m_MDArray)
    myResult(3) = ArrayInfo.IsArray(my3dArray, m_ListArray)
    'Assert:
    AssertStrictAreEqual myExpected, myResult, myProcedureName
    
TestExit:
    Exit Sub
TestFail:
    Debug.Print myComponentName, myProcedureName, " raised an error: #" & Err.Number & " - " & Err.Description
    Resume TestExit
    
End Sub

'  and

Public Sub AssertStrictAreEqual(ByRef ipExpected As Variant, ipResult As Variant, ipWhere As String)
    
#If twinbasic Then
        Assert.Strict.AreEqual ipExpected, ipResult, ipWhere
#Else
    Assert.AreEqual ipExpected, ipResult, ipWhere
#End If

End Sub

Two points to note.

  1. I have an error in the test as I did not update the indexes for the result variable resulting in a 4 item array rather than the expected 10 item array.
  2. Due to a copy pasta error I have the rubberduck assert test as 'AreEqual' equal rather than SequenceEquals.
    '
    myTypical experience of incorrectly passing passing arrays to 'AreEqual' are that I get a helpful error message. However, in the case of the above code the assertion 'AreEqual' passes, presumably because the first item in each array is the same ( True) although I can't help feeling that the fact that the arrays have been passed as parameters before assertion testing is part of the problem.

Expected behavior
If the 'AreEqual' assertion receives variants containing arrays it should produce the usual helpful error message of suggesting to use 'SequenceEquals'.

Update possibly an even more serious issue. In the test method above I changed

 AssertStrictAreEqual myExpected, myResult, myProcedureName

to

Assert.SequenceEquals myExpected, myResult, myProcedureName

I used the test method above (with the myResult indexing error) so the sequence equals was comparing 10 item and four Item arrays. Unfortunately the Assertion passed.

I even changed the first item in result in expected to True, but the assertion still passed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIdentifies work items for known bugs

    Type

    No type

    Projects

    Status

    Backlog | Unit Testing

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions