SystemOrganization addCategory: #'Container-Tests-Core'! 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: 'accessing' stamp: 'lr 11/5/2011 18:42'! collectionClass ^ CTCollection! ! !CTCollectionTest methodsFor: 'accessing' stamp: 'lr 8/7/2011 19:17'! emptyCollection ^ self collectionClass new! ! !CTCollectionTest methodsFor: 'accessing' stamp: 'lr 8/7/2011 19:18'! oneElementCollection ^ self collectionClass with: 1! ! !CTCollectionTest methodsFor: 'tests-iterators' stamp: 'lr 12/31/2011 17:12'! 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 8/7/2011 19:19'! testIsEmpty self assert: self emptyCollection isEmpty. self deny: self oneElementCollection isEmpty. self deny: self twoElementCollection isEmpty! ! !CTCollectionTest methodsFor: 'tests-iterators' stamp: 'lr 12/31/2011 12:48'! testSimpleIterator | iterator | iterator := self oneElementCollection iterator. self assert: iterator hasNext. self assert: iterator next notNil. self deny: iterator hasNext. self should: [ iterator next ] raise: CTNoSuchElementError! ! !CTCollectionTest methodsFor: 'tests-accessing' stamp: 'lr 8/7/2011 19:19'! testSize self assert: self emptyCollection size = 0. self assert: self oneElementCollection size = 1. self assert: self twoElementCollection size = 2! ! !CTCollectionTest methodsFor: 'accessing' stamp: 'lr 8/7/2011 19:25'! twoElementCollection ^ self collectionClass with: 1 with: 2! ! 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-operations' stamp: 'lr 1/1/2012 01:16'! testAddFirstRemoveLast | list | list := self emptyCollection. 0001 to: 1000 do: [ :index | self assert: (list addFirst: index) = index ]. 1001 to: 2000 do: [ :index | self assert: (list addFirst: index) = index. self assert: list removeLast = (index - 1000) ]. 2001 to: 3000 do: [ :index | self assert: list removeLast = (index - 1000) ]. self assert: list isEmpty! ! !CTListTest methodsFor: 'tests-operations' stamp: 'lr 1/1/2012 01:15'! testAddLastRemoveFirst | list | list := self emptyCollection. 0001 to: 1000 do: [ :index | self assert: (list addLast: index) = index ]. 1001 to: 2000 do: [ :index | self assert: (list addLast: index) = index. self assert: list removeFirst = (index - 1000) ]. 2001 to: 3000 do: [ :index | self assert: list removeFirst = (index - 1000) ]. self assert: list isEmpty! ! !CTListTest methodsFor: 'tests-iterators' stamp: 'lr 12/31/2011 14:39'! testEmptyReverseIterator | reverseIterator | reverseIterator := self emptyCollection reverseIterator. self deny: reverseIterator hasNext. self should: [ reverseIterator next ] raise: CTNoSuchElementError! ! !CTListTest methodsFor: 'tests-accessing' stamp: 'lr 8/7/2011 20:08'! testFirst self should: [ self emptyCollection first ] raise: CTNoSuchElementError. self assert: self oneElementCollection first = 1. self assert: self twoElementCollection first = 1! ! !CTListTest methodsFor: 'tests-accessing' stamp: 'lr 8/7/2011 19:54'! testLast self should: [ self emptyCollection last ] raise: CTNoSuchElementError. self assert: self oneElementCollection last = 1. self assert: self twoElementCollection last = 2! ! !CTListTest methodsFor: 'tests-iterators' stamp: 'lr 12/31/2011 14:40'! testSimpleReverseIterator | iterator reverseIterator | iterator := self oneElementCollection iterator. reverseIterator := self oneElementCollection 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 12/31/2011 15:01'! assertIterator: anIteratorOne equals: anIteratorTwo [ anIteratorOne hasNext and: [ anIteratorTwo hasNext ] ] whileTrue: [ self assert: anIteratorOne next = anIteratorTwo next ]. self assertIteratorAtEnd: anIteratorOne; assertIteratorAtEnd: anIteratorTwo! ! !CTIteratorTest methodsFor: 'utilities' stamp: 'lr 12/31/2011 15:01'! assertIteratorAtEnd: anIterator self deny: anIterator hasNext! ! !CTIteratorTest methodsFor: 'tests-modifications' stamp: 'lr 1/1/2012 00:52'! testAddTo | collection | collection := CTArrayList new. #(1 2 3 4) iterator addTo: collection. self assertIterator: collection iterator equals: #(1 2 3 4) iterator! ! !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/9/2012 20:31'! testArrayIteratorBidirectional self assertIterator: #() iterator equals: #() reverseIterator. self assertIterator: #(1) iterator equals: #(1) reverseIterator. self assertIterator: #(1 2) iterator equals: #(2 1) reverseIterator. self assertIterator: #(1 2 3) iterator equals: #(3 2 1) reverseIterator. self assertIterator: #(1 2 3 4) iterator equals: #(4 3 2 1) reverseIterator. self assertIterator: #(1 2 3 4 5) iterator equals: #(5 4 3 2 1) reverseIterator! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 07:05'! 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 assertIteratorAtEnd: expected. expected := #(10 20 30) iterator. (letters iterator collect: [ :index :each | index * 10 ]) do: [ :each | self assert: each = expected next ]. self assertIteratorAtEnd: expected! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 07:04'! 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 assertIteratorAtEnd: expected! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 07:12'! 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 assertIteratorAtEnd: 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 assertIteratorAtEnd: expected! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 07:04'! 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 assertIteratorAtEnd: expected. expected := #($b $d $f) iterator. (letters iterator select: [ :index :each | index even ]) do: [ :each | self assert: each = expected next ]. self assertIteratorAtEnd: expected! ! !CTIteratorTest methodsFor: 'tests-array' stamp: 'lr 1/10/2012 07:05'! 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 assertIteratorAtEnd: expected! ! !CTIteratorTest methodsFor: 'tests-iterators' stamp: 'lr 1/1/2012 00:32'! testCollect self assertIterator: (#() iterator collect: [ :each | 2 * each ]) equals: #() iterator. self assertIterator: (#(1) iterator collect: [ :each | 2 * each ]) equals: #(2) iterator. self assertIterator: (#(1 2) iterator collect: [ :each | 2 * each ]) equals: #(2 4) iterator. self assertIterator: (#(1 2 3 4) iterator collect: [ :each | 2 * each ]) equals: #(2 4 6 8) iterator! ! !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/1/2012 00:47'! testCycle self assertIterator: (#() iterator cycle limit: 5) equals: #() iterator. self assertIterator: (#(1) iterator cycle limit: 5) equals: #(1 1 1 1 1) iterator. self assertIterator: (#(1 2) iterator cycle limit: 5) equals: #(1 2 1 2 1) iterator. self assertIterator: (#(1 2 3) iterator cycle limit: 5) equals: #(1 2 3 1 2) iterator. self assertIterator: (#(1 2 3 4) iterator cycle limit: 5) equals: #(1 2 3 4 1) iterator! ! !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 12/31/2011 16:27'! 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 assertIteratorAtEnd: iterator! ! !CTIteratorTest methodsFor: 'tests-enumerating' stamp: 'lr 12/31/2011 16:28'! 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 assertIteratorAtEnd: iterator! ! !CTIteratorTest methodsFor: 'tests-iterators' stamp: 'lr 1/10/2012 07:18'! testEmpty self assertIterator: CTEmptyIterator new equals: #() iterator. 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/1/2012 00:38'! testLimit self assertIterator: (#() iterator limit: 0) equals: #() iterator. self assertIterator: (#(1) iterator limit: 0) equals: #() iterator. self assertIterator: (#(1 2) iterator limit: 0) equals: #() iterator. self assertIterator: (#(1 2 3) iterator limit: 0) equals: #() iterator. self assertIterator: (#() iterator limit: 1) equals: #() iterator. self assertIterator: (#(1) iterator limit: 1) equals: #(1) iterator. self assertIterator: (#(1 2) iterator limit: 1) equals: #(1) iterator. self assertIterator: (#(1 2 3) iterator limit: 1) equals: #(1) iterator. self assertIterator: (#() iterator limit: 2) equals: #() iterator. self assertIterator: (#(1) iterator limit: 2) equals: #(1) iterator. self assertIterator: (#(1 2) iterator limit: 2) equals: #(1 2) iterator. self assertIterator: (#(1 2 3) iterator limit: 2) equals: #(1 2) iterator. self assertIterator: (#() iterator limit: 3) equals: #() iterator. self assertIterator: (#(1) iterator limit: 3) equals: #(1) iterator. self assertIterator: (#(1 2) iterator limit: 3) equals: #(1 2) iterator. self assertIterator: (#(1 2 3) iterator limit: 3) equals: #(1 2 3) iterator. self assertIterator: (#() iterator limit: 4) equals: #() iterator. self assertIterator: (#(1) iterator limit: 4) equals: #(1) iterator. self assertIterator: (#(1 2) iterator limit: 4) equals: #(1 2) iterator. self assertIterator: (#(1 2 3) iterator limit: 4) equals: #(1 2 3) iterator! ! !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 12/31/2011 23:58'! testReject self assertIterator: (#() iterator reject: [ :each | each even ]) equals: #() iterator. self assertIterator: (#(1) iterator reject: [ :each | each even ]) equals: #(1) iterator. self assertIterator: (#(1 3) iterator reject: [ :each | each even ]) equals: #(1 3) iterator. self assertIterator: (#(1 3 5) iterator reject: [ :each | each even ]) equals: #(1 3 5) iterator. self assertIterator: (#(2) iterator reject: [ :each | each even ]) equals: #() iterator. self assertIterator: (#(2 4) iterator reject: [ :each | each even ]) equals: #() iterator. self assertIterator: (#(2 4 6) iterator reject: [ :each | each even ]) equals: #() iterator. self assertIterator: (#(1 2 3 4 5 6) iterator reject: [ :each | each even ]) equals: #(1 3 5) iterator. self assertIterator: (#(1 3 5 2 4 6) iterator reject: [ :each | each even ]) equals: #(1 3 5) iterator. self assertIterator: (#(2 4 6 1 3 5) iterator reject: [ :each | each even ]) equals: #(1 3 5) iterator! ! !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 12/31/2011 23:57'! testSelect self assertIterator: (#() iterator select: [ :each | each even ]) equals: #() iterator. self assertIterator: (#(1) iterator select: [ :each | each even ]) equals: #() iterator. self assertIterator: (#(1 3) iterator select: [ :each | each even ]) equals: #() iterator. self assertIterator: (#(1 3 5) iterator select: [ :each | each even ]) equals: #() iterator. self assertIterator: (#(2) iterator select: [ :each | each even ]) equals: #(2) iterator. self assertIterator: (#(2 4) iterator select: [ :each | each even ]) equals: #(2 4) iterator. self assertIterator: (#(2 4 6) iterator select: [ :each | each even ]) equals: #(2 4 6) iterator. self assertIterator: (#(1 2 3 4 5 6) iterator select: [ :each | each even ]) equals: #(2 4 6) iterator. self assertIterator: (#(1 3 5 2 4 6) iterator select: [ :each | each even ]) equals: #(2 4 6) iterator. self assertIterator: (#(2 4 6 1 3 5) iterator select: [ :each | each even ]) equals: #(2 4 6) iterator! ! !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! !