February 21, 2009

WinTask - Test Data Generator



This is a handy collection of WinTask test data generation functions



'
' Test Data Generator
'
' Author: Joe Strazzere

Dim FirstM$(1000)
Dim FirstF$(1000)
Dim FirstA$(1000)
Dim LastA$(1000)
Dim States$(1000)
Dim StateAs$(1000)
Dim Provinces$(1000)
Dim Cities$(1000)
Dim Lipsum$(1000)

' Returns a random string based on the picture supplied.
'
' This can be useful for generating large amounts of psuedo-random data for testing.
'
' picture is a string with special characters interpreted as follows:
'
' 9 = generate a random number (0-9) in its place
' A = generate a random alphabetic character (A-Z, a-z) in its place
' U = generate a random uppercase alphabetic character (A-Z) in its place
' L = generate a random lowercase alphabetic character (a-z) in its place
' N = generate a random alphanumeric character (A-Z, a-z, 0-9) in its place
' X = generate any character in its place
' = an escape character.  Anything following this character is placed in the result string,
'     even if it is a picture character.  Two backslashes () cause a single backslash to be
'     placed into the result string.
' any other character is simply copied into the result string
Function RandStr$(test$)
    Local i
    Local a
    Local new$
    Local work$
    work$=""
    i=1
    While i<= len(test$)
        Select Case Mid$(test$,i,1)
            Case ""
                 i=i+1
                 new$=Mid$(test$,i,1)
            Case "9"
                 new$=str$(Random(9))
            Case "X"
                 new$=Chr$(Random(93)+33)
            Case "U"
                 new$=Chr$(Random(25)+65)
            Case "L"
                 new$=Chr$(Random(25)+97)
            Case "A"
                 Repeat
                     a = Random(57)+65
                 Until a < 91 Or a >96
                 new$=Chr$(a)
            Case "N"
                 Repeat
                     a = Random(74)+48
                 Until a < 58 Or (a >64 And a <91) Or a > 96
                 new$=Chr$(a)
            Case Else
                 new$=Mid$(test$,i,1)
        EndSelect
        work$=work$+new$
        i=i+1
    Wend
    RandStr$=work$
EndFunction

'Zip Code
Function ZipCode$()
    ZipCode$=RandStr$("99999")
EndFunction

'Zip+4 Code
Function ZipPlus4$()
    ZipPlus4$=RandStr$("99999-9999")
EndFunction

'Canadian Postal Code
Function CAPostalCode$()
    CAPostalCode$=RandStr$("U9U 9U9")
EndFunction

'Social Security Number
Function SocSec$()
    SocSec$=RandStr$("999-99-9999")
EndFunction

'Phone Number
Function Phone$()
    Phone$=RandStr$("(999) 999-9999")
EndFunction

'Random Date - between two dates
Function RandomDate$(FromDate$,ToDate$)
    Local days
    Local rand
    days=DateBetween("d",FromDate$,ToDate$)
    rand=Random(Days)
    RandomDate$=DateToDate$("d",rand,FromDate$)
EndFunction

'Male First Name
Function MaleFirst$()
    MaleFirst$=FirstM$(Random(FirstMCount))
EndFunction

'Female First Name
Function FemaleFirst$()
    FemaleFirst$=FirstF$(Random(FirstFCount))
EndFunction

'First Name (Male or Female)
Function FirstName$()
    FirstName$=FirstA$(Random(FirstACount))
EndFunction

'Last Name
Function LastName$()
    LastName$=LastA$(Random(LastACount))
EndFunction

'First then Last name
Function FirstLastName$()
    FirstLastName$=FirstA$(Random(FirstACount))+" "+LastA$(Random(LastACount))
EndFunction

'First, Middle Initial, Last name
Function FirstMLastName$()
    FirstMLastName$=FirstA$(Random(FirstACount))+" "+RandStr$("U")+". "+LastA$(Random(LastACount))
EndFunction

'Last, comma, First name
Function LastFirstName$()
    LastFirstName$=LastA$(Random(LastACount))+", "+FirstA$(Random(FirstACount))
EndFunction

'State Name
Function StateName$()
    StateName$=States$(Random(StateCount))
EndFunction

'State Abbreviation
Function StateAbbr$()
    StateAbbr$=StateAs$(Random(StateACount))
EndFunction

'Canadian Province Name
Function ProvinceName$()
    ProvinceName$=Provinces$(Random(ProvinceCount))
EndFunction

'City Name
Function CityName$()
    CityName$=Cities$(Random(CityCount))
EndFunction

'Lorem Ipsum Word
Function LipsumWord$()
    LipsumWord$=Lipsum$(Random(LipsumCount))
EndFunction

'Lorem Ipsum Sentence - average 14 words in a sentence
Function LipsumSentence$(MaxLen)
    Local sentencelen
    Local sentence$
    Local separator$
    Local i

    sentencelen=Random(MaxLen)+1
    sentence$=""
    i=0

    While i < sentencelen
        If Random(50) < 1 Then
            separator$="; "
        Else
            If Random(10) < 1 Then
                separator$=", "
            Else
                separator$=" "
            EndIf
        EndIf
        sentence$=sentence$+Lipsum$(Random(LipsumCount))+separator$
        i=i+1
    Wend
    ' Capitalize the first letter
    sentence$=Ucase$(Left$(sentence$,1))+Right$(sentence$,(Len(sentence$)-1))
    ' Remove extra whitespace and add a period
    If (Right$(sentence$,2)="; " OR Right$(sentence$,2)=", ")Then
        LipsumSentence$=Left$(sentence$,Len(sentence$)-2)+"."
    Else
        LipsumSentence$=Left$(sentence$,Len(sentence$)-1)+"."   
    EndIf
EndFunction
' You can add or remove names as desired
Male$="Aaron,Barry,Carl,Daniel,Edward,Frank,George,Harold,Ike,Joseph,Kareem,Lawrence,Michael,Nicolas,Oliver,Patrick,Quinton,Richard,Salvatore,Thomas,Umesh,Vincent,William,Xerxes,Yves,Zeus" Female$="Abby,Barbara,Caitlin,Donna,Ellen,Faye,Gail,Hannah,Ilene,Jenna,Kate,Laura,Maggie,Nadine,Odella,Paige,Queenie,Rachael,Samantha,Tamara,Uma,Valerie,Wendy,Xera,Yvonne,Zoe"
Last$="Al-Hussein,Bacon,Carter,Dennis,Edwards,Fowler,Grant,Hadley,Irving,Josephson,Keith,Landon,Michaels,Ng,O'Brien,Paulson,Quigley,Richardson,St. Pierre,Thompson,Unger,Van Kempen,Williamson,Xeronson,Young,Zachary"
' You can add or remove territories as required
State$="Alabama,Alaska,Arkansas,Arizona,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisisana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Puerto Rico,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming"
StateA$="AK,AL,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY"
Province$="Alberta,British Columbia,Manitoba,New Brunswick,Newfoundland,Nova Scotia,Northwest Territories,Ontario,Prince Edward Island,Quebec,Saskatchewan,Yukon Territory"
City$="Albany,Boston,Carson City,Denver,East Point,Fairfax,Georgetown,Harts Landing,Indianapolis,Johnstown,Kansas City,Lower Mills,Middletown,North Hills,Oakland,Philadelphia,Quincy,Ridgeview,South Orange,Teaneck,Upsilanti,vienna,West Haven,Xavier,Youngstown,Zanzibar"
LoremIpsum$="lorem,ipsum,dolor,sit,amet,consectetur,adipisicing,elit,sed,do,eiusmod,tempor,incididunt,ut,labore,et,dolore,magna,aliqua,ut,enim,ad,minim,veniam,quis,nostrud,exercitation,ullamco,laboris,nisi,ut,aliquip,ex,ea,commodo,consequat,duis,aute,irure,dolor,in,reprehenderit,in,voluptate,velit,esse,cillum,dolore,eu,fugiat,nulla,pariatur,excepteur,sint,occaecat,cupidatat,non,proident,sunt,in,culpa,qui,officia,deserunt,mollit,anim,id,est,laborum"

FirstMCount=SplitIntoArray(Male$,FirstM$(),",") 'Count of Male first names
FirstFCount=SplitIntoArray(Female$,FirstF$(),",") ' Count of Female first names
FirstACount=SplitIntoArray(Male$+","+Female$,FirstA$(),",")' Count of All first names
LastACount=SplitIntoArray(Last$,LastA$(),",") ' Count of All last names
StateCount=SplitIntoArray(State$,States$(),",") ' Count of All States
StateACount=SplitIntoArray(StateA$,StateAs$(),",") ' Count of All State Abbreviations
ProvinceCount=SplitIntoArray(Province$,Provinces$(),",") ' Count of All Canadian Provinces
CityCount=SplitIntoArray(City$,Cities$(),",") ' Count of All Cities
LipsumCount=SplitIntoArray(LoremIpsum$,Lipsum$(),",") ' Count of All Lorem Ipsum words

'MsgBox(ZipCode$())
'MsgBox(ZipPlus4$())
'MsgBox(CAPostalCode$())
'MsgBox(SocSec$())
'MsgBox(Phone$())
'MsgBox(RandomDate$("01/01/2000", Date$()))
'MsgBox(MaleFirst$())
'MsgBox(FemaleFirst$())
'MsgBox(FirstName$())
'MsgBox(FirstLastName$())
'MsgBox(FirstMLastName$())
'MsgBox(LastFirstName$())
'MsgBox(StateName$())
'MsgBox(StateAbbr$())
'MsgBox(ProvinceName$())
'MsgBox(CityName$())
'MsgBox(LipsumWord$())
'MsgBox(LipsumSentence$(20))