Advertisement
Guest User

Rubberduck unit tests used for benchmarking

a guest
May 12th, 2015
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. Option Private Module
  3.  
  4. '@TestModule
  5. Private Assert As New Rubberduck.AssertClass
  6.  
  7. Private strTest(1 To 5000) As String
  8. Private strSentence As String
  9. Private sentenceLength As Long
  10.  
  11.  
  12. '@ModuleInitialize
  13. Public Sub ModuleInitialize()
  14.     'this method runs once per module.
  15.    Dim lngStringIter As Long
  16.     Dim lngChars As Long
  17.  
  18.     ' Generate  some long strings first
  19.    For lngStringIter = 1 To 5000
  20.         strTest(lngStringIter) = vbNullChar
  21.         For lngChars = 1 To 10
  22.             strTest(lngStringIter) = strTest(lngStringIter) & _
  23.                 Chr(Int((90 - 65 + 1) * Rnd + 65)) & strTest(lngStringIter)
  24.         Next lngChars
  25.     Next lngStringIter
  26.    
  27.     strSentence = StrConv("This is a string", vbUnicode)
  28.     sentenceLength = Len(strSentence)
  29.  
  30. End Sub
  31.  
  32. '@ModuleCleanup
  33. Public Sub ModuleCleanup()
  34.     'this method runs once per module.
  35. End Sub
  36.  
  37. '@TestInitialize
  38. Public Sub TestInitialize()
  39.     'this method runs before every test in the module.
  40. End Sub
  41.  
  42. '@TestCleanup
  43. Public Sub TestCleanup()
  44.     'this method runs afer every test in the module.
  45. End Sub
  46.  
  47. '@TestMethod
  48. Public Sub TestMid() 'TODO: Rename test
  49.    On Error GoTo TestFail
  50.    
  51.     'Arrange:
  52.    Dim lngStringIter As Long
  53.     Dim lngCount As Long
  54.     Dim output As String
  55.        
  56.     'Act:
  57.    For lngStringIter = 1 To 5000
  58.        
  59.         For lngCount = 1 To sentenceLength
  60.             output = Mid$(strSentence, lngCount, 1)
  61.         Next lngCount
  62.    
  63.     Next lngStringIter
  64.    
  65.     'Assert:
  66.    'Assert.Inconclusive
  67.  
  68. TestExit:
  69.     Exit Sub
  70. TestFail:
  71.     Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
  72. End Sub
  73.  
  74. '@TestMethod
  75. Public Sub TestSplit() 'TODO: Rename test
  76.    On Error GoTo TestFail
  77.    
  78.     'Arrange:
  79.    Dim lngStringIter As Long
  80.    
  81.     Dim strArray() As String
  82.     strArray = Split(strSentence, vbNullChar)
  83.    
  84.     Dim lngCount As Long
  85.     Dim output As String
  86.    
  87.     'Act:
  88.    For lngStringIter = 1 To 5000
  89.    
  90.         For lngCount = 0 To UBound(strArray)
  91.             output = strArray(lngCount)
  92.         Next lngCount
  93.    
  94.     Next lngStringIter
  95.    
  96.     'Assert:
  97.    'Assert.Inconclusive
  98.  
  99. TestExit:
  100.     Exit Sub
  101. TestFail:
  102.     Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
  103. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement