SystemOrganization addCategory: #'Container-Tests-Core'! !CTCollection methodsFor: '*container-tests-core' stamp: 'lr 1/13/2012 11:08'! assertInvariants: anAsserter "Asserts the internal state of this collection" anAsserter assert: self iterator size = self size! ! TestCase subclass: #CTCollectionTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core'! !CTCollectionTest class methodsFor: 'testing' stamp: 'lr 8/7/2011 19:59'! isAbstract ^ self name = #CTCollectionTest! ! !CTCollectionTest class methodsFor: 'accessing' stamp: 'lr 12/31/2011 12:42'! packageNamesUnderTest ^ #('Container')! ! !CTCollectionTest methodsFor: 'utilities' stamp: 'lr 1/11/2012 22:45'! assertInvariants: aCollection aCollection assertInvariants: self! ! !CTCollectionTest methodsFor: 'utilities' stamp: 'lr 1/10/2012 22:34'! assertIsEmpty: anIterable self deny: anIterable iterator hasNext! ! !CTCollectionTest methodsFor: 'utilities' stamp: 'lr 1/10/2012 22:34'! 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! ! !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/10/2012 07:44'! collectionWithRandomElements: anInteger | collection | collection := self collectionClass new: anInteger. anInteger timesRepeat: [ collection add: anInteger atRandom ]. ^ collection! ! !CTCollectionTest methodsFor: 'accessing' stamp: 'lr 1/11/2012 22:44'! emptyCollection ^ self collectionClass new! ! !CTCollectionTest methodsFor: 'tests-copying' stamp: 'lr 1/11/2012 22:46'! testCopyEmpty | old new | old := self emptyCollection. new := old copy. self deny: old == 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! ! !CTCollectionTest methodsFor: 'tests-copying' stamp: 'lr 1/11/2012 22:47'! 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-iterators' stamp: 'lr 1/11/2012 22:44'! testEmptyIterator | iterator | iterator := self emptyCollection iterator. self deny: iterator hasNext; assert: iterator isEmpty. self should: [ iterator next ] raise: CTNoSuchElementError! ! !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' stamp: 'lr 1/11/2012 22:46'! testLargeCollection self assertInvariants: (self collectionWithRandomElements: 1000)! ! !CTCollectionTest methodsFor: 'tests-removing' stamp: 'lr 1/11/2012 22:47'! 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 assertIterable: collection equals: #($b $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/11/2012 22:47'! 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 assertIterable: collection equals: #($b $d). self assertInvariants: collection! ! !CTCollectionTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 07:46'! testSimpleIterator | collection iterator | collection := self collectionWithAll: #($a). iterator := collection iterator. self assert: iterator hasNext. self assert: iterator next = $a. self deny: iterator hasNext. self should: [ iterator next ] raise: CTNoSuchElementError! ! !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 subclass: #CTListTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core'! CTListTest subclass: #CTArrayListTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core'! !CTArrayListTest methodsFor: 'accessing' stamp: 'lr 8/7/2011 19:21'! collectionClass ^ CTArrayList! ! CTListTest subclass: #CTLinkedListTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core'! !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/11/2012 22:44'! testEmptyReverseIterator | reverseIterator | reverseIterator := self emptyCollection reverseIterator. self deny: reverseIterator hasNext. self should: [ reverseIterator next ] raise: CTNoSuchElementError! ! !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-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/10/2012 23:32'! testRemoveLast | letters collection | letters := #($a $b $c $d $e). collection := self collectionWithAll: letters. letters reverseIterator do: [ :each | self assert: collection removeLast = each ]. self should: [ collection removeFirst ] raise: CTNoSuchElementError. self assertIterable: collection equals: #()! ! !CTListTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 07:53'! testSimpleReverseIterator | collection iterator reverseIterator | collection := self collectionWithAll: #($a). iterator := collection iterator. reverseIterator := collection reverseIterator. self assert: reverseIterator hasNext. self assert: reverseIterator next = iterator next. self deny: reverseIterator hasNext. self should: [ reverseIterator next ] raise: CTNoSuchElementError! ! TestCase subclass: #CTIteratorTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Container-Tests-Core'! !CTIteratorTest methodsFor: 'utilities' stamp: 'lr 1/10/2012 22:30'! assertIsEmpty: anIterable self deny: anIterable iterator hasNext! ! !CTIteratorTest methodsFor: 'utilities' stamp: 'lr 1/10/2012 22:30'! 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! ! !CTIteratorTest methodsFor: 'tests-modifications' stamp: 'lr 1/10/2012 22:31'! 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/1/2012 00:53'! 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! ! !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 ]! ! !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! ! !CTLinkedList methodsFor: '*container-tests-core' stamp: 'lr 1/13/2012 11:08'! assertInvariants: anAsserter super assertInvariants: anAsserter. root assertInvariants: anAsserter! !