; tst-a_array.ahk
; TestSuite for AHK's Binary Array RC2 ; (w) by derRaphael / released under the WTFPL 1.0 ; see http://sam.zoy.org/wtfpl/ for details.
Loop,5 ; Add 5 elements to Array VarSetCapacity(t,5,asc("0")+A_Index), A_Put(MyArray,t)
; Display AHK array Signature MsgBox,0,DirectAccess Array,% MyArray
Data := "aaaa", A_Put(MyArray, Data, 1) ; Change 1st element w/ shorter size Data := "bbbbbbbbb", A_Put(MyArray, Data, 3) ; ; Change 3rd element w/ longer size ; Change 5th element w/ longer size - currently last element of our Array Data := "1234567890abcdefghijklmnopqrstuvwxyz", A_Put(MyArray, Data, 5)
Loop,5 ; Add another 5 elements to Array VarSetCapacity(t,5,asc("0")+A_Index), A_Put(MyArray,t)
A_Put(MyArray, (Data := "-+-+-"), 1) ; Change 1st element again with different Size A_Put(MyArray, Data, 3) ; Change 3rd element again with different Size A_Put(MyArray, Data, 5) ; Change 5th element again with different Size
Loop,10 ; Retrieve all elements via loop ArrayElements .= "ArrayElement #" A_Index ": " A_Get(MyArray,A_Index) "`n"
MsgBox,0,ArrayElementvia Loop,% ArrayElements "`n`n" ; Display 'em MsgBox,0,GlueTest,% A_Implode(MyArray,"`n") ; Display A_Implode(Array) test
; If existing array given, it appends data to its end A_Explode(MyArray, " ", "This is a test for A_Explode") MsgBox,0,A_Explode Test,% "Dump Array after A_Explode applied:`n" A_Dump(MyArray)
; A_Del(Array,Item) Test / Element 4 is "44444" cb := A_Count(MyArray), data := A_Del(MyArray,4), size := ErrorLevel MsgBox,0,A_Del Test,% cB " elements counted before A_Del`n" . A_Count(MyArray) " elements counted after A_Del`n" . "Deleted element #4: " data " (" size ")`n`n" . "--------------DUMP:`n" A_Dump(MyArray)
; pops Element from ArrayStack MsgBox,0,A_Pop Test,% A_Count(MyArray) " elements counted before A_Pop removed: " A_Pop(MyArray)
. " ("
ErrorLevel ")`n`n--------------DUMP:`n" A_Dump(MyArray)
; shifts Element off from start of ArrayStack MsgBox,0,A_Shift Test,% A_Count(MyArray) " elemens counted before A_Shift removed: " A_Shift(MyArray)
.
" (" ErrorLevel ")`n`n--------------DUMP:`n" A_Dump(MyArray)
; swap 2 elements 1 w/ 2 and 1 w/ 10 A_Swap(MyArray,1,2), A_Swap(MyArray,1,10) MsgBox,0,A_Swap 1<->2 and 10<->1 Test, % "--------------DUMP:`n" A_Dump(MyArray)
; Slicetest - Slice Element 1 to 3 from MyArray A_Slice(MyOtherArray,MyArray,1,3) MsgBox,0,A_Slice Test, % "--------------DUMP:`n" A_Dump(MyOtherArray)
; Append MyOtherArray to MyArray's Structure A_Merge(MyArray,MyOtherArray) MsgBox,0,A_Merge Test, % "--------------DUMP:`n" A_Dump(MyArray)
#include A_Array.ahk |