[Gambas-user] Test Module, First try

Christof Thalhofer chrisml at deganius.de
Sun Jul 26 20:48:50 CEST 2020


Btw: I saw something I do not recommend for testing situations.

You used 'Try' together with 'If Error Then'. I can only say that I have
a bad feeling with that. Because at minimum Error should be cleared
afterwards with Error.Clear, which does not happen in your code.

I add a version of the function CompareStringArray to show that the same
can be achieved without 'Try' through the nice (or ugly depending on the
view) trick:

bResult = sA[i] = sB[i]

Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur
-------------- next part --------------
'' **************************************************************************************
'' Test Support routines
'' **************************************************************************************
Public Sub CompareStringArray(sA As String[], sB As String[]) As Boolean

  Dim bResult As Boolean = True
  Dim bFinalResult As Boolean = True
  Dim sPrintLine As String

  For i As Integer = 0 To IIf(sA.max > sB.max, sA.max, sB.max)
    bResult = sA[i] = sB[i]
    If Not bResult Then bFinalResult = False
  Next

  If bFinalResult = False Then
    Test.Note(Subst("Compare size a=&1, b=&2", sA.count, sB.count))
    For i As Integer = 0 To IIf(sA.max > sB.max, sA.max, sB.max)
      bResult = sA[i] = sB[i]

      sPrintLine = Format(i + 1, "000#") & IIf(bResult = True, " = ", " - ")
      If i <= sA.max Then
        sPrintLine &= Mid(Replace(Quote(sA[i]), " ", ".") & Space(38), 1, 38) & " | "
      Else
        sPrintLine &= Space(25) & " | "
      Endif
      If i <= sB.max Then
        sPrintLine &= Mid(Replace(Quote(sB[i]), " ", ".") & Space(38), 1, 38)
      Endif
      Test.Note(sPrintLine)
    Next
  Endif

  Return bFinalResult

End

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200726/89aeb87c/attachment.sig>


More information about the User mailing list