Andreas Raab uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-ar.144.mcz ==================== Summary ==================== Name: CollectionsTests-ar.144 Author: ar Time: 13 February 2010, 3:38:39.957 pm UUID: 326d00ba-b767-7c4e-b795-f39a6f871b6b Ancestors: CollectionsTests-nice.143 Merge class GeneratorTest from http://source.lukas-renggli.ch/continuations/Generator-ar.5.mcz =============== Diff against CollectionsTests-nice.143 =============== Item was added: + ----- Method: GeneratorTest>>testErrorPropagation (in category 'testing') ----- + testErrorPropagation + "Ensure that errors in the generator block are properly propagated" + | generator | + self shouldnt:[generator := Generator on: [ :g | g yield: 1. g error: 'yo']] raise: Error. + self should:[generator next] raise: Error. + ! Item was added: + TestCase subclass: #GeneratorTest + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: '' + category: 'CollectionsTests-Streams'! Item was added: + ----- Method: GeneratorTest>>testEmpty (in category 'testing') ----- + testEmpty + | generator | + generator := Generator on: [ :g | ]. + self assert: generator atEnd. + self assert: generator peek isNil. + self assert: generator next isNil! Item was added: + ----- Method: GeneratorTest>>testAtEnd (in category 'testing') ----- + testAtEnd + | generator | + generator := self numbersBetween: 1 and: 3. + self deny: generator atEnd. + generator next. + self deny: generator atEnd. + generator next. + self deny: generator atEnd. + generator next. + self assert: generator atEnd! Item was added: + ----- Method: GeneratorTest>>testEnsure (in category 'testing') ----- + testEnsure + | generator | + generator := Generator on: [ :g | + [ g yield: 1; yield: 2 ] + ensure: [ g yield: 3 ] ]. + self assert: generator upToEnd asArray = #( 1 2 3 )! Item was added: + ----- Method: GeneratorTest>>fibonacciSequence (in category 'generators') ----- + fibonacciSequence + "Yields an infinite sequence of fibonacci numbers." + + ^ Generator on: [ :generator | + | a b | + a := 0. b := 1. + [ a := b + (b := a). + generator yield: a ] + repeat ]! Item was added: + ----- Method: GeneratorTest>>testSimple (in category 'testing') ----- + testSimple + | generator | + generator := Generator on: [ :g | g yield: 1; yield: 2 ]. + self assert: generator upToEnd asArray = #( 1 2 )! Item was added: + ----- Method: GeneratorTest>>testPeek (in category 'testing') ----- + testPeek + | generator | + generator := self numbersBetween: 1 and: 3. + self assert: generator peek = 1. + self assert: generator peek = 1. + generator next. + self assert: generator peek = 2! Item was added: + ----- Method: GeneratorTest>>testFibonacci (in category 'testing') ----- + testFibonacci + | generator | + generator := self fibonacciSequence. + self assert: (generator next: 10) asArray = #( 1 1 2 3 5 8 13 21 34 55 )! Item was added: + ----- Method: GeneratorTest>>testReset (in category 'testing') ----- + testReset + | generator | + generator := self numbersBetween: 1 and: 3. + self assert: generator next = 1. + self assert: generator next = 2. + generator reset. + self assert: generator next = 1. + self assert: generator next = 2. + self assert: generator next = 3. + self assert: generator next = nil. + generator reset. + self assert: generator next = 1! Item was added: + ----- Method: GeneratorTest>>testClose (in category 'testing') ----- + testClose + | generator doEnsure notEnsure | + doEnsure := notEnsure := 0. + [ generator := Generator on: [ :g | + [ g yield: 1; yield: 2 ] + ensure: [ doEnsure := doEnsure + 1 ] ]. + self assert: doEnsure = 0; assert: notEnsure = 0. + self assert: generator peek = 1. + self assert: doEnsure = 0; assert: notEnsure = 0. + generator close. + self assert: doEnsure = 1; assert: notEnsure = 0 ] + ensure: [ notEnsure := notEnsure + 1 ]. + self assert: doEnsure = 1; assert: notEnsure = 1! Item was added: + ----- Method: GeneratorTest>>testNext (in category 'testing') ----- + testNext + | generator | + generator := self numbersBetween: 1 and: 3. + self assert: generator next = 1. + self assert: generator next = 2. + self assert: generator next = 3. + self assert: generator next isNil! Item was added: + ----- Method: GeneratorTest>>testContents (in category 'testing') ----- + testContents + | generator | + generator := self numbersBetween: 1 and: 3. + self assert: generator contents = #(1 2 3)! Item was added: + ----- Method: GeneratorTest>>testResetUnwind (in category 'testing') ----- + testResetUnwind + "Just like close, just using reset" + | generator doEnsure notEnsure | + doEnsure := notEnsure := 0. + [ generator := Generator on: [ :g | + [ g yield: 1; yield: 2 ] + ensure: [ doEnsure := doEnsure + 1 ] ]. + self assert: doEnsure = 0; assert: notEnsure = 0. + self assert: generator peek = 1. + self assert: doEnsure = 0; assert: notEnsure = 0. + generator reset. + self assert: doEnsure = 1; assert: notEnsure = 0 ] + ensure: [ notEnsure := notEnsure + 1 ]. + self assert: doEnsure = 1; assert: notEnsure = 1! Item was added: + ----- Method: GeneratorTest classSide>>packageNamesUnderTest (in category 'accessing') ----- + packageNamesUnderTest + ^ #('Generator')! Item was added: + ----- Method: GeneratorTest>>numbersBetween:and: (in category 'generators') ----- + numbersBetween: aStartInteger and: aStopInteger + "Yields the nubmers between aStartInteger and aStopInteger." + + ^ Generator on: [ :generator | + aStartInteger to: aStopInteger + do: [ :value | generator yield: value ] ]! |
Free forum by Nabble | Edit this page |