(* ==================================================== TestScript for AppleScript's Variable Types Table Of Contents Important handlers in the file are sorted in alphabetical order To locate the handler in the file, select the text below the handler name (but be careful to not select any whitespace at the beginning or end!) and Edit -> Find -> Use Selection For Find (Cmd-E), Find -> Find Next (Cmd-G) ==================================================== addToOneNotShared to addToOneNotShared() appendTwoItemsUsingEndOf to appendTwoItemsUsingEndOf() callBackWithGlobal to callBackWithGlobal() changeAReferenceType to changeAReferenceType() changeDataReferenced to changeDataReferenced() changeList to changeList(lst) changeListContentsList to changeListContentsList() changeListContentsListContents to changeListContentsListContents() changeListCopyListContents to changeListCopyListContents() changeListItemListAndList to changeListItemListAndList() changeListListAndList to changeListListAndList() changeListListEndOfList to changeListListEndOfList() changeReference to changeReference() changeScalar to changeScalar(val) changeScalarEndOfList to changeScalarEndOfList() changeScalarInList to changeScalarInList(val) changeScalarListAndScalar to changeScalarListAndScalar() changeScalarListContents to changeScalarListContents() changeScalarListEndOfList to changeScalarListEndOfList() changeValueOfParameterListList to changeValueOfParameterListList() changeValueOfParameterScalar to changeValueOfParameterScalar() changeValueOfParameterScalarList to changeValueOfParameterScalarList() copyWithLists on copyWithLists() deepCopyChangeOne to deepCopyChangeOne() displayFinalMessage to displayFinalMessage(msg) recurseUntilOverflow to recurseUntilOverflow() recurseUntilOverflowWithReference to recurseUntilOverflowWithReference(aRef) recurseUntilOverflowWithValue to recurseUntilOverflowWithValue(aParam) setEndOfSharedData to setEndOfSharedData() setEndOfWithContainerContainerAppend to setEndOfWithContainerContainerAppend() setListToListAndContainerListItemAppend to setListToListAndContainerListItemAppend() shallowCopyChangeOne to shallowCopyChangeOne() shallowCopyChangeScalarValue to shallowCopyChangeScalarValue() shallowCopyChangeSharedValue to shallowCopyChangeSharedValue() simpleAddSelfToEndOfSelfErr to simpleAddSelfToEndOfSelfErr() testContainerItemChangeReflectedInShared to testContainerItemChangeReflectedInShared() testContainerItemsShareScalars to testContainerItemsShareScalars() testContainersShareScalars to testContainersShareScalars() testEmptyListsChangesContents to testEmptyListsChangesContents() testEmptyListsChangesContentsChangesNotBack to testEmptyListsChangesContentsChangesNotBack() testFirstOfReassignRefItem to testFirstOfReassignRefItem() testNonEmptyListCorrectlyChangesContents to testNonEmptyListCorrectlyChangesContents() testSimpleEndOfWorksScalar to testSimpleEndOfWorksScalar() timeCopyListAndListToList on timeCopyListAndListToList() timeCopyListAndListToList100Items to timeCopyListAndListToList100Items() timeCopyListAndListToList100ItemsDualCopy to timeCopyListAndListToList100ItemsDualCopy() timeCopyListAndScalaryToList on timeCopyListAndScalaryToList() timeCopyScalarAndListToList100Items to timeCopyScalarAndListToList100Items() timeCopyScalarAndListToList100ItemsDualCopy to timeCopyScalarAndListToList100ItemsDualCopy() timeCopyScalarToList100Items to timeCopyScalarToList100Items() timeDeepCopyList on timeDeepCopyList() timeReferenceList on timeReferenceList() timeSetEndOfList100ItemsList to timeSetEndOfList100ItemsList() timeSetEndOfList100ItemsScalar to timeSetEndOfList100ItemsScalar() timeSetEndOfListToList to timeSetEndOfListToList() timeSetEndOfListToScalar to timeSetEndOfListToScalar() timeSetListToContentsOfAndList to timeSetListToContentsOfAndList() timeSetListToContentsOfAndListCont to timeSetListToContentsOfAndListCont() timeSetListToContentsOfAndScalar on timeSetListToContentsOfAndScalar() timeSetListToListAndList to timeSetListToListAndList() timeSetListToListAndScalar on timeSetListToListAndScalar() twiddleCopyListItemList to twiddleCopyListItemList() twiddleListItemListAndList to twiddleListItemListAndList() twiddleListsWithThreeLists to twiddleListsWithThreeLists() twiddleReferenceItem to twiddleReferenceItem() twiddleScalarListContents to twiddleScalarListContents() xAnYScalars on xAnYScalars() xAndYList on xAndYList() xAndYListCopy on xAndYListCopy() ============================================================ This test script shows many (if not all) of the assertions made in the AppleScript's Variable Types and You (Part 1 and Part 2) by Ryan Wilcox for MacTech Magazine. This script uses the WDTestHarness for AppleScript, a test harness for doing unit tests or general QA stuff in Applescript, based on the principle of The Simplest Unit Testing Framework That Could Exist (for Applescript). It also provides timing mechanisms. The WDTestHarness for AppleScript was Created by Ryan Wilcox on Tuesday May 10 2005. Copyright (c) 2005 Wilcox Development Solutions (http://www.wilcoxd.com). This framework is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. *) -- ---------------------- framework properties ---------------------- -- property numberTestsThatHaveRun : 0 property numberTestsThatHavePassed : 0 property numberTestsThatHaveFailed : 0 property processFile : 0 property currTimedFunction : 0 -- ---------------------- User control properties ---------------------- -- property doTimings : true -- ---------------------- Our Properties/globals ---------------------- -- property mcount : 0 property one2ten : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} property refProp : 0 global iWasCalled global callThis -- ---------------------- Tests ---------------------- -- on xAnYScalars() (*254*) set x to true set y to x set y to false return (x is true and y is false) end xAnYScalars (*260*) on xAndYList() (*262*) set x to {true} set y to x set item 1 of y to false return (x is {false} and y is {false}) end xAndYList (*268*) on xAndYListCopy() (*270*) set x to true copy x to y set y to false return (x is true and y is false) end xAndYListCopy (*276*) on copyWithLists() (*278*) set x to {true} copy x to y -- y to x set item 1 of y to false return (x is {true} and y is {false}) end copyWithLists (*284*) to changeDataReferenced() (*286*) set a to {1} set b to {a} set item 1 of item 1 of b to 42 return (b is equal to {{42}}) and (a is equal to {42}) end changeDataReferenced (*292*) to changeReference() (*294*) set a to {1} set b to {a} set item 1 of b to 42 return (b is equal to {42}) and (a is equal to {1}) end changeReference (*300*) to setEndOfSharedData() (*302*) set a to {1} set b to a set end of b to 45 return a is equal to {1, 45} and b is equal to {1, 45} end setEndOfSharedData (*308*) to addToOneNotShared() (*310*) set a to {1} set b to a set b to a & {45} return a is equal to {1} and b is equal to {1, 45} end addToOneNotShared (*316*) to changeScalarListContents() (*318*) set myList to {} set myItem to 1 repeat with i from 1 to 5 copy myList & myItem to myList set myItem to 2 end repeat return myList is equal to {1, 2, 2, 2, 2} end changeScalarListContents (*326*) to twiddleScalarListContents() (*328*) set myList to {} set myItem to 1 repeat with i from 1 to 5 copy myList to myVar if i = 2 then set item 1 of myList to 5 --but won't be at the end because we have a copy which gets thrown away when this loop ends end if set myList to myVar & myItem set myItem to 2 end repeat log myList return myList is equal to {1, 2, 2, 2, 2} end twiddleScalarListContents (*342*) to changeListCopyListContents() (*344*) set myList to {} set myItem to {1} repeat with i from 1 to 5 copy myList & myItem to myList set item 1 of myItem to 2 end repeat return myList is equal to {1, 2, 2, 2, 2} end changeListCopyListContents (*352*) to changeListContentsList() (*354*) set myList to {} set myItem to {1} repeat with i from 1 to 5 set myList to (contents of myList) & myItem set item 1 of myItem to 2 end repeat return myList is equal to {2, 2, 2, 2, 2} end changeListContentsList (*362*) to changeListContentsListContents() (*364*) set myList to {} set myItem to {1} repeat with i from 1 to 5 set myList to (contents of myList) & (contents of myItem) set item 1 of myItem to 2 end repeat return myList is equal to {1, 2, 2, 2, 2} end changeListContentsListContents (*372*) to changeScalarListAndScalar() (*374*) set myList to {} set myItem to 123 repeat with i from 1 to 5 copy myList & myItem to myList set myItem to 124 end repeat return myList is equal to {123, 124, 124, 124, 124} end changeScalarListAndScalar (*382*) to changeListItemListAndList() (*384*) set myList to {} set myItem to {1} set biggerList to false repeat with i from 1 to 5 set myList to myList & myItem if not biggerList then --only do it once set end of myItem to {2} set biggerList to true end if end repeat return myList is equal to {1, 2, 1, 2, 1, 2, 1, 2, 1, 2} end changeListItemListAndList (*396*) to twiddleListItemListAndList() (*398*) set myList to {} set myItem to {1} repeat with i from 1 to 5 set referTo to myList if i = 2 then set item 1 of myList to 234 --change the shared data end if set myList to referTo & myItem end repeat return myList is equal to {234, 234, 234, 234, 234} end twiddleListItemListAndList (*410*) to twiddleReferenceItem() (*412*) set myList to {} set shallowCopy to missing value repeat with i from 1 to 5 set end of myList to i end repeat set shallowCopy to myList set item 4 of shallowCopy to 42 return (myList is equal to {1, 2, 3, 42, 5}) and (shallowCopy is equal to {1, 2, 3, 42, 5}) end twiddleReferenceItem (*421*) to twiddleCopyListItemList() (*423*) set a to 1 set myList to {{a}, {a}, {a}, {a}, {a}} copy myList to deepCopy set shallowCopy to items of myList set item 1 of item 4 of deepCopy to 42 -- not reflected set item 1 of item 5 of myList to 23 -- reflected return (myList is equal to {{1}, {1}, {1}, {1}, {23}}) and (deepCopy is equal to {{1}, {1}, {1}, {42}, {1}}) and (shallowCopy is equal to {{1}, {1}, {1}, {1}, {23}}) end twiddleCopyListItemList (*432*) to twiddleListsWithThreeLists() (*434*) set myList to {} set L1 to {1} set L2 to myList & L1 set item 1 of L2 to 234 return L1 is equal to {234} end twiddleListsWithThreeLists (*440*) to changeListListAndList() (*442*) set myList to {} set myItem to {1} repeat with i from 1 to 5 set myList to myList & myItem set myItem to {1, 2} end repeat return myList is {1, 1, 2, 1, 2, 1, 2, 1, 2} end changeListListAndList (*450*) to setListToListAndContainerListItemAppend() (*452*) set a to {1, 3} set b to {2} set b to a & b return b is equal to {1, 3, 2} end setListToListAndContainerListItemAppend (*457*) to testSimpleEndOfWorksScalar() (*459*) set a to 2 set b to {1} set end of b to a return b is equal to {1, 2} end testSimpleEndOfWorksScalar (*464*) to setEndOfWithContainerContainerAppend() (*466*) set a to {2} set b to {1} set end of b to a return b is equal to {1, {2}} end setEndOfWithContainerContainerAppend (*471*) to changeScalarListEndOfList() (*473*) set myList to {} set myItem to 1 repeat with i from 1 to 5 set myList to myList & myItem set myItem to 2 end repeat return myList is equal to {1, 2, 2, 2, 2} end changeScalarListEndOfList (*481*) to changeListListEndOfList() (*484*) set myList to {} set myItem to {1, 2} repeat with i from 1 to 5 set end of myList to myItem set item 2 of myItem to 3 end repeat return myList is equal to {{1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}} end changeListListEndOfList (*492*) to changeScalarEndOfList() (*494*) set myItem to 1 set myList to {} set end of myList to myItem set myItem to 45 --set myItem to {46} set theIt to item 1 of myList return theIt is equal to 1 and myItem is equal to 45 end changeScalarEndOfList (*504*) to testFirstOfReassignRefItem() (*507*) set a to 1 set myList to {a, 2, 3, 4, 5, 6} set first item of myList to 42 --get end of myList return (a is equal to 1) and (myList is equal to {42, 2, 3, 4, 5, 6}) end testFirstOfReassignRefItem (*513*) to deepCopyChangeOne() (*515*) set a to {1} set b to {2} set myList to {a, b} copy myList to deepCopy -- deepCopy contains new list with duplicate contents set item 1 of a to 42 return (myList is equal to {{42}, {2}}) and (a is equal to {42}) and (deepCopy is equal to {{1}, {2}}) end deepCopyChangeOne (*525*) to shallowCopyChangeOne() (*528*) set a to {1} set b to {2} set myList to {a, b} set shallowCopy to items of myList set item 1 of myList to 0 return (myList is equal to {0, {2}}) and (a is equal to {1}) and (shallowCopy is equal to {{1}, {2}}) end shallowCopyChangeOne (*538*) to shallowCopyChangeSharedValue() (*540*) set a to {1} set b to {2} set myList to {a, b} set shallowCopy to items of myList copy myList to deepCopy set item 1 of item 1 of myList to 0 return (myList is equal to {{0}, {2}}) and (shallowCopy is equal to {{0}, {2}}) and (deepCopy is equal to {{1}, {2}}) end shallowCopyChangeSharedValue (*552*) to shallowCopyChangeScalarValue() (*554*) set a to 42 set myList to {a} set myShallowCopy to items of myList set item 1 of myList to 45 return (myList is equal to {45}) and (myShallowCopy is equal to {42}) and (a is equal to 42) end shallowCopyChangeScalarValue (*562*) to changeScalarInList(val) (*564*) set item 1 of val to 67 --just changing the reference end changeScalarInList (*567*) to changeScalar(val) (*569*) set val to 124 end changeScalar (*571*) to changeList(lst) (*573*) set item 1 of item 1 of lst to 67 --change the value associated with the reference end changeList (*576*) to changeValueOfParameterScalarList() (*578*) set ftwo to 42 set myParam to {ftwo} changeScalarInList(myParam) return (ftwo is equal to 42) and (myParam is equal to {67}) --the value stays the same, but myParam has a diferent reference in it! end changeValueOfParameterScalarList (*587*) to changeValueOfParameterListList() (*589*) set ftwo to {42} set myParam to {ftwo} changeList(myParam) return (ftwo is equal to {67}) and (myParam is equal to {{67}}) end changeValueOfParameterListList (*597*) to changeValueOfParameterScalar() (*599*) set ftwo to 42 changeScalar(ftwo) return (ftwo is equal to 42) end changeValueOfParameterScalar (*604*) to changeAReferenceType() (*606*) set refProp to "world" set y to a reference to refProp set z to a reference to refProp set y to "hello" set contents of z to "foo" return ((refProp is equal to "foo") and (y is equal to "hello") and (contents of z is equal to "foo")) end changeAReferenceType (*615*) to testEmptyListsChangesContents() (*617*) --counterpoint to testContainerItemsShareScalars --and testNonEmptyListCorrectlyChangesContents --change item 1 of myList and see myItem change --one would have expected our changes to --have simply changed what item 1 was sharing --(ala: figure 6 in Part 1), but instead it changes --the contents of the shared item (ala Figure 5 in Part 1) set emptyList to {} set myItem to {1} set myList to emptyList & myItem set item 1 of myList to 123 set myList to myList & myItem return (myItem is equal to {123} and myList is equal to {123, 123}) end testEmptyListsChangesContents (*634*) to testEmptyListsChangesContentsChangesNotBack() (*636*) --same test as testEmptyListsChangesContents(), but --but we change where item 1 of myItem points to, and we --don't see the change reflected in myList set emptyList to {} set myItem to {1} set myList to emptyList & myItem set item 1 of myList to 123 set myList to myList & myItem set item 1 of myItem to 45 return (myItem is equal to {45} and myList is equal to {123, 123}) end testEmptyListsChangesContentsChangesNotBack (*649*) to testNonEmptyListCorrectlyChangesContents() (*651*) --counterpoint to testEmptyListsIncorrectlyChangesContents --myItem changes because myList is just sharing the --myItem, and changes to one affect the other set myItem to {1} set myList to myItem set item 1 of myList to 45 --directly changes myItem because myList shares all of it set myList to myList & myItem log myList log myItem return (myList is equal to {45, 45} and myItem is equal to {45}) end testNonEmptyListCorrectlyChangesContents (*663*) to testContainerItemsShareScalars() (*665*) --counterpoint to testEmptyListsIncorrectlyChangesContents() --change myItem and see myList not change set myItem to {1} set myList to myItem set myList to myList & myItem set item 1 of myItem to 45 return (myList is equal to {1, 1} and myItem is equal to {45}) end testContainerItemsShareScalars (*675*) to testContainersShareScalars() (*677*) --counterpoint to testContainerItemsShareScalars() --change myItem and see myList not change --except this time myItem is a container holding another --container (but it works just like testContainerItemsShareScalars set myItem to {{1}} set myList to myItem set myList to myList & myItem set item 1 of myItem to 45 return (myList is equal to {{1}, {1}} and myItem is equal to {45}) end testContainersShareScalars (*689*) to testContainerItemChangeReflectedInShared() (*691*) --counterpoint to testContainerItemsShareScalars() --45 should get reflected in myList because we are --changing the contents of it set myItem to {{1}} set myList to myItem set myList to myList & myItem set item 1 of item 1 of myItem to 45 return myItem is equal to {{45}} and myList is equal to {{45}, {45}} end testContainerItemChangeReflectedInShared (*702*) to appendTwoItemsUsingEndOf() (*704*) set a to {1} set end of a to {3, 2} log a return a is equal to {1, {3, 2}} end appendTwoItemsUsingEndOf (*709*) to simpleAddSelfToEndOfSelfErr() (*711*) set a to {1} set end of a to {a, 2} try log a on error return false end try return true end simpleAddSelfToEndOfSelfErr (*720*) to called() (*722*) global iWasCalled set iWasCalled to true end called (*726*) to caller() (*728*) global callThis callThis() end caller (*731*) to callBackWithGlobal() (*733*) global callThis global iWasCalled set iWasCalled to false set callThis to called caller() return (iWasCalled) end callBackWithGlobal (*743*) -- ---------------------- Timings ---------------------- -- on timeDeepCopyList() (*747*) set myList to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} repeat with i from 1 to 200 copy myList to junk end repeat end timeDeepCopyList (*753*) on timeReferenceList() (*755*) set myList to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} repeat with i from 1 to 200 set junk to myList end repeat end timeReferenceList (*761*) on timeSetListToContentsOfAndScalar() (*763*) set myList to {} set myItem to 1 repeat with i from 1 to 100 set myList to (contents of myList) & myItem end repeat end timeSetListToContentsOfAndScalar (*769*) on timeCopyListAndScalaryToList() (*771*) set myList to {} set myItem to 1 repeat with i from 1 to 100 copy myList & myItem to myList end repeat end timeCopyListAndScalaryToList (*777*) on timeCopyListAndListToList() (*779*) set myList to {} set myItem to {1} repeat with i from 1 to 100 copy myList & myItem to myList end repeat end timeCopyListAndListToList (*785*) to timeSetListToContentsOfAndList() (*788*) set myList to {} set myItem to {1} repeat with i from 1 to 100 set myList to (contents of myList) & myItem end repeat end timeSetListToContentsOfAndList (*794*) to timeSetListToContentsOfAndListCont() (*796*) set myList to {} set myItem to {1} repeat with i from 1 to 100 set myList to (contents of myList) & (contents of myItem) end repeat end timeSetListToContentsOfAndListCont (*802*) on timeSetListToListAndScalar() (*804*) set myList to {} set myItem to 1 repeat with i from 1 to 100 set myList to myList & myItem end repeat end timeSetListToListAndScalar (*810*) to timeSetListToListAndList() (*812*) set myList to {} set myItem to {1} repeat with i from 1 to 100 set myList to myList & myItem end repeat end timeSetListToListAndList (*818*) to timeSetEndOfListToScalar() (*820*) set myList to {} set myItem to 1 repeat with i from 1 to 100 set end of myList to myItem end repeat end timeSetEndOfListToScalar (*826*) to timeSetEndOfListToList() (*828*) set myList to {} set myItem to {1} repeat with i from 1 to 100 set end of myList to myItem end repeat end timeSetEndOfListToList (*834*) to timeSetEndOfList100ItemsList() (*837*) set myList to {} set myItem to {} repeat with i from 1 to 100 set end of myItem to i end repeat repeat with i from 1 to 100 set end of myList to myItem end repeat end timeSetEndOfList100ItemsList (*847*) to timeSetEndOfList100ItemsScalar() (*849*) set myList to {} set myItem to {} repeat with i from 1 to 100 set end of myItem to i end repeat set myItem to myItem as string repeat with i from 1 to 100 set end of myList to myItem end repeat end timeSetEndOfList100ItemsScalar (*859*) to timeCopyScalarToList100Items() (*861*) set myList to {} set myItem to {} repeat with i from 1 to 100 set end of myItem to i end repeat set myItem to myItem as string repeat with i from 1 to 100 set end of myList to myItem end repeat end timeCopyScalarToList100Items (*871*) to timeCopyScalarAndListToList100Items() (*873*) set myList to {} set myItem to {} repeat with i from 1 to 100 set end of myItem to i --do it fast as can to only show one var end repeat set myItem to myItem as string repeat with i from 1 to 100 copy myList & myItem to myList end repeat end timeCopyScalarAndListToList100Items (*883*) to timeCopyListAndListToList100Items() (*885*) set myList to {} set myItem to {} repeat with i from 1 to 100 set end of myItem to {i} --do it fast as can to only show one var end repeat set myItem to myItem as string repeat with i from 1 to 100 copy myList & myItem to myList end repeat end timeCopyListAndListToList100Items (*895*) to timeCopyScalarAndListToList100ItemsDualCopy() (*897*) set myList to {} set myItem to {} repeat with i from 1 to 100 copy myItem & i to myItem --set end of myItem to i --do it fast as can to only show one var end repeat set myItem to myItem as string repeat with i from 1 to 100 copy myList & myItem to myList end repeat end timeCopyScalarAndListToList100ItemsDualCopy (*908*) to timeCopyListAndListToList100ItemsDualCopy() (*910*) set myList to {} set myItem to {} repeat with i from 1 to 100 copy myItem & {i} to myItem end repeat set myItem to myItem as string repeat with i from 1 to 100 copy myList & myItem to myList end repeat end timeCopyListAndListToList100ItemsDualCopy (*920*) -- ---------------------- Results ---------------------- -- to recurseUntilOverflowWithValue(aParam) (*924*) set mcount to mcount + 1 recurseUntilOverflowWithValue(aParam) end recurseUntilOverflowWithValue (*927*) to recurseUntilOverflow() (*929*) set mcount to mcount + 1 recurseUntilOverflow() end recurseUntilOverflow (*932*) to recurseUntilOverflowWithReference(aRef) (*934*) set mcount to mcount + 1 recurseUntilOverflowWithReference(aRef) end recurseUntilOverflowWithReference (*937*) -- ----------------------- Utility Functions ---------------------- -- to getMinimumOf(lst) (*940*) set currSmaller to item 1 of lst repeat with each in lst if (each < currSmaller) then set currSmaller to each end if end repeat return contents of currSmaller end getMinimumOf (*948*) to getMaximumOf(lst) (*950*) set currSmaller to item 1 of lst repeat with each in lst if (each > currSmaller) then set currSmaller to each end if end repeat return contents of currSmaller end getMaximumOf (*958*) on getAverageOf(lst) (*960*) set total to 0 set nums to number of items in lst repeat with each in lst set total to total + each end repeat set average to total / nums return average end getAverageOf (*969*) to _result(beforeText, testName, afterText) (*971*) tell application "TextEdit" set testInfo to beforeText & testName & " (" & afterText & ")" set text of processFile to text of processFile & return & testInfo end tell end _result (*976*) -- ----------------------- Framework stuff ---------------------- -- on _test(testPassed, testName) (*979*) set numberTestsThatHaveRun to numberTestsThatHaveRun + 1 set textStatus to "" if (testPassed) then set numberTestsThatHavePassed to numberTestsThatHavePassed + 1 set textStatus to "passed" else set numberTestsThatHaveFailed to numberTestsThatHaveFailed + 1 set textStatus to "failed" end if _result("tested: ", testName, textStatus) end _test (*992*) on _time(iters, testName) (*994*) if doTimings then set durations to {} repeat with i from 1 to iters set startTime to the ticks currTimedFunction() set endTime to the ticks set ourDuration to endTime - startTime log startTime log endTime log ourDuration set end of durations to ourDuration end repeat set minTime to getMinimumOf(durations) set avgTime to getAverageOf(durations) set maxTime to getMaximumOf(durations) _result("timed: ", testName, "min: " & minTime & ", max: " & maxTime & ", avg: " & avgTime) else _result("timing for: ", testName, "skipped") end if end _time (*1018*) to _timeTest(iters, testName) (*1020*) _test(currTimedFunction(), testName) _time(iters - 1, testName) end _timeTest (*1023*) on runTheTests() (*1025*) --call your tests via _test() here _test(xAnYScalars(), "xAnYScalars") _test(xAndYList(), "xAndYList") _test(xAndYListCopy(), "xAndYListCopy") _test(copyWithLists(), "copyWithLists") _test(changeDataReferenced(), "changeDataReferenced") _test(changeReference(), "changeReference") _test(setEndOfSharedData(), "setEndOfSharedData") _test(addToOneNotShared(), "addToOneNotShared") _test(changeScalarListContents(), "changeScalarListContents") _test(twiddleScalarListContents(), "twiddleScalarListContents") _test(changeListCopyListContents(), "changeListCopyListContents") _test(changeListContentsListContents(), "changeListContentsListContents") _test(changeListContentsList(), "changeListContentsList") _test(changeScalarListAndScalar(), "changeScalarListAndScalar") _test(twiddleListItemListAndList(), "twiddleListItemListAndList") _test(twiddleReferenceItem(), "twiddleReferenceItem") _test(twiddleCopyListItemList(), "twiddleCopyListItemList") _test(twiddleListsWithThreeLists(), "twiddleListsWithThreeLists") _test(changeListListAndList(), "changeListListAndList") _test(setListToListAndContainerListItemAppend(), "setListToListAndContainerListItemAppend") _test(testSimpleEndOfWorksScalar(), "testSimpleEndOfWorksScalar") _test(setEndOfWithContainerContainerAppend(), "setEndOfWithContainerContainerAppend") _test(changeScalarListEndOfList(), "changeScalarListEndOfList") _test(changeListListEndOfList(), "changeListListEndOfList") _test(changeScalarEndOfList(), "changeScalarEndOfList") _test(testFirstOfReassignRefItem(), "testFirstOfReassignRefItem") _test(testEmptyListsChangesContents(), "testEmptyListsChangesContents") _test(testEmptyListsChangesContentsChangesNotBack(), "testEmptyListsChangesContentsChangesNotBack") _test(testNonEmptyListCorrectlyChangesContents(), "testNonEmptyListCorrectlyChangesContents") _test(testContainerItemsShareScalars(), "testContainerItemsShareScalars") _test(testContainersShareScalars(), "testContainersShareScalars()") _test(testContainerItemChangeReflectedInShared(), "testContainerItemChangeReflectedInShared") _test(appendTwoItemsUsingEndOf(), "appendTwoItemsUsingEndOf") _test(simpleAddSelfToEndOfSelfErr() is equal to false, "simpleAddSelfToEndOfSelfErr") _test(deepCopyChangeOne(), "deepCopyChangeOne") _test(shallowCopyChangeOne(), "shallowCopyChangeOne") _test(shallowCopyChangeSharedValue(), "shallowCopyChangeSharedValue") _test(shallowCopyChangeScalarValue(), "shallowCopyChangeScalarValue") _test(changeAReferenceType(), "changeAReferenceType") _test(changeValueOfParameterScalarList(), "changeValueOfParameterScalarList") _test(changeValueOfParameterListList(), "changeValueOfParameterListList") _test(changeValueOfParameterScalar(), "changeValueOfParameterScalar") _test(callBackWithGlobal(), "callBackWithGlobal") set currTimedFunction to timeDeepCopyList _time(100, "timeCopyList") set currTimedFunction to timeReferenceList _time(100, "timeReferenceList") set currTimedFunction to timeSetListToContentsOfAndScalar _time(100, "timeSetListToContentsOfAndScalar") set currTimedFunction to timeSetListToContentsOfAndList _time(100, "timeSetListToContentsOfAndList") set currTimedFunction to timeSetListToContentsOfAndListCont _time(100, "timeSetListToContentsOfAndListCont") set currTimedFunction to timeCopyListAndScalaryToList _time(100, "timeCopyListAndScalaryToList") set currTimedFunction to timeCopyListAndListToList _time(100, "timeCopyListAndListToList") set currTimedFunction to timeSetListToListAndScalar _time(100, "timeSetListToListAndScalar") set currTimedFunction to timeSetListToListAndList _time(100, "timeSetListToListAndList") set currTimedFunction to timeSetEndOfListToScalar _time(100, "timeSetEndOfListToScalar") set currTimedFunction to timeSetEndOfListToList _time(100, "timeSetEndOfListToList") set currTimedFunction to timeSetEndOfList100ItemsList _time(100, "timeSetEndOfList100ItemsList") set currTimedFunction to timeSetEndOfList100ItemsScalar _time(100, "timeSetEndOfList100ItemsScalar") set currTimedFunction to timeCopyScalarAndListToList100Items _time(100, "timeCopyScalarAndListToList100Items") set currTimedFunction to timeCopyListAndListToList100Items _time(100, "timeCopyListAndListToList100Items") set currTimedFunction to timeCopyScalarAndListToList100ItemsDualCopy _time(100, "timeCopyScalarAndListToList100ItemsDualCopy") set currTimedFunction to timeCopyListAndListToList100ItemsDualCopy _time(100, "timeCopyListAndListToList100ItemsDualCopy") set aParam to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} try recurseUntilOverflowWithValue(aParam) end try _result("result: ", "recurseUntilOverflowWith(Param)", "iterations before overflow: " & mcount) try recurseUntilOverflow() end try _result("result: ", "recurseUntilOverflow()", "iterations before overflow: " & mcount) try recurseUntilOverflowWithReference(a reference to one2ten) end try _result("result: ", "recurseUntilOverflowWithReference", "iterations before overflow: " & mcount) end runTheTests (*1140*) on initFramework() (*1142*) tell application "TextEdit" set processFile to make new document at end of documents set text of processFile to ("Test Run starting at " & (current date) as string) & return activate end tell end initFramework (*1148*) to displayFinalMessage(msg) (*1150*) tell application "TextEdit" display dialog msg end tell end displayFinalMessage (*1154*) on terminateFramework() (*1156*) tell application "TextEdit" set text of processFile to text of processFile & return & return & "===============================" & return & "Number of tests ran: " & numberTestsThatHaveRun end tell --take care to reset our properties set numberTestsThatHaveRun to 0 set numberTestsThatHavePassed to 0 set numberTestsThatHaveFailed to 0 set currTimedFunction to 0 end terminateFramework (*1166*) -- ----------------------- main ----------------------- -- on main() (*1169*) initFramework() runTheTests() set messageStr to ((("The Test Suite Has Run! Ran " & numberTestsThatHaveRun as string) & " tests. " & numberTestsThatHavePassed as string) & " passed passed, " & numberTestsThatHaveFailed as string) & " tests failed." --tell me to activate -- switch back to this app for the user displayFinalMessage(messageStr) terminateFramework() end main (*1177*) main()