SystemOrganization addCategory: #'Container-Tests-Core'! !CTArrayList methodsFor: '*container-tests-core' stamp: 'lr 1/11/2012 22:39'! 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 ]! ! !CTCollection methodsFor: '*container-tests-core' stamp: 'lr 1/10/2012 22:19'! assertInvariants: anAsserter "Asserts the internal state of this collection"! ! !CTLinkedList methodsFor: '*container-tests-core' stamp: 'lr 1/11/2012 22:42'! assertInvariants: anAsserter anAsserter assert: self nodeIterator size = size. self assertInvariants: anAsserter forNode: root. self nodeIterator do: [ :node | self assertInvariants: anAsserter forNode: node ]. self reverseNodeIterator do: [ :node | self assertInvariants: anAsserter forNode: node ].! ! !CTLinkedList methodsFor: '*container-tests-core' stamp: 'lr 1/11/2012 22:42'! assertInvariants: anAsserter forNode: aNode anAsserter assert: aNode before after == aNode. anAsserter assert: aNode after before == aNode! ! 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 12/31/2011 15:14'! testAllSatisfy self assert: (#() iterator allSatisfy: [ :each | each > 2 ]). self assert: (#() reverseIterator allSatisfy: [ :each | each > 2 ]). self deny: (#(1) iterator allSatisfy: [ :each | each > 2 ]). self deny: (#(1) reverseIterator allSatisfy: [ :each | each > 2 ]). self assert: (#(3) iterator allSatisfy: [ :each | each > 2 ]). self assert: (#(3) reverseIterator allSatisfy: [ :each | each > 2 ]). self deny: (#(2 3 4) iterator allSatisfy: [ :each | each > 2 ]). self deny: (#(2 3 4) reverseIterator allSatisfy: [ :each | each > 2 ]). self assert: (#(3 4 5) iterator allSatisfy: [ :each | each > 2 ]). self assert: (#(3 4 5) reverseIterator allSatisfy: [ :each | each > 2 ])! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 15:20'! testAnySatisfy self deny: (#() iterator anySatisfy: [ :each | each > 2 ]). self deny: (#() reverseIterator anySatisfy: [ :each | each > 2 ]). self assert: (#(3) iterator anySatisfy: [ :each | each > 2 ]). self assert: (#(3) reverseIterator anySatisfy: [ :each | each > 2 ]). self deny: (#(1) iterator anySatisfy: [ :each | each > 2 ]). self deny: (#(1) reverseIterator anySatisfy: [ :each | each > 2 ]). self assert: (#(1 2 3) iterator anySatisfy: [ :each | each > 2 ]). self assert: (#(1 2 3) reverseIterator anySatisfy: [ :each | each > 2 ]). self deny: (#(0 1 2) iterator anySatisfy: [ :each | each > 2 ]). self deny: (#(0 1 2) reverseIterator anySatisfy: [ :each | each > 2 ])! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 22:32'! testArrayIteratorBidirectional self assertIterable: #() iterator equals: #() reverseIterator. self assertIterable: #(1) iterator equals: #(1) reverseIterator. self assertIterable: #(1 2) iterator equals: #(2 1) reverseIterator. self assertIterable: #(1 2 3) iterator equals: #(3 2 1) reverseIterator. self assertIterable: #(1 2 3 4) iterator equals: #(4 3 2 1) reverseIterator. self assertIterable: #(1 2 3 4 5) iterator equals: #(5 4 3 2 1) reverseIterator! ! !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/10/2012 22:30'! testArrayIteratorReverseDo | letters expected | letters := #($a $b $c $d). expected := #(4 $d 3 $c 2 $b 1 $a) iterator. #($a $b $c $d) reverseIterator 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 12/31/2011 15:21'! testCount self assert: (#() iterator count: [ :each | each > 2 ]) = 0. self assert: (#() reverseIterator count: [ :each | each > 2 ]) = 0. self assert: (#(1) iterator count: [ :each | each > 2 ]) = 0. self assert: (#(1) reverseIterator count: [ :each | each > 2 ]) = 0. self assert: (#(1 2) iterator count: [ :each | each > 2 ]) = 0. self assert: (#(1 2) reverseIterator count: [ :each | each > 2 ]) = 0. self assert: (#(1 2 3) iterator count: [ :each | each > 2 ]) = 1. self assert: (#(1 2 3) reverseIterator count: [ :each | each > 2 ]) = 1. self assert: (#(1 2 3 4) iterator count: [ :each | each > 2 ]) = 2. self assert: (#(1 2 3 4) reverseIterator 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 12/31/2011 16:16'! testDetect self should: [ #() iterator detect: [ :each | each > 2 ] ] raise: CTNoSuchElementError. self should: [ #() reverseIterator detect: [ :each | each > 2 ] ] raise: CTNoSuchElementError. self should: [ #(1) iterator detect: [ :each | each > 2 ] ] raise: CTNoSuchElementError. self should: [ #(1) reverseIterator detect: [ :each | each > 2 ] ] raise: CTNoSuchElementError. self assert: (#(3) iterator detect: [ :each | each > 2 ]) = 3. self assert: (#(3) reverseIterator detect: [ :each | each > 2 ]) = 3. self assert: (#(2 3 4) iterator detect: [ :each | each > 2 ]) = 3. self assert: (#(2 3 4) reverseIterator detect: [ :each | each > 2 ]) = 4. self assert: (#(3 4 5) iterator detect: [ :each | each > 2 ]) = 3. self assert: (#(3 4 5) reverseIterator detect: [ :each | each > 2 ]) = 5! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 16:20'! testDetectIfNone self assert: (#() iterator detect: [ :each | each > 2 ] ifNone: [ true ]). self assert: (#() reverseIterator detect: [ :each | each > 2 ] ifNone: [ true ]). self assert: (#(1) iterator detect: [ :each | each > 2 ] ifNone: [ true ]). self assert: (#(1) reverseIterator detect: [ :each | each > 2 ] ifNone: [ true ]). self assert: (#(3) iterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 3. self assert: (#(3) reverseIterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 3. self assert: (#(2 3 4) iterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 3. self assert: (#(2 3 4) reverseIterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 4. self assert: (#(3 4 5) iterator detect: [ :each | each > 2 ] ifNone: [ true ]) = 3. self assert: (#(3 4 5) reverseIterator 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 12/31/2011 16:31'! testFind self assert: (#() iterator find: [ :each | each > 2 ]) = 0. self assert: (#() reverseIterator find: [ :each | each > 2 ]) = 0. self assert: (#(1) iterator find: [ :each | each > 2 ]) = 0. self assert: (#(1) reverseIterator find: [ :each | each > 2 ]) = 0. self assert: (#(3) iterator find: [ :each | each > 2 ]) = 1. self assert: (#(3) reverseIterator find: [ :each | each > 2 ]) = 1. self assert: (#(2 3 4) iterator find: [ :each | each > 2 ]) = 2. self assert: (#(2 3 4) reverseIterator find: [ :each | each > 2 ]) = 1. self assert: (#(3 4 5) iterator find: [ :each | each > 2 ]) = 1. self assert: (#(3 4 5) reverseIterator find: [ :each | each > 2 ]) = 1! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 16:33'! testFindIfAbsent self assert: (#() iterator find: [ :each | each > 2 ] ifAbsent: [ true ]). self assert: (#() reverseIterator find: [ :each | each > 2 ] ifAbsent: [ true ]). self assert: (#(1) iterator find: [ :each | each > 2 ] ifAbsent: [ true ]). self assert: (#(1) reverseIterator find: [ :each | each > 2 ] ifAbsent: [ true ]). self assert: (#(3) iterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1. self assert: (#(3) reverseIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1. self assert: (#(2 3 4) iterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 2. self assert: (#(2 3 4) reverseIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1. self assert: (#(3 4 5) iterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1. self assert: (#(3 4 5) reverseIterator find: [ :each | each > 2 ] ifAbsent: [ true ]) = 1! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 16:51'! testIncludes self deny: (#() iterator includes: 2). self deny: (#() reverseIterator includes: 2). self deny: (#(1) iterator includes: 2). self deny: (#(1) reverseIterator includes: 2). self deny: (#(3) iterator includes: 2). self deny: (#(3) reverseIterator includes: 2). self deny: (#(3 4 5) iterator includes: 2). self deny: (#(3 4 5) reverseIterator includes: 2). self assert: (#(2 3 4) iterator includes: 2). self assert: (#(2 3 4) reverseIterator includes: 2)! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 16:56'! testIndexOf self assert: (#() iterator indexOf: 2) = 0. self assert: (#() reverseIterator indexOf: 2) = 0. self assert: (#(1) iterator indexOf: 2) = 0. self assert: (#(1) reverseIterator indexOf: 2) = 0. self assert: (#(2) iterator indexOf: 2) = 1. self assert: (#(2) reverseIterator indexOf: 2) = 1. self assert: (#(3 4 5) iterator indexOf: 2) = 0. self assert: (#(3 4 5) reverseIterator indexOf: 2) = 0. self assert: (#(2 3 4) iterator indexOf: 2) = 1. self assert: (#(2 3 4) reverseIterator indexOf: 2) = 3! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 16:58'! testIndexOfIfAbsent self assert: (#() iterator indexOf: 2 ifAbsent: [ true ]). self assert: (#() reverseIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(1) iterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(1) reverseIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(2) iterator indexOf: 2 ifAbsent: [ true ]) = 1. self assert: (#(2) reverseIterator indexOf: 2 ifAbsent: [ true ]) = 1. self assert: (#(3 4 5) iterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(3 4 5) reverseIterator indexOf: 2 ifAbsent: [ true ]). self assert: (#(2 3 4) iterator indexOf: 2 ifAbsent: [ true ]) = 1. self assert: (#(2 3 4) reverseIterator indexOf: 2 ifAbsent: [ true ]) = 3! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 17:11'! testInjectInto self assert: (#() iterator inject: 1 into: [ :a :b | a - b ]) = 1. self assert: (#() reverseIterator inject: 1 into: [ :a :b | a - b ]) = 1. self assert: (#(2) iterator inject: 1 into: [ :a :b | a - b ]) = -1. self assert: (#(2) reverseIterator inject: 1 into: [ :a :b | a - b ]) = -1. self assert: (#(3 4) iterator inject: 1 into: [ :a :b | a - b ]) = -6. self assert: (#(3 4) reverseIterator inject: 1 into: [ :a :b | a - b ]) = -6. self assert: (#(4 5 6) iterator inject: 1 into: [ :a :b | a - b ]) = -14. self assert: (#(4 5 6) reverseIterator inject: 1 into: [ :a :b | a - b ]) = -14. self assert: (#(5 6 7 8) iterator inject: 1 into: [ :a :b | a - b ]) = -25. self assert: (#(5 6 7 8) reverseIterator 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 12/31/2011 17:00'! testNoneSatisfy self assert: (#() iterator noneSatisfy: [ :each | each > 2 ]). self assert: (#() reverseIterator noneSatisfy: [ :each | each > 2 ]). self deny: (#(3) iterator noneSatisfy: [ :each | each > 2 ]). self deny: (#(3) reverseIterator noneSatisfy: [ :each | each > 2 ]). self assert: (#(1) iterator noneSatisfy: [ :each | each > 2 ]). self assert: (#(1) reverseIterator noneSatisfy: [ :each | each > 2 ]). self deny: (#(1 2 3) iterator noneSatisfy: [ :each | each > 2 ]). self deny: (#(1 2 3) reverseIterator noneSatisfy: [ :each | each > 2 ]). self assert: (#(0 1 2) iterator noneSatisfy: [ :each | each > 2 ]). self assert: (#(0 1 2) reverseIterator noneSatisfy: [ :each | each > 2 ])! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 17:08'! testReduce self should: [ #() iterator reduce: [ :a :b | a - b ] ] raise: CTNoSuchElementError. self should: [ #() reverseIterator reduce: [ :a :b | a - b ] ] raise: CTNoSuchElementError. self assert: (#(2) iterator reduce: [ :a :b | a - b ]) = 2. self assert: (#(2) reverseIterator reduce: [ :a :b | a - b ]) = 2. self assert: (#(3 4) iterator reduce: [ :a :b | a - b ]) = -1. self assert: (#(3 4) reverseIterator reduce: [ :a :b | a - b ]) = 1. self assert: (#(4 5 6) iterator reduce: [ :a :b | a - b ]) = -7. self assert: (#(4 5 6) reverseIterator reduce: [ :a :b | a - b ]) = -3. self assert: (#(5 6 7 8) iterator reduce: [ :a :b | a - b ]) = -16. self assert: (#(5 6 7 8) reverseIterator 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! !