SystemOrganization addCategory: #'Container-Tests-Core-Abstract'! SystemOrganization addCategory: #'Container-Tests-Core-Comparators'! SystemOrganization addCategory: #'Container-Tests-Core-Iterators'! SystemOrganization addCategory: #'Container-Tests-Core-Lists'! SystemOrganization addCategory: #'Container-Tests-Core-Sets'! SystemOrganization addCategory: #'Container-Tests-Core-Maps'! !CTCollection methodsFor: '*container-tests-core' stamp: 'lr 1/25/2012 08:04'! assertInvariants: anAsserter "Asserts the internal state of this collection" anAsserter assert: self iterator size = self size description: 'Iterator and collection size are not equal'! ! !CTLinkedHashMap methodsFor: '*container-tests-core' stamp: 'lr 1/14/2012 11:19'! assertInvariants: anAsserter super assertInvariants: anAsserter. root assertInvariants: anAsserter. self assert: table size = root forwardIterator size! ! TestCase subclass: #CTContainerTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Abstract'! CTContainerTest subclass: #CTCollectionTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Abstract'! !CTCollectionTest class methodsFor: 'testing' stamp: 'lr 8/7/2011 19:59'! isAbstract ^ self name = #CTCollectionTest! ! !CTCollectionTest methodsFor: 'accessing' stamp: 'lr 11/5/2011 18:42'! collectionClass ^ CTCollection! ! !CTCollectionTest methodsFor: 'accessing' stamp: 'lr 1/10/2012 07:40'! collectionWithAll: aCollection ^ self collectionClass withAll: aCollection! ! !CTCollectionTest methodsFor: 'accessing' stamp: 'lr 1/13/2012 23:52'! collectionWithRandomElements: anInteger | collection | collection := self collectionClass new: anInteger. 1 to: anInteger do: [ :index | collection add: index ]. ^ collection! ! !CTCollectionTest methodsFor: 'accessing' stamp: 'lr 1/11/2012 22:44'! emptyCollection ^ self collectionClass new! ! !CTCollectionTest methodsFor: 'tests-copying' stamp: 'lr 1/13/2012 12:06'! testCopyEmpty | old new | old := self emptyCollection. new := old copy. self deny: old == new. self assertIterable: old equals: new. self assertInvariants: old. self assertInvariants: new. old add: $a. new add: $b. self assert: old size = 1. self assert: new size = 1. self assert: old iterator next = $a. self assert: new iterator next = $b. self assert: (old iterator anySatisfy: [ :e | e = $a ]). self assert: (new iterator anySatisfy: [ :e | e = $b ]). self assert: (old iterator noneSatisfy: [ :e | e = $b ]). self assert: (new iterator noneSatisfy: [ :e | e = $a ])! ! !CTCollectionTest methodsFor: 'tests-copying' stamp: 'lr 1/13/2012 23:52'! testCopyMany | old new | old := self collectionWithRandomElements: 100. new := old copy. self deny: old == new. self assertIterable: old equals: new. self assertInvariants: old. self assertInvariants: new. old add: $a. new add: $b. self assert: old size = 101. self assert: new size = 101. self assert: (old iterator anySatisfy: [ :e | e = $a ]). self assert: (new iterator anySatisfy: [ :e | e = $b ]). self assert: (old iterator noneSatisfy: [ :e | e = $b ]). self assert: (new iterator noneSatisfy: [ :e | e = $a ])! ! !CTCollectionTest methodsFor: 'tests' stamp: 'lr 1/11/2012 22:45'! testEmptyCollection self assertInvariants: self emptyCollection! ! !CTCollectionTest methodsFor: 'tests-testing' stamp: 'lr 1/10/2012 07:42'! testIsEmpty self assert: (self collectionWithAll: #()) isEmpty. self deny: (self collectionWithAll: #($a)) isEmpty. self deny: (self collectionWithAll: #($a $b)) isEmpty! ! !CTCollectionTest methodsFor: 'tests-iterators' stamp: 'lr 1/13/2012 11:42'! testIteratorEmpty | collection | collection := self collectionWithAll: #(). self assertIterable: #() equals: collection iterator! ! !CTCollectionTest methodsFor: 'tests-iterators' stamp: 'lr 1/13/2012 11:44'! testIteratorMultiple | collection | collection := self collectionWithAll: #($a $b $c). self assert: collection iterator size = 3. self assert: (collection iterator includes: $a). self assert: (collection iterator includes: $b). self assert: (collection iterator includes: $c)! ! !CTCollectionTest methodsFor: 'tests-iterators' stamp: 'lr 1/13/2012 11:42'! testIteratorSingle | collection | collection := self collectionWithAll: #($a). self assertIterable: #($a) equals: collection iterator! ! !CTCollectionTest methodsFor: 'tests' stamp: 'lr 1/11/2012 22:46'! testLargeCollection self assertInvariants: (self collectionWithRandomElements: 1000)! ! !CTCollectionTest methodsFor: 'tests-instantiation' stamp: 'lr 1/14/2012 11:10'! testNew | collection | collection := self collectionClass new. self assert: collection isEmpty. collection := self collectionClass new: 100. self assert: collection isEmpty! ! !CTCollectionTest methodsFor: 'tests' stamp: 'lr 1/14/2012 10:40'! testPrintCollection | collection | collection := self emptyCollection. self assert: collection printString isString. collection := self collectionWithAll: #($a $b $c). self assert: collection printString isString! ! !CTCollectionTest methodsFor: 'tests-removing' stamp: 'lr 1/14/2012 00:21'! testRemove | collection | collection := self collectionWithAll: #($a $b $c $d $e). self should: [ collection remove: $y ] raise: CTElementNotFoundError. self assert: (collection remove: $a) = $a. self assert: (collection remove: $c) = $c. self assert: (collection remove: $e) = $e. self assert: collection size = 2. self assert: (collection iterator includes: $b). self assert: (collection iterator includes: $d). self assertInvariants: collection! ! !CTCollectionTest methodsFor: 'tests-removing' stamp: 'lr 1/11/2012 22:47'! testRemoveAll | collection | collection := self collectionWithRandomElements: 100. collection removeAll. self assert: collection isEmpty. self assertInvariants: collection! ! !CTCollectionTest methodsFor: 'tests-removing' stamp: 'lr 1/14/2012 00:21'! testRemoveIfAbsent | collection | collection := self collectionWithAll: #($a $b $c $d $e). self assert: (collection remove: $y ifAbsent: [ $x ]) = $x. self assert: (collection remove: $a ifAbsent: [ $x ]) = $a. self assert: (collection remove: $c ifAbsent: [ $x ]) = $c. self assert: (collection remove: $e ifAbsent: [ $x ]) = $e. self assert: collection size = 2. self assert: (collection iterator includes: $b). self assert: (collection iterator includes: $d). self assertInvariants: collection! ! !CTCollectionTest methodsFor: 'tests-accessing' stamp: 'lr 1/10/2012 07:41'! testSize self assert: (self collectionWithAll: #()) size = 0. self assert: (self collectionWithAll: #($a)) size = 1. self assert: (self collectionWithAll: #($a $b)) size = 2! ! !CTCollectionTest methodsFor: 'tests' stamp: 'lr 1/11/2012 22:46'! testSmallCollection self assertInvariants: (self collectionWithAll: #(a b c d e))! ! !CTCollectionTest methodsFor: 'tests-instantiation' stamp: 'lr 1/14/2012 11:13'! testWith | collection | collection := self collectionClass with: $a. self assert: (collection iterator includes: $a). self assert: (collection size) = 1. collection := self collectionClass with: $a with: $b. self assert: (collection iterator includes: $a). self assert: (collection iterator includes: $b). self assert: (collection size) = 2. collection := self collectionClass with: $a with: $b with: $c. self assert: (collection iterator includes: $a). self assert: (collection iterator includes: $b). self assert: (collection iterator includes: $c). self assert: (collection size) = 3. collection := self collectionClass with: $a with: $b with: $c with: $d. self assert: (collection iterator includes: $a). self assert: (collection iterator includes: $b). self assert: (collection iterator includes: $c). self assert: (collection iterator includes: $d). self assert: (collection size) = 4! ! !CTCollectionTest methodsFor: 'tests-instantiation' stamp: 'lr 1/14/2012 13:40'! testWithAll | old new | old := self collectionWithRandomElements: 100. new := self collectionClass withAll: old. self deny: old == new. self assertIterable: old equals: new. self assertInvariants: old. self assertInvariants: new. old add: $a. new add: $b. self assert: old size = 101. self assert: new size = 101. self assert: (old iterator anySatisfy: [ :e | e = $a ]). self assert: (new iterator anySatisfy: [ :e | e = $b ]). self assert: (old iterator noneSatisfy: [ :e | e = $b ]). self assert: (new iterator noneSatisfy: [ :e | e = $a ])! ! CTCollectionTest subclass: #CTListTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Abstract'! CTListTest subclass: #CTArrayListTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Lists'! !CTArrayListTest methodsFor: 'accessing' stamp: 'lr 1/20/2012 22:16'! collectionClass ^ CTArrayList! ! CTListTest subclass: #CTLinkedListTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Lists'! !CTLinkedListTest methodsFor: 'accessing' stamp: 'lr 8/7/2011 19:21'! collectionClass ^ CTLinkedList! ! !CTListTest class methodsFor: 'testing' stamp: 'lr 8/7/2011 19:59'! isAbstract ^ self name = #CTListTest! ! !CTListTest methodsFor: 'accessing' stamp: 'lr 11/5/2011 18:42'! collectionClass ^ CTList! ! !CTListTest methodsFor: 'tests-adding' stamp: 'lr 1/11/2012 22:48'! testAdd | collection | collection := self emptyCollection. self assert: (collection add: $a) = $a. self assertIterable: collection equals: #($a). self assert: (collection add: $b) = $b. self assertIterable: collection equals: #($a $b). self assert: (collection add: $c) = $c. self assertIterable: collection equals: #($a $b $c). self assertInvariants: collection ! ! !CTListTest methodsFor: 'tests-adding' stamp: 'lr 1/11/2012 22:48'! testAddAt | collection | collection := self emptyCollection. self should: [ collection add: $a at: 0 ] raise: CTIndexOutOfBoundsError. self should: [ collection add: $a at: 2 ] raise: CTIndexOutOfBoundsError. self assert: (collection add: $a at: 1) = $a. self assertIterable: collection equals: #($a). self assert: (collection add: $b at: 2) = $b. self assertIterable: collection equals: #($a $b). self assert: (collection add: $c at: 2) = $c. self assertIterable: collection equals: #($a $c $b). self assert: (collection add: $d at: 1) = $d. self assertIterable: collection equals: #($d $a $c $b). self assert: (collection add: $e at: 4) = $e. self assertIterable: collection equals: #($d $a $c $e $b). self should: [ collection add: $a at: 0 ] raise: CTIndexOutOfBoundsError. self should: [ collection add: $a at: 7 ] raise: CTIndexOutOfBoundsError. self assertInvariants: collection! ! !CTListTest methodsFor: 'tests-adding' stamp: 'lr 1/11/2012 22:48'! testAddFirst | collection | collection := self emptyCollection. self assert: (collection addFirst: $a) = $a. self assertIterable: collection equals: #($a). self assert: (collection addFirst: $b) = $b. self assertIterable: collection equals: #($b $a). self assert: (collection addFirst: $c) = $c. self assertIterable: collection equals: #($c $b $a). self assertInvariants: collection ! ! !CTListTest methodsFor: 'tests-operations' stamp: 'lr 1/11/2012 22:48'! testAddFirstRemoveLast | collection | collection := self emptyCollection. 0001 to: 1000 do: [ :index | self assert: (collection addFirst: index) = index ]. self assertInvariants: collection. 1001 to: 2000 do: [ :index | self assert: (collection addFirst: index) = index. self assert: collection removeLast = (index - 1000) ]. self assertInvariants: collection. 2001 to: 3000 do: [ :index | self assert: collection removeLast = (index - 1000) ]. self assertInvariants: collection. self assert: collection isEmpty! ! !CTListTest methodsFor: 'tests-adding' stamp: 'lr 1/11/2012 22:48'! testAddLast | collection | collection := self emptyCollection. self assert: (collection addLast: $a) = $a. self assertIterable: collection equals: #($a). self assert: (collection addLast: $b) = $b. self assertIterable: collection equals: #($a $b). self assert: (collection addLast: $c) = $c. self assertIterable: collection equals: #($a $b $c). self assertInvariants: collection ! ! !CTListTest methodsFor: 'tests-operations' stamp: 'lr 1/11/2012 22:48'! testAddLastRemoveFirst | collection | collection := self emptyCollection. 0001 to: 1000 do: [ :index | self assert: (collection addLast: index) = index ]. self assertInvariants: collection. 1001 to: 2000 do: [ :index | self assert: (collection addLast: index) = index. self assert: collection removeFirst = (index - 1000) ]. self assertInvariants: collection. 2001 to: 3000 do: [ :index | self assert: collection removeFirst = (index - 1000) ]. self assertInvariants: collection. self assert: collection isEmpty! ! !CTListTest methodsFor: 'tests-accessing' stamp: 'lr 1/10/2012 22:20'! testAt | collection | collection := self collectionWithAll: #($a $b $c). self should: [ collection at: 0 ] raise: CTIndexOutOfBoundsError. self assert: (collection at: 1) = $a. self assert: (collection at: 2) = $b. self assert: (collection at: 3) = $c. self should: [ collection at: 4 ] raise: CTIndexOutOfBoundsError! ! !CTListTest methodsFor: 'tests-accessing' stamp: 'lr 1/10/2012 07:47'! testAtIfAbsent | collection | collection := self collectionWithAll: #($a $b $c). self assert: (collection at: 0 ifAbsent: [ $x ]) = $x. self assert: (collection at: 1 ifAbsent: [ $x ]) = $a. self assert: (collection at: 2 ifAbsent: [ $x ]) = $b. self assert: (collection at: 3 ifAbsent: [ $x ]) = $c. self assert: (collection at: 4 ifAbsent: [ $x ]) = $x! ! !CTListTest methodsFor: 'tests-accessing' stamp: 'lr 1/11/2012 22:47'! testAtPut | collection | collection := self collectionWithAll: #($a $b $c). self should: [ collection at: 0 put: $x ] raise: CTIndexOutOfBoundsError. self assert: (collection at: 1 put: $x) = $x. self assert: (collection at: 2 put: $x) = $x. self assert: (collection at: 3 put: $x) = $x. self should: [ collection at: 4 put: $x ] raise: CTIndexOutOfBoundsError. self assertInvariants: collection! ! !CTListTest methodsFor: 'tests-iterators' stamp: 'lr 1/13/2012 11:40'! testBackwardIterator | collection | collection := self collectionWithAll: #($a $b $c). self assertIterable: #($c $b $a) equals: collection backwardIterator! ! !CTListTest methodsFor: 'tests-iterators' stamp: 'lr 1/13/2012 11:41'! testBackwardIteratorEmpty | collection | collection := self collectionWithAll: #(). self assertIterable: #() equals: collection backwardIterator! ! !CTListTest methodsFor: 'tests-accessing' stamp: 'lr 1/11/2012 22:44'! testFirst | collection | collection := self emptyCollection. self should: [ self emptyCollection last ] raise: CTNoSuchElementError. 10 to: 20 do: [ :index | collection addFirst: index. self assert: collection first = index ]! ! !CTListTest methodsFor: 'tests-iterators' stamp: 'lr 1/13/2012 11:40'! testForwardIterator | collection | collection := self collectionWithAll: #($a $b $c). self assertIterable: #($a $b $c) equals: collection forwardIterator! ! !CTListTest methodsFor: 'tests-iterators' stamp: 'lr 1/13/2012 11:41'! testForwardIteratorEmpty | collection | collection := self collectionWithAll: #(). self assertIterable: #() equals: collection forwardIterator! ! !CTListTest methodsFor: 'tests-accessing' stamp: 'lr 1/11/2012 22:44'! testLast | collection | collection := self emptyCollection. self should: [ self emptyCollection last ] raise: CTNoSuchElementError. 10 to: 20 do: [ :index | collection addLast: index. self assert: collection last = index ]! ! !CTListTest methodsFor: 'tests-removing' stamp: 'lr 1/10/2012 23:27'! testRemoveAt | collection | collection := self collectionWithAll: #($a $b $c $d $e). self should: [ collection removeAt: 0 ] raise: CTIndexOutOfBoundsError. self should: [ collection removeAt: 6 ] raise: CTIndexOutOfBoundsError. self assert: (collection removeAt: 1) = $a. self assert: (collection removeAt: 4) = $e. self assert: (collection removeAt: 2) = $c. self assertIterable: collection equals: #($b $d)! ! !CTListTest methodsFor: 'tests-removing' stamp: 'lr 1/10/2012 23:28'! testRemoveAtIfAbsent | collection | collection := self collectionWithAll: #($a $b $c $d $e). self assert: (collection removeAt: 0 ifAbsent: [ $x ]) = $x. self assert: (collection removeAt: 6 ifAbsent: [ $x ]) = $x. self assert: (collection removeAt: 1 ifAbsent: [ $x ]) = $a. self assert: (collection removeAt: 4 ifAbsent: [ $x ]) = $e. self assert: (collection removeAt: 2 ifAbsent: [ $x ]) = $c. self assertIterable: collection equals: #($b $d)! ! !CTListTest methodsFor: 'tests-removing' stamp: 'lr 1/10/2012 23:32'! testRemoveFirst | letters collection | letters := #($a $b $c $d $e). collection := self collectionWithAll: letters. letters iterator do: [ :each | self assert: collection removeFirst = each ]. self should: [ collection removeFirst ] raise: CTNoSuchElementError. self assertIterable: collection equals: #()! ! !CTListTest methodsFor: 'tests-removing' stamp: 'lr 1/13/2012 11:34'! testRemoveLast | letters collection | letters := #($a $b $c $d $e). collection := self collectionWithAll: letters. letters backwardIterator do: [ :each | self assert: collection removeLast = each ]. self should: [ collection removeFirst ] raise: CTNoSuchElementError. self assertIterable: collection equals: #()! ! !CTListTest methodsFor: 'tests-sorting' stamp: 'lr 1/23/2012 19:24'! testSortDefault | list | list := self collectionWithAll: #(2 8 6 7 3 9 4 5 1). list sort. self assertIterable: list equals: #(1 2 3 4 5 6 7 8 9)! ! !CTListTest methodsFor: 'tests-sorting' stamp: 'lr 1/24/2012 19:15'! testSortOrder | list | list := self collectionWithAll: #(2 8 6 7 3 9 4 5 1). list sort: CTNaturalComparator new reverse. self assertIterable: list equals: #(9 8 7 6 5 4 3 2 1)! ! !CTListTest methodsFor: 'tests-sorting' stamp: 'lr 1/24/2012 19:15'! testSortRange | list | list := self collectionWithAll: #(2 8 6 7 3 9 4 5 1). list sort: CTNaturalComparator new from: 4 to: 6. self assertIterable: list equals: #(2 8 6 3 7 9 4 5 1)! ! CTListTest subclass: #CTVectorListTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Lists'! !CTVectorListTest methodsFor: 'accessing' stamp: 'lr 1/21/2012 19:28'! collectionClass ^ CTVectorList! ! CTCollectionTest subclass: #CTSetTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Abstract'! CTSetTest subclass: #CTHashSetTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Sets'! !CTHashSetTest methodsFor: 'accessing' stamp: 'lr 1/13/2012 22:47'! collectionClass ^ CTHashSet! ! CTHashSetTest subclass: #CTLinkedHashSetTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Sets'! !CTLinkedHashSetTest methodsFor: 'accessing' stamp: 'lr 1/13/2012 22:47'! collectionClass ^ CTLinkedHashSet! ! !CTLinkedHashSetTest methodsFor: 'testing' stamp: 'lr 1/14/2012 13:33'! testAddInOrder | collection | collection := self collectionWithAll: #($l $u $k $a $s). self assertIterable: #($l $u $k $a $s) equals: collection.. self assertInvariants: collection. collection add: $k. self assertIterable: #($l $u $a $s $k) equals: collection. self assertInvariants: collection. collection add: $l. self assertIterable: #($u $a $s $k $l) equals: collection. self assertInvariants: collection. collection add: $l. self assertIterable: #($u $a $s $k $l) equals: collection. self assertInvariants: collection. collection add: $x. self assertIterable: #($u $a $s $k $l $x) equals: collection. self assertInvariants: collection! ! !CTLinkedHashSetTest methodsFor: 'testing' stamp: 'lr 1/14/2012 13:33'! testRemoveInOrder | collection | collection := self collectionWithAll: #($l $u $k $a $s). self assertIterable: #($l $u $k $a $s) equals: collection.. self assertInvariants: collection. collection remove: $u. self assertIterable: #($l $k $a $s) equals: collection. self assertInvariants: collection. collection remove: $l. self assertIterable: #($k $a $s) equals: collection. self assertInvariants: collection. collection remove: $s. self assertIterable: #($k $a) equals: collection. self assertInvariants: collection! ! !CTSetTest class methodsFor: 'testing' stamp: 'lr 1/13/2012 22:47'! isAbstract ^ self name = #CTSetTest! ! !CTSetTest methodsFor: 'accessing' stamp: 'lr 1/13/2012 22:46'! collectionClass ^ CTSet! ! !CTSetTest methodsFor: 'tests-adding' stamp: 'lr 1/14/2012 10:00'! testAddDuplicates | collection | collection := self collectionWithAll: #($a $b $c). self assert: (collection add: $c) = $c. self assert: (collection add: $b) = $b. self assert: (collection add: $a) = $a. self assert: (collection size) = 3. self assert: (collection add: $d) = $d. self assert: (collection size) = 4. self assertInvariants: collection! ! !CTSetTest methodsFor: 'tests-adding' stamp: 'lr 1/14/2012 10:01'! testAddRemove | collection | collection := self emptyCollection. self deny: (collection includes: $a). self assert: (collection add: $a) = $a. self assert: (collection includes: $a). self assert: (collection add: $a) = $a. self assert: (collection includes: $a). self assert: (collection remove: $a) = $a. self deny: (collection includes: $a). self assertInvariants: collection! ! !CTSetTest methodsFor: 'tests-testing' stamp: 'lr 1/14/2012 09:59'! testIncludes | collection | collection := self collectionWithAll: #($a $b $c). self assert: (collection includes: $a). self assert: (collection includes: $b). self assert: (collection includes: $c). self deny: (collection includes: $d)! ! !CTSetTest methodsFor: 'tests-testing' stamp: 'lr 1/14/2012 09:59'! testIncludesAll | collection | collection := self collectionWithAll: #($a $b $c). self assert: (collection includesAll: #()). self assert: (collection includesAll: #($a)). self assert: (collection includesAll: #($a $b)). self assert: (collection includesAll: #($a $b $c)). self deny: (collection includesAll: #($d)). self deny: (collection includesAll: #($a $d))! ! CTSetTest subclass: #CTTreeSetTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Sets'! !CTTreeSetTest methodsFor: 'accessing' stamp: 'lr 1/15/2012 15:03'! collectionClass ^ CTTreeSet! ! CTContainerTest subclass: #CTComparatorTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Comparators'! !CTComparatorTest methodsFor: 'utilies' stamp: 'lr 1/22/2012 19:37'! assertPrintString: anOrder! ! !CTComparatorTest methodsFor: 'tests-operators' stamp: 'lr 1/22/2012 19:16'! testCombine | array | array := #(('Pierre' 'Curie') ('Marie' 'Curie') ('Tina' 'Turner') ('Ike' 'Turner') ('Gerald' 'Ford') ('Betty' 'Ford')). #first asOrder , #last asOrder sort: array. self assert: array = #(('Betty' 'Ford') ('Gerald' 'Ford') ('Ike' 'Turner') ('Marie' 'Curie') ('Pierre' 'Curie') ('Tina' 'Turner')). #last asOrder , #first asOrder sort: array. self assert: array = #(('Marie' 'Curie') ('Pierre' 'Curie') ('Betty' 'Ford') ('Gerald' 'Ford') ('Ike' 'Turner') ('Tina' 'Turner'))! ! !CTComparatorTest methodsFor: 'tests-testing' stamp: 'lr 1/24/2012 19:15'! testIsPartial | order | order := CTNaturalComparator new. self assert: (order isPartial: #()). self assert: (order isPartial: #(1)). self assert: (order isPartial: #(1 2)). self assert: (order isPartial: #(1 2 3)). self assert: (order isPartial: #(1 1 2 3)). self assert: (order isPartial: #(1 2 2 3)). self assert: (order isPartial: #(1 2 3 3)). self deny: (order isPartial: #(2 1 2 3)). self deny: (order isPartial: #(1 2 3 2))! ! !CTComparatorTest methodsFor: 'tests-testing' stamp: 'lr 1/24/2012 19:15'! testIsStrict | order | order := CTNaturalComparator new. self assert: (order isStrict: #()). self assert: (order isStrict: #(1)). self assert: (order isStrict: #(1 2)). self assert: (order isStrict: #(1 2 3)). self deny: (order isStrict: #(1 1 2 3)). self deny: (order isStrict: #(1 2 2 3)). self deny: (order isStrict: #(1 2 3 3)). self deny: (order isStrict: #(2 1 2 3)). self deny: (order isStrict: #(1 2 3 2))! ! !CTComparatorTest methodsFor: 'tests-querying' stamp: 'lr 1/24/2012 19:15'! testMaximum | order | order := CTNaturalComparator new. self should: [ order maximum: #() ] raise: CTNoSuchElementError. self assert: (order maximum: #(1)) = 1. self assert: (order maximum: #(1 2)) = 2. self assert: (order maximum: #(2 1)) = 2. self assert: (order maximum: #(3 2 1)) = 3. self assert: (order maximum: #(3 2 3)) = 3! ! !CTComparatorTest methodsFor: 'tests-querying' stamp: 'lr 1/24/2012 19:15'! testMinimum | order | order := CTNaturalComparator new. self should: [ order minimum: #() ] raise: CTNoSuchElementError. self assert: (order minimum: #(1)) = 1. self assert: (order minimum: #(1 2)) = 1. self assert: (order minimum: #(2 1)) = 1. self assert: (order minimum: #(3 2 1)) = 1. self assert: (order minimum: #(3 2 2)) = 2! ! !CTComparatorTest methodsFor: 'tests-operators' stamp: 'lr 1/22/2012 19:23'! testMutating | order array | array := #('Pierre' 'Ike' 'Barbara' 'Betty' 'Tina' 'Kimberley'). #yourself asOrder sort: array. self assert: array = #('Barbara' 'Betty' 'Ike' 'Kimberley' 'Pierre' 'Tina'). #size asOrder sort: array. self assert: array = #('Ike' 'Tina' 'Betty' 'Pierre' 'Barbara' 'Kimberley'). #asLowercase asOrder sort: array. self assert: array = #('Barbara' 'Betty' 'Ike' 'Kimberley' 'Pierre' 'Tina') ! ! !CTComparatorTest methodsFor: 'tests-operators' stamp: 'lr 1/24/2012 19:15'! testReverse | order array | order := CTNaturalComparator new. array := #('Pierre' 'Marie' 'Tina' 'Ike' 'Gerald' 'Betty' 'Ford'). order := order reverse. order sort: array. self assert: array = #('Tina' 'Pierre' 'Marie' 'Ike' 'Gerald' 'Ford' 'Betty'). order := order reverse. order sort: array. self assert: array = #('Betty' 'Ford' 'Gerald' 'Ike' 'Marie' 'Pierre' 'Tina')! ! !CTComparatorTest methodsFor: 'tests-sorting' stamp: 'lr 1/24/2012 19:15'! testSortRandomizedArray | array | array := Array new: 10000. 1 to: 10000 do: [ :index | array at: index put: index ]. CTNaturalComparator new sort: array shuffled. 1 to: 10000 do: [ :index | self assert: (array at: index) = index ]! ! !CTComparatorTest methodsFor: 'tests-sorting' stamp: 'lr 1/24/2012 19:15'! testSortReversedArray | array | array := Array new: 10000. 1 to: 10000 do: [ :index | array at: index put: 10001 - index ]. CTNaturalComparator new sort: array. 1 to: 10000 do: [ :index | self assert: (array at: index) = index ]! ! !CTComparatorTest methodsFor: 'tests-sorting' stamp: 'lr 1/24/2012 19:15'! testSortSortedArray | array | array := Array new: 10000. 1 to: 10000 do: [ :index | array at: index put: index ]. CTNaturalComparator new sort: array. 1 to: 10000 do: [ :index | self assert: (array at: index) = index ]! ! !CTContainerTest class methodsFor: 'testing' stamp: 'lr 1/14/2012 11:15'! isAbstract ^ self name = #CTContainerTest! ! !CTContainerTest class methodsFor: 'accessing' stamp: 'lr 1/14/2012 14:37'! packageNamesUnderTest ^ #('Container-Core')! ! !CTContainerTest class methodsFor: 'testing' stamp: 'lr 1/14/2012 14:36'! shouldInheritSelectors ^ true! ! !CTContainerTest methodsFor: 'creational' stamp: 'lr 1/22/2012 18:42'! addNumbers: anInteger into: aCollection "Adds the randomly shuffled numbers from 1 to anInteger into aCollection: http://en.wikipedia.org/wiki/Fisher Yates_shuffle" | numbers | numbers := Array new: anInteger. 1 to: anInteger do: [ :index | numbers at: index put: index ]. anInteger to: 2 by: -1 do: [ :index | numbers swap: index with: index atRandom ]. aCollection addAll: numbers. ^ aCollection! ! !CTContainerTest methodsFor: 'utilities' stamp: 'lr 1/24/2012 19:25'! assertInvariants: anObject anObject assertInvariants: self! ! !CTContainerTest methodsFor: 'utilities' stamp: 'lr 1/14/2012 12:05'! assertIsEmpty: anIterable self assert: anIterable iterator isEmpty. self deny: anIterable iterator hasNext! ! !CTContainerTest methodsFor: 'utilities' stamp: 'lr 1/14/2012 11:16'! assertIterable: firstCollection equals: secondCollection | firstIterator secondIterator | firstIterator := firstCollection iterator. secondIterator := secondCollection iterator. [ firstIterator hasNext and: [ secondIterator hasNext ] ] whileTrue: [ self assert: firstIterator next = secondIterator next ]. self assertIsEmpty: firstIterator; assertIsEmpty: secondIterator! ! CTContainerTest subclass: #CTIteratorTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Iterators'! !CTIteratorTest methodsFor: 'tests-modifications' stamp: 'lr 1/20/2012 22:16'! testAddTo | collection | collection := CTArrayList new. #(1 2 3 4) iterator addTo: collection. self assertIterable: collection equals: #(1 2 3 4)! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:02'! testAllSatisfy self assert: (#() forwardIterator allSatisfy: [ :each | each > 2 ]). self assert: (#() backwardIterator allSatisfy: [ :each | each > 2 ]). self deny: (#(1) forwardIterator allSatisfy: [ :each | each > 2 ]). self deny: (#(1) backwardIterator allSatisfy: [ :each | each > 2 ]). self assert: (#(3) forwardIterator allSatisfy: [ :each | each > 2 ]). self assert: (#(3) backwardIterator allSatisfy: [ :each | each > 2 ]). self deny: (#(2 3 4) forwardIterator allSatisfy: [ :each | each > 2 ]). self deny: (#(2 3 4) backwardIterator allSatisfy: [ :each | each > 2 ]). self assert: (#(3 4 5) forwardIterator allSatisfy: [ :each | each > 2 ]). self assert: (#(3 4 5) backwardIterator allSatisfy: [ :each | each > 2 ])! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:01'! testAnySatisfy self deny: (#() forwardIterator anySatisfy: [ :each | each > 2 ]). self deny: (#() backwardIterator anySatisfy: [ :each | each > 2 ]). self assert: (#(3) forwardIterator anySatisfy: [ :each | each > 2 ]). self assert: (#(3) backwardIterator anySatisfy: [ :each | each > 2 ]). self deny: (#(1) forwardIterator anySatisfy: [ :each | each > 2 ]). self deny: (#(1) backwardIterator anySatisfy: [ :each | each > 2 ]). self assert: (#(1 2 3) forwardIterator anySatisfy: [ :each | each > 2 ]). self assert: (#(1 2 3) backwardIterator anySatisfy: [ :each | each > 2 ]). self deny: (#(0 1 2) forwardIterator anySatisfy: [ :each | each > 2 ]). self deny: (#(0 1 2) backwardIterator anySatisfy: [ :each | each > 2 ])! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/13/2012 11:01'! testArrayIteratorBidirectional self assertIterable: #() forwardIterator equals: #() backwardIterator. self assertIterable: #(1) forwardIterator equals: #(1) backwardIterator. self assertIterable: #(1 2) forwardIterator equals: #(2 1) backwardIterator. self assertIterable: #(1 2 3) forwardIterator equals: #(3 2 1) backwardIterator. self assertIterable: #(1 2 3 4) forwardIterator equals: #(4 3 2 1) backwardIterator. self assertIterable: #(1 2 3 4 5) forwardIterator equals: #(5 4 3 2 1) backwardIterator! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 22:30'! testArrayIteratorForwardCollect | letters expected | letters := #($a $b $c). expected := #(1 $A 2 $B 3 $C) iterator. (letters iterator collect: [ :each | each asUppercase ]) do: [ :index :each | self assert: index = expected next. self assert: each = expected next ]. self assertIsEmpty: expected. expected := #(10 20 30) iterator. (letters iterator collect: [ :index :each | index * 10 ]) do: [ :each | self assert: each = expected next ]. self assertIsEmpty: expected! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 22:30'! testArrayIteratorForwardDo | letters expected | letters := #($a $b $c $d). expected := #(1 $a 2 $b 3 $c 4 $d) iterator. #($a $b $c $d) iterator do: [ :index :each | self assert: index = expected next. self assert: each = expected next ]. self assertIsEmpty: expected! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 22:30'! testArrayIteratorForwardInject | letters expected | letters := #($a $b $c). expected := #(0 $a 10 $b 20 $c) iterator. letters iterator inject: 0 into: [ :result :each | self assert: result = expected next. self assert: each = expected next. result + 10 ]. self assertIsEmpty: expected. expected := #(0 1 $a 10 2 $b 20 3 $c) iterator. letters iterator inject: 0 into: [ :result :index :each | self assert: result = expected next. self assert: index = expected next. self assert: each = expected next. result + 10 ]. self assertIsEmpty: expected! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 22:30'! testArrayIteratorForwardSelect | letters expected | letters := #($a $b $c $d $e $f $g). expected := #(1 $a 5 $e) iterator. (letters iterator select: [ :each | each isVowel ]) do: [ :index :each | self assert: index = expected next. self assert: each = expected next ]. self assertIsEmpty: expected. expected := #($b $d $f) iterator. (letters iterator select: [ :index :each | index even ]) do: [ :each | self assert: each = expected next ]. self assertIsEmpty: expected! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/13/2012 10:59'! testArrayIteratorReverseDo | letters expected | letters := #($a $b $c $d). expected := #(4 $d 3 $c 2 $b 1 $a) iterator. #($a $b $c $d) backwardIterator do: [ :index :each | self assert: index = expected next. self assert: each = expected next ]. self assertIsEmpty: expected! ! !CTIteratorTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 22:33'! testCollect self assertIterable: (#() iterator collect: [ :each | 2 * each ]) equals: #(). self assertIterable: (#(1) iterator collect: [ :each | 2 * each ]) equals: #(2). self assertIterable: (#(1 2) iterator collect: [ :each | 2 * each ]) equals: #(2 4). self assertIterable: (#(1 2 3 4) iterator collect: [ :each | 2 * each ]) equals: #(2 4 6 8)! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:02'! testCount self assert: (#() forwardIterator count: [ :each | each > 2 ]) = 0. self assert: (#() backwardIterator count: [ :each | each > 2 ]) = 0. self assert: (#(1) forwardIterator count: [ :each | each > 2 ]) = 0. self assert: (#(1) backwardIterator count: [ :each | each > 2 ]) = 0. self assert: (#(1 2) forwardIterator count: [ :each | each > 2 ]) = 0. self assert: (#(1 2) backwardIterator count: [ :each | each > 2 ]) = 0. self assert: (#(1 2 3) forwardIterator count: [ :each | each > 2 ]) = 1. self assert: (#(1 2 3) backwardIterator count: [ :each | each > 2 ]) = 1. self assert: (#(1 2 3 4) forwardIterator count: [ :each | each > 2 ]) = 2. self assert: (#(1 2 3 4) backwardIterator count: [ :each | each > 2 ]) = 2! ! !CTIteratorTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 22:33'! testCycle self assertIterable: (#() iterator cycle limit: 5) equals: #(). self assertIterable: (#(1) iterator cycle limit: 5) equals: #(1 1 1 1 1). self assertIterable: (#(1 2) iterator cycle limit: 5) equals: #(1 2 1 2 1). self assertIterable: (#(1 2 3) iterator cycle limit: 5) equals: #(1 2 3 1 2). self assertIterable: (#(1 2 3 4) iterator cycle limit: 5) equals: #(1 2 3 4 1)! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:02'! testDetect self should: [ #() forwardIterator detect: [ :each | each > 2 ] ] raise: CTNoSuchElementError. self should: [ #() backwardIterator detect: [ :each | each > 2 ] ] raise: CTNoSuchElementError. self should: [ #(1) forwardIterator detect: [ :each | each > 2 ] ] raise: CTNoSuchElementError. self should: [ #(1) backwardIterator detect: [ :each | each > 2 ] ] raise: CTNoSuchElementError. self assert: (#(3) forwardIterator detect: [ :each | each > 2 ]) = 3. self assert: (#(3) backwardIterator detect: [ :each | each > 2 ]) = 3. self assert: (#(2 3 4) forwardIterator detect: [ :each | each > 2 ]) = 3. self assert: (#(2 3 4) backwardIterator detect: [ :each | each > 2 ]) = 4. self assert: (#(3 4 5) forwardIterator detect: [ :each | each > 2 ]) = 3. self assert: (#(3 4 5) backwardIterator detect: [ :each | each > 2 ]) = 5! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:02'! testDetectIfNone self assert: (#() forwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]). self assert: (#() backwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]). self assert: (#(1) forwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]). self assert: (#(1) backwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]). self assert: (#(3) forwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 3. self assert: (#(3) backwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 3. self assert: (#(2 3 4) forwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 3. self assert: (#(2 3 4) backwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 4. self assert: (#(3 4 5) forwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 3. self assert: (#(3 4 5) backwardIterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 5! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/10/2012 22:30'! testDo | iterator | #() iterator do: [ :each | self assert: false ]. iterator := #(1 2 3 4) iterator. #(1 2 3 4) iterator do: [ :each | self assert: each = iterator next ]. self assertIsEmpty: iterator! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/10/2012 22:30'! testDoSeparatedBy | iterator | #() iterator do: [ :each | self assert: false ] separatedBy: [ self assert: false ]. iterator := #(1 nil 2 nil 3 nil 4) iterator. #(1 2 3 4) iterator do: [ :each | self assert: each = iterator next ] separatedBy: [ self assert: iterator next isNil ]. self assertIsEmpty: iterator! ! !CTIteratorTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 22:33'! testEmpty self assertIterable: CTEmptyIterator new equals: #(). self deny: CTEmptyIterator new hasNext. self should: [ CTEmptyIterator new next ] raise: CTNoSuchElementError ! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:02'! testFind self assert: (#() forwardIterator find: [ :each | each > 2 ]) = 0. self assert: (#() backwardIterator find: [ :each | each > 2 ]) = 0. self assert: (#(1) forwardIterator find: [ :each | each > 2 ]) = 0. self assert: (#(1) backwardIterator find: [ :each | each > 2 ]) = 0. self assert: (#(3) forwardIterator find: [ :each | each > 2 ]) = 1. self assert: (#(3) backwardIterator find: [ :each | each > 2 ]) = 1. self assert: (#(2 3 4) forwardIterator find: [ :each | each > 2 ]) = 2. self assert: (#(2 3 4) backwardIterator find: [ :each | each > 2 ]) = 1. self assert: (#(3 4 5) forwardIterator find: [ :each | each > 2 ]) = 1. self assert: (#(3 4 5) backwardIterator find: [ :each | each > 2 ]) = 1! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:03'! testFindIfAbsent self assert: (#() forwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]). self assert: (#() backwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]). self assert: (#(1) forwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]). self assert: (#(1) backwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]). self assert: (#(3) forwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1. self assert: (#(3) backwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1. self assert: (#(2 3 4) forwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 2. self assert: (#(2 3 4) backwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1. self assert: (#(3 4 5) forwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1. self assert: (#(3 4 5) backwardIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:04'! testIncludes self deny: (#() forwardIterator includes: 2). self deny: (#() backwardIterator includes: 2). self deny: (#(1) forwardIterator includes: 2). self deny: (#(1) backwardIterator includes: 2). self deny: (#(3) forwardIterator includes: 2). self deny: (#(3) backwardIterator includes: 2). self deny: (#(3 4 5) forwardIterator includes: 2). self deny: (#(3 4 5) backwardIterator includes: 2). self assert: (#(2 3 4) forwardIterator includes: 2). self assert: (#(2 3 4) backwardIterator includes: 2)! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:04'! testIndexOf self assert: (#() forwardIterator indexOf: 2) = 0. self assert: (#() backwardIterator indexOf: 2) = 0. self assert: (#(1) forwardIterator indexOf: 2) = 0. self assert: (#(1) backwardIterator indexOf: 2) = 0. self assert: (#(2) forwardIterator indexOf: 2) = 1. self assert: (#(2) backwardIterator indexOf: 2) = 1. self assert: (#(3 4 5) forwardIterator indexOf: 2) = 0. self assert: (#(3 4 5) backwardIterator indexOf: 2) = 0. self assert: (#(2 3 4) forwardIterator indexOf: 2) = 1. self assert: (#(2 3 4) backwardIterator indexOf: 2) = 3! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:03'! testIndexOfIfAbsent self assert: (#() forwardIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#() backwardIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(1) forwardIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(1) backwardIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(2) forwardIterator indexOf: 2 ifAbsent: [ true ]) = 1. self assert: (#(2) backwardIterator indexOf: 2 ifAbsent: [ true ]) = 1. self assert: (#(3 4 5) forwardIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(3 4 5) backwardIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(2 3 4) forwardIterator indexOf: 2 ifAbsent: [ true ]) = 1. self assert: (#(2 3 4) backwardIterator indexOf: 2 ifAbsent: [ true ]) = 3! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:03'! testInjectInto self assert: (#() forwardIterator inject: 1 into: [ :a :b | a - b ]) = 1. self assert: (#() backwardIterator inject: 1 into: [ :a :b | a - b ]) = 1. self assert: (#(2) forwardIterator inject: 1 into: [ :a :b | a - b ]) = -1. self assert: (#(2) backwardIterator inject: 1 into: [ :a :b | a - b ]) = -1. self assert: (#(3 4) forwardIterator inject: 1 into: [ :a :b | a - b ]) = -6. self assert: (#(3 4) backwardIterator inject: 1 into: [ :a :b | a - b ]) = -6. self assert: (#(4 5 6) forwardIterator inject: 1 into: [ :a :b | a - b ]) = -14. self assert: (#(4 5 6) backwardIterator inject: 1 into: [ :a :b | a - b ]) = -14. self assert: (#(5 6 7 8) forwardIterator inject: 1 into: [ :a :b | a - b ]) = -25. self assert: (#(5 6 7 8) backwardIterator inject: 1 into: [ :a :b | a - b ]) = -25! ! !CTIteratorTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 22:33'! testLimit self assertIterable: (#() iterator limit: 0) equals: #(). self assertIterable: (#(1) iterator limit: 0) equals: #(). self assertIterable: (#(1 2) iterator limit: 0) equals: #(). self assertIterable: (#(1 2 3) iterator limit: 0) equals: #(). self assertIterable: (#() iterator limit: 1) equals: #(). self assertIterable: (#(1) iterator limit: 1) equals: #(1). self assertIterable: (#(1 2) iterator limit: 1) equals: #(1). self assertIterable: (#(1 2 3) iterator limit: 1) equals: #(1). self assertIterable: (#() iterator limit: 2) equals: #(). self assertIterable: (#(1) iterator limit: 2) equals: #(1). self assertIterable: (#(1 2) iterator limit: 2) equals: #(1 2). self assertIterable: (#(1 2 3) iterator limit: 2) equals: #(1 2). self assertIterable: (#() iterator limit: 3) equals: #(). self assertIterable: (#(1) iterator limit: 3) equals: #(1). self assertIterable: (#(1 2) iterator limit: 3) equals: #(1 2). self assertIterable: (#(1 2 3) iterator limit: 3) equals: #(1 2 3). self assertIterable: (#() iterator limit: 4) equals: #(). self assertIterable: (#(1) iterator limit: 4) equals: #(1). self assertIterable: (#(1 2) iterator limit: 4) equals: #(1 2). self assertIterable: (#(1 2 3) iterator limit: 4) equals: #(1 2 3)! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:04'! testNoneSatisfy self assert: (#() forwardIterator noneSatisfy: [ :each | each > 2 ]). self assert: (#() backwardIterator noneSatisfy: [ :each | each > 2 ]). self deny: (#(3) forwardIterator noneSatisfy: [ :each | each > 2 ]). self deny: (#(3) backwardIterator noneSatisfy: [ :each | each > 2 ]). self assert: (#(1) forwardIterator noneSatisfy: [ :each | each > 2 ]). self assert: (#(1) backwardIterator noneSatisfy: [ :each | each > 2 ]). self deny: (#(1 2 3) forwardIterator noneSatisfy: [ :each | each > 2 ]). self deny: (#(1 2 3) backwardIterator noneSatisfy: [ :each | each > 2 ]). self assert: (#(0 1 2) forwardIterator noneSatisfy: [ :each | each > 2 ]). self assert: (#(0 1 2) backwardIterator noneSatisfy: [ :each | each > 2 ])! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/13/2012 11:04'! testReduce self should: [ #() forwardIterator reduce: [ :a :b | a - b ] ] raise: CTNoSuchElementError. self should: [ #() backwardIterator reduce: [ :a :b | a - b ] ] raise: CTNoSuchElementError. self assert: (#(2) forwardIterator reduce: [ :a :b | a - b ]) = 2. self assert: (#(2) backwardIterator reduce: [ :a :b | a - b ]) = 2. self assert: (#(3 4) forwardIterator reduce: [ :a :b | a - b ]) = -1. self assert: (#(3 4) backwardIterator reduce: [ :a :b | a - b ]) = 1. self assert: (#(4 5 6) forwardIterator reduce: [ :a :b | a - b ]) = -7. self assert: (#(4 5 6) backwardIterator reduce: [ :a :b | a - b ]) = -3. self assert: (#(5 6 7 8) forwardIterator reduce: [ :a :b | a - b ]) = -16. self assert: (#(5 6 7 8) backwardIterator reduce: [ :a :b | a - b ]) = -10! ! !CTIteratorTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 22:32'! testReject self assertIterable: (#() iterator reject: [ :each | each even ]) equals: #(). self assertIterable: (#(1) iterator reject: [ :each | each even ]) equals: #(1). self assertIterable: (#(1 3) iterator reject: [ :each | each even ]) equals: #(1 3). self assertIterable: (#(1 3 5) iterator reject: [ :each | each even ]) equals: #(1 3 5). self assertIterable: (#(2) iterator reject: [ :each | each even ]) equals: #(). self assertIterable: (#(2 4) iterator reject: [ :each | each even ]) equals: #(). self assertIterable: (#(2 4 6) iterator reject: [ :each | each even ]) equals: #(). self assertIterable: (#(1 2 3 4 5 6) iterator reject: [ :each | each even ]) equals: #(1 3 5). self assertIterable: (#(1 3 5 2 4 6) iterator reject: [ :each | each even ]) equals: #(1 3 5). self assertIterable: (#(2 4 6 1 3 5) iterator reject: [ :each | each even ]) equals: #(1 3 5)! ! !CTIteratorTest methodsFor: 'tests-modifications' stamp: 'lr 1/20/2012 22:16'! testRemoveFrom | collection | collection := CTArrayList new. collection add: 1; add: 2; add: 3; add: 4. #(2 4 3 1) iterator removeFrom: collection. self assert: collection isEmpty! ! !CTIteratorTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 22:31'! testSelect self assertIterable: (#() iterator select: [ :each | each even ]) equals: #(). self assertIterable: (#(1) iterator select: [ :each | each even ]) equals: #(). self assertIterable: (#(1 3) iterator select: [ :each | each even ]) equals: #(). self assertIterable: (#(1 3 5) iterator select: [ :each | each even ]) equals: #(). self assertIterable: (#(2) iterator select: [ :each | each even ]) equals: #(2). self assertIterable: (#(2 4) iterator select: [ :each | each even ]) equals: #(2 4). self assertIterable: (#(2 4 6) iterator select: [ :each | each even ]) equals: #(2 4 6). self assertIterable: (#(1 2 3 4 5 6) iterator select: [ :each | each even ]) equals: #(2 4 6). self assertIterable: (#(1 3 5 2 4 6) iterator select: [ :each | each even ]) equals: #(2 4 6). self assertIterable: (#(2 4 6 1 3 5) iterator select: [ :each | each even ]) equals: #(2 4 6) ! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 1/1/2012 00:50'! testSize self assert: #() iterator size = 0. self assert: #(1) iterator size = 1. self assert: #(1 2) iterator size = 2. self assert: #(1 2 3) iterator size = 3! ! CTContainerTest subclass: #CTMapTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Abstract'! CTMapTest subclass: #CTHashMapTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Maps'! !CTHashMapTest methodsFor: 'accessing' stamp: 'lr 1/14/2012 11:28'! mapClass ^ CTHashMap! ! CTHashMapTest subclass: #CTLinkedHashMapTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Maps'! !CTLinkedHashMapTest methodsFor: 'accessing' stamp: 'lr 1/14/2012 11:28'! mapClass ^ CTLinkedHashMap! ! !CTLinkedHashMapTest methodsFor: 'testing' stamp: 'lr 1/14/2012 13:33'! testAddInOrder | map | map := self emptyMap. map at: $l put: 1; at: $u put: 2; at: $k put: 3; at: $a put: 4; at: $s put: 5. self assertIterable: map keys equals: #($l $u $k $a $s). self assertIterable: map values equals: #(1 2 3 4 5). self assertInvariants: map. map at: $k put: 6. self assertIterable: map keys equals: #($l $u $a $s $k). self assertIterable: map values equals: #(1 2 4 5 6). self assertInvariants: map. map at: $l put: 7. self assertIterable: map keys equals: #($u $a $s $k $l). self assertIterable: map values equals: #(2 4 5 6 7). self assertInvariants: map. map at: $l put: 8. self assertIterable: map keys equals: #($u $a $s $k $l). self assertIterable: map values equals: #(2 4 5 6 8). self assertInvariants: map. map at: $x put: 9. self assertIterable: map keys equals: #($u $a $s $k $l $x). self assertIterable: map values equals: #(2 4 5 6 8 9). self assertInvariants: map! ! !CTLinkedHashMapTest methodsFor: 'testing' stamp: 'lr 1/14/2012 13:35'! testRemoveInOrder| map | map := self emptyMap. map at: $l put: 1; at: $u put: 2; at: $k put: 3; at: $a put: 4; at: $s put: 5. self assertIterable: map keys equals: #($l $u $k $a $s). self assertIterable: map values equals: #(1 2 3 4 5). self assertInvariants: map. map removeKey: $k. self assertIterable: map keys equals: #($l $u $a $s). self assertIterable: map values equals: #(1 2 4 5). self assertInvariants: map. map removeKey: $l. self assertIterable: map keys equals: #($u $a $s). self assertIterable: map values equals: #(2 4 5). self assertInvariants: map. map removeKey: $s. self assertIterable: map keys equals: #($u $a). self assertIterable: map values equals: #(2 4). self assertInvariants: map! ! !CTMapTest class methodsFor: 'testing' stamp: 'lr 1/14/2012 11:14'! isAbstract ^ self name = #CTMapTest! ! !CTMapTest methodsFor: 'accessing' stamp: 'lr 1/14/2012 11:26'! emptyMap ^ self mapClass new! ! !CTMapTest methodsFor: 'accessing' stamp: 'lr 1/14/2012 11:26'! mapClass ^ CTMap! ! !CTMapTest methodsFor: 'tests-accessing' stamp: 'lr 1/14/2012 11:32'! testAt | map | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. self assert: (map at: $a) = $b. self assert: (map at: $c) = $d. self assert: (map at: $e) = $f. self should: [ map at: $b ] raise: CTKeyNotFoundError ! ! !CTMapTest methodsFor: 'tests-accessing' stamp: 'lr 1/14/2012 11:33'! testAtIfAbsent | map | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. self assert: (map at: $a ifAbsent: [ $x ]) = $b. self assert: (map at: $c ifAbsent: [ $x ]) = $d. self assert: (map at: $e ifAbsent: [ $x ]) = $f. self assert: (map at: $b ifAbsent: [ $x ]) = $x! ! !CTMapTest methodsFor: 'tests-accessing' stamp: 'lr 1/14/2012 11:34'! testAtIfPresent | map | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. self assert: (map at: $a ifPresent: [ :v | v asUppercase ]) = $B. self assert: (map at: $c ifPresent: [ :v | v asUppercase ]) = $D. self assert: (map at: $e ifPresent: [ :v | v asUppercase ]) = $F. self assert: (map at: $b ifPresent: [ :v | v asUppercase ]) isNil! ! !CTMapTest methodsFor: 'tests-accessing' stamp: 'lr 1/14/2012 11:41'! testAtPut | map | map := self emptyMap. self assert: (map at: $a put: $b) = $b. self assert: (map at: $c put: $d) = $d. self assert: (map at: $e put: $f) = $f. self assert: (map at: $a put: $x) = $x. self assert: (map at: $a) = $x. self assertInvariants: map! ! !CTMapTest methodsFor: 'tests-copying' stamp: 'lr 1/14/2012 12:07'! testCopyEmpty | old new | old := self emptyMap. new := old copy. self deny: old == new. self assertInvariants: old. self assertInvariants: new. old at: $a put: $b. new at: $c put: $d. self assert: old size = 1. self assert: new size = 1. self assert: old keys next = $a. self assert: new keys next = $c. self assert: old values next = $b. self assert: new values next = $d! ! !CTMapTest methodsFor: 'tests-copying' stamp: 'lr 1/14/2012 12:10'! testCopyMany | old new | old := self emptyMap. 1 to: 100 do: [ :index | old at: index put: 2 * index ]. new := old copy. self deny: old == new. self assertInvariants: old. self assertInvariants: new. 1 to: 100 do: [ :index | self assert: (old at: index) = (2 * index). self assert: (new at: index) = (2 * index) ]. old at: $a put: $b. new at: $c put: $d. self assert: old size = 101. self assert: new size = 101. self assert: (old at: $a) = $b. self assert: (new at: $c) = $d. self deny: (old includesKey: $c). self deny: (new includesKey: $a)! ! !CTMapTest methodsFor: 'tests' stamp: 'lr 1/14/2012 11:26'! testEmptyMap self assertInvariants: self emptyMap! ! !CTMapTest methodsFor: 'tests-iterating' stamp: 'lr 1/14/2012 13:38'! testInjectInto | map values | map := self emptyMap. map at: 1 put: 10; at: 2 put: 20; at: 3 put: 30. self assert: (map iterator inject: 0 into: [ :result :key :value | result + key + value ]) = 66! ! !CTMapTest methodsFor: 'tests-testing' stamp: 'lr 1/14/2012 11:31'! testIsEmpty | map | map := self emptyMap. self assert: map isEmpty. map at: $a put: $b. self deny: map isEmpty! ! !CTMapTest methodsFor: 'tests-iterating' stamp: 'lr 1/25/2012 22:48'! testIterator | map keys values | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. values := CTArrayList new. map iterator do: [ :value | values add: value ]. self assert: values size = 3. self assert: (values iterator includes: $b). self assert: (values iterator includes: $d). self assert: (values iterator includes: $f). keys := CTArrayList new. values := CTArrayList new. map iterator do: [ :key :value | keys add: key. values add: value ]. self assert: keys size = 3. self assert: (keys iterator includes: $a). self assert: (keys iterator includes: $c). self assert: (keys iterator includes: $e). self assert: values size = 3. self assert: (values iterator includes: $b). self assert: (values iterator includes: $d). self assert: (values iterator includes: $f).! ! !CTMapTest methodsFor: 'tests-iterating' stamp: 'lr 1/20/2012 22:16'! testKeys | map keys | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. keys := CTArrayList new. map keys do: [ :key | keys add: key ]. self assert: keys size = 3. self assert: (keys iterator includes: $a). self assert: (keys iterator includes: $c). self assert: (keys iterator includes: $e)! ! !CTMapTest methodsFor: 'tests' stamp: 'lr 1/14/2012 12:07'! testLargeMap | map | map := self emptyMap. 100 timesRepeat: [ map at: SmallInteger maxVal atRandom put: SmallInteger maxVal atRandom ]. self assertInvariants: map! ! !CTMapTest methodsFor: 'tests' stamp: 'lr 1/14/2012 11:32'! testPrintMap | map | map := self emptyMap. self assert: map printString isString. map at: $a put: $b; at: $c put: $d; at: $e put: $f. self assert: map printString isString! ! !CTMapTest methodsFor: 'tests-removing' stamp: 'lr 1/14/2012 11:43'! testRemoveAll | map | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. map removeAll. self assert: map isEmpty. self assertInvariants: map! ! !CTMapTest methodsFor: 'tests-removing' stamp: 'lr 1/14/2012 11:42'! testRemoveKey | map | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. self should: [ map removeKey: $x ] raise: CTKeyNotFoundError. self assert: (map removeKey: $a) = $b. self assert: map size = 2. self assertInvariants: map! ! !CTMapTest methodsFor: 'tests-removing' stamp: 'lr 1/14/2012 11:43'! testRemoveKeyIfAbsent | map | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. self assert: (map removeKey: $x ifAbsent: [ $y ]) = $y. self assert: (map removeKey: $a) = $b. self assert: map size = 2. self assertInvariants: map! ! !CTMapTest methodsFor: 'tests-accessing' stamp: 'lr 1/14/2012 11:38'! testSize | map | map := self emptyMap. self assert: map size = 0. map at: $a put: $b. self assert: map size = 1. map at: $c put: $d. self assert: map size = 2. map at: $a put: $x. self assert: map size = 2! ! !CTMapTest methodsFor: 'tests' stamp: 'lr 1/14/2012 11:32'! testSmallMap | map | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. self assertInvariants: map! ! !CTMapTest methodsFor: 'tests-iterating' stamp: 'lr 1/20/2012 22:16'! testValues | map values | map := self emptyMap. map at: $a put: $b; at: $c put: $d; at: $e put: $f. values := CTArrayList new. map values do: [ :value | values add: value ]. self assert: values size = 3. self assert: (values iterator includes: $b). self assert: (values iterator includes: $d). self assert: (values iterator includes: $f)! ! !CTMapTest methodsFor: 'tests-instantiation' stamp: 'lr 1/14/2012 13:40'! testWithAll | old new | old := self emptyMap. 1 to: 100 do: [ :index | old at: index put: 2 * index ]. new := self mapClass withAll: old. self deny: old == new. self assertInvariants: old. self assertInvariants: new. 1 to: 100 do: [ :index | self assert: (old at: index) = (2 * index). self assert: (new at: index) = (2 * index) ]. old at: $a put: $b. new at: $c put: $d. self assert: old size = 101. self assert: new size = 101. self assert: (old at: $a) = $b. self assert: (new at: $c) = $d. self deny: (old includesKey: $c). self deny: (new includesKey: $a)! ! CTMapTest subclass: #CTTreeMapTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core-Maps'! !CTTreeMapTest methodsFor: 'accessing' stamp: 'lr 1/24/2012 20:45'! mapClass ^ CTTreeMap! ! !CTLinkedHashSet methodsFor: '*container-tests-core' stamp: 'lr 1/14/2012 10:36'! assertInvariants: anAsserter super assertInvariants: anAsserter. root assertInvariants: anAsserter. self assert: table size = root forwardIterator size. self assert: (self includesAll: self iterator)! ! !CTVectorList methodsFor: '*container-tests-core' stamp: 'lr 1/21/2012 19:15'! assertInvariants: anAsserter super assertInvariants: anAsserter. size + 1 to: array size do: [ :index | anAsserter assert: (array at: index) isNil ]! ! !CTArrayList methodsFor: '*container-tests-core' stamp: 'lr 1/13/2012 11:08'! assertInvariants: anAsserter super assertInvariants: anAsserter. 1 to: firstIndex - 1 do: [ :index | anAsserter assert: (array at: index) isNil ]. lastIndex + 1 to: array size do: [ :index | anAsserter assert: (array at: index) isNil ]! ! !CTLinkedList methodsFor: '*container-tests-core' stamp: 'lr 1/13/2012 11:08'! assertInvariants: anAsserter super assertInvariants: anAsserter. root assertInvariants: anAsserter! ! !CTHashTable methodsFor: '*container-tests-core' stamp: 'lr 1/24/2012 20:02'! assertInvariants: anAsserter self assert: self size = self iterator size. self assert: self size <= threshold! ! !CTHashSet methodsFor: '*container-tests-core' stamp: 'lr 1/13/2012 23:57'! assertInvariants: anAsserter super assertInvariants: anAsserter. table assertInvariants: anAsserter! ! !CTTreeMap methodsFor: '*container-tests-core' stamp: 'lr 1/25/2012 08:11'! assertInvariants: anAsserter super assertInvariants: anAsserter. tree assertInvariants: anAsserter! ! !CTMap methodsFor: '*container-tests-core' stamp: 'lr 1/14/2012 11:18'! assertInvariants: anAsserter "Asserts the internal state of this collection" anAsserter assert: self iterator size = self size description: 'Iterator and collection size are not equal'! ! !CTComparator methodsFor: '*container-tests-core' stamp: 'lr 1/24/2012 19:29'! assertInvariants: anAsserter self assert: self printString isString! ! !CTLinkedListRoot methodsFor: '*container-tests-core' stamp: 'lr 1/13/2012 11:07'! assertInvariants: anAsserter self assertInvariants: anAsserter forNode: self. self forwardIterator do: [ :node | self assertInvariants: anAsserter forNode: node ]. self backwardIterator do: [ :node | self assertInvariants: anAsserter forNode: node ]! ! !CTLinkedListRoot methodsFor: '*container-tests-core' stamp: 'lr 1/13/2012 11:07'! assertInvariants: anAsserter forNode: aNode anAsserter assert: aNode before after == aNode. anAsserter assert: aNode after before == aNode! ! !CTList methodsFor: '*container-tests-core' stamp: 'lr 1/13/2012 11:35'! assertInvariants: anAsserter super assertInvariants: anAsserter. anAsserter assert: self forwardIterator size = self size description: 'Forward-iterator and collection size are not equal'. anAsserter assert: self backwardIterator size = self size description: 'Backward-iterator and collection size are not equal'! ! !CTSplayTreeNode methodsFor: '*container-tests-core' stamp: 'lr 1/25/2012 19:22'! assertInvariants: anAsserter comparator: aComparator self left isNil ifFalse: [ anAsserter assert: (aComparator less: self left key than: self key). self left assertInvariants: anAsserter comparator: aComparator ]. self right isNil ifFalse: [ anAsserter assert: (aComparator less: self key than: self right key). self right assertInvariants: anAsserter comparator: aComparator ]! ! !CTTreeSet methodsFor: '*container-tests-core' stamp: 'lr 1/25/2012 08:11'! assertInvariants: anAsserter super assertInvariants: anAsserter. tree assertInvariants: anAsserter! ! !CTHashMap methodsFor: '*container-tests-core' stamp: 'lr 1/14/2012 10:28'! assertInvariants: anAsserter super assertInvariants: anAsserter. table assertInvariants: anAsserter! ! !CTSplayTree methodsFor: '*container-tests-core' stamp: 'lr 1/24/2012 20:02'! assertInvariants: anAsserter root isNil ifFalse: [ root assertInvariants: anAsserter comparator: comparator ]! !