Skip to content

Commit

Permalink
Merge pull request #816 from ApptiveGrid/More-tests-Iterator
Browse files Browse the repository at this point in the history
Test and fix for iterator: empty #reverseDo:
  • Loading branch information
noha authored Sep 24, 2024
2 parents d48c1eb + 275e77b commit 2d222c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion src/Soil-Core-Tests/SoilIndexIteratorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,31 @@ SoilIndexIteratorTest >> testNextKeyCloseTo [
self assert: (iterator nextKeyCloseTo: 100) equals: 20
]

{ #category : #tests }
SoilIndexIteratorTest >> testNextPage [

| capacity iterator value expected |
iterator := index newIterator.

"empty case"
iterator findPageFor: 1.
value := iterator nextPage.
self assert: value isNil.

capacity := index headerPage itemCapacity * 2.
1 to: capacity do: [ :n |
index at: n put: (n asByteArrayOfSize: 8) ].

expected := index class == SoilBTree ifTrue: [ 4 ] ifFalse: [ 2 ].
value := iterator
findPageFor: 222.
self assert: iterator nextPage index equals: expected.

value := iterator
findPageFor: capacity + 1.
self assert: iterator nextPage isNil
]

{ #category : #tests }
SoilIndexIteratorTest >> testPrevious [

Expand Down Expand Up @@ -776,8 +801,12 @@ SoilIndexIteratorTest >> testReverseDo [

| capacity result |

"empty case"
result := OrderedCollection new.
index newIterator reverseDo: [ :each | result add: each ].
self assert: result size equals: 0.

result := OrderedCollection new.

capacity := index headerPage itemCapacity * 2.
1 to: capacity do: [ :n |
index at: n put: (n asByteArrayOfSize: 8) ].
Expand Down
2 changes: 1 addition & 1 deletion src/Soil-Core/SoilIndexIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ SoilIndexIterator >> restoreItem: anItem [
{ #category : #enumerating }
SoilIndexIterator >> reverseDo: aBlock [
| item |
aBlock value: self lastAssociation value.
self lastAssociation ifNotNil: [ :last | aBlock value: last value ] ifNil: [ ^self ].

"We use basicNextAssociation to avoid the creation of intermediate associations of nextAssociation"
[ (item := self basicPreviousAssociation ) notNil ] whileTrue: [
Expand Down

0 comments on commit 2d222c9

Please sign in to comment.