[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

sunit[s8] iterating

"Test for iterations"
TestCase 
   subclass: #TestIterations
   instanceVariableNames: ''
   category: #sunit-s8!

! TestIterations methodsFor: #test!
testInterval1To10
   |result| result := #().
   (1 to: 10) do: [:i| result add: i ].
   self assert: result = #(1 2 3 4 5 6 7 8 9 10)! !

! TestIterations methodsFor: #test!
testInterval10To1
   |result| result := #().
   (10 to: 1) do: [:i| result add: i ].
   self assert: result isEmpty! !

! TestIterations methodsFor: #test!
testReverseInterval10To1
   |result| result := #().
   (10 to: 1 by: -1) do: [:i| result add: i ].
   self assert: result = #(10 9 8 7 6 5 4 3 2 1)! !

! TestIterations methodsFor: #test!
testInterval10To1By7
   |result| result := #().
   (10 to: 1 by: -7) do: [:i| result add: i ].
   self assert: result = #(10 3)! !

! TestIterations methodsFor: #test!
testIntervalAToZ
   |result| result := #().
   ($A to: $Z) do: [:i| result add: i ].
   self assert: result = #(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)! !

! TestIterations methodsFor: #test!
testIntervalAToZBy7
   |result| result := #().
   ($A to: $Z by: 7) do: [:i| result add: i ].
   self assert: result = #(A H O V)! !

! TestIterations methodsFor: #test!
testIntervalAToZBy7reverseDo
   |result| result := #().
   ($A to: $Z by: 7) reverseDo: [:i| result add: i ].
   self assert: result = #(Z S L E)! !

! TestIterations methodsFor: #test!
testIntervalAToZBy7Plus1
   |result| result := #().
   ($A to: $Z by: 7) + 1 do: [:i| result add: i ].
   self assert: result = #(B I P W)! !