Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Option Private Module
- '@TestModule
- Private Assert As New Rubberduck.AssertClass
- Private strTest(1 To 5000) As String
- Private strSentence As String
- Private sentenceLength As Long
- '@ModuleInitialize
- Public Sub ModuleInitialize()
- 'this method runs once per module.
- Dim lngStringIter As Long
- Dim lngChars As Long
- ' Generate some long strings first
- For lngStringIter = 1 To 5000
- strTest(lngStringIter) = vbNullChar
- For lngChars = 1 To 10
- strTest(lngStringIter) = strTest(lngStringIter) & _
- Chr(Int((90 - 65 + 1) * Rnd + 65)) & strTest(lngStringIter)
- Next lngChars
- Next lngStringIter
- strSentence = StrConv("This is a string", vbUnicode)
- sentenceLength = Len(strSentence)
- End Sub
- '@ModuleCleanup
- Public Sub ModuleCleanup()
- 'this method runs once per module.
- End Sub
- '@TestInitialize
- Public Sub TestInitialize()
- 'this method runs before every test in the module.
- End Sub
- '@TestCleanup
- Public Sub TestCleanup()
- 'this method runs afer every test in the module.
- End Sub
- '@TestMethod
- Public Sub TestMid() 'TODO: Rename test
- On Error GoTo TestFail
- 'Arrange:
- Dim lngStringIter As Long
- Dim lngCount As Long
- Dim output As String
- 'Act:
- For lngStringIter = 1 To 5000
- For lngCount = 1 To sentenceLength
- output = Mid$(strSentence, lngCount, 1)
- Next lngCount
- Next lngStringIter
- 'Assert:
- 'Assert.Inconclusive
- TestExit:
- Exit Sub
- TestFail:
- Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
- End Sub
- '@TestMethod
- Public Sub TestSplit() 'TODO: Rename test
- On Error GoTo TestFail
- 'Arrange:
- Dim lngStringIter As Long
- Dim strArray() As String
- strArray = Split(strSentence, vbNullChar)
- Dim lngCount As Long
- Dim output As String
- 'Act:
- For lngStringIter = 1 To 5000
- For lngCount = 0 To UBound(strArray)
- output = strArray(lngCount)
- Next lngCount
- Next lngStringIter
- 'Assert:
- 'Assert.Inconclusive
- TestExit:
- Exit Sub
- TestFail:
- Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement