Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Coverage + fix SoilIndexedDictionary>>#removeKey:ifAbsent: #477

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,34 @@ SoilIndexedDictionaryTest >> testAtIndex [
self assert: (dict atIndex: 1) equals: #bar2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testAtIndexWithTransaction [
| tx tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: 1 put: #one.
dict at: 2 put: #two.
tx commit.
"open a second transaction ..."
tx2 := soil newTransaction.
"and test atIndex:"
self assert: (tx2 root atIndex: 1) equals: #one

]

{ #category : #tests }
SoilIndexedDictionaryTest >> testDo [
| counter |
dict at: #foo2 put: #bar2.
dict at: #foo put: #bar.

counter := 0.
dict do: [ :each |
self assert: (each beginsWith: 'bar').
counter := counter + 1].
self assert: counter equals: 2
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFirst [
dict at: #foo2 put: #bar2.
Expand Down Expand Up @@ -353,6 +381,34 @@ SoilIndexedDictionaryTest >> testRemoveKey [
self should: [ dict removeKey: #blah ] raise: KeyNotFound
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testRemoveKeyIfAbsentWithTransaction [


| tx tx2 tag |
tx := soil newTransaction.
tx root: dict.
dict at: 1 put: #one.
dict at: 2 put: #two.
"self assert: dict last equals: #two."
tx commit.
"open a second transaction ..."
tx2 := soil newTransaction.
"remove the key"
tx2 root removeKey: 2.
self assert: tx2 root size equals: 1.
"remove again to test absent case"
tag := false.
tx2 root removeKey: 3 ifAbsent: [ tag := true ].
self assert: tag.
"remove again to test absent case with already removed key"
tag := false.
tx2 root removeKey: 2 ifAbsent: [ tag := true ].
self assert: tag.


]

{ #category : #tests }
SoilIndexedDictionaryTest >> testSecond [
dict at: #foo put: #bar.
Expand Down
10 changes: 10 additions & 0 deletions src/Soil-Core/SoilBasicBTree.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ SoilBasicBTree >> at: aKeyObject put: anObject [

]

{ #category : #accessing }
SoilBasicBTree >> atIndex: anInteger [
| current iterator |
iterator := self newIterator.
current := iterator first.
2 to: anInteger do: [ :idx |
current := iterator next ].
^ current value
]

{ #category : #'open/close' }
SoilBasicBTree >> close [
self store close
Expand Down
5 changes: 5 additions & 0 deletions src/Soil-Core/SoilIndexIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ SoilIndexIterator class >> on: aSoilIndex [
index: aSoilIndex
]

{ #category : #accessing }
SoilIndexIterator >> at: aKeyObject [
^ self at: aKeyObject ifAbsent: [ KeyNotFound signalFor: aKeyObject in: self ]
]

{ #category : #accessing }
SoilIndexIterator >> at: aKeyObject ifAbsent: aBlock [
^ self subclassResponsibility
Expand Down
8 changes: 3 additions & 5 deletions src/Soil-Core/SoilIndexedDictionary.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ SoilIndexedDictionary >> do: aBlock [
iterator: iterator) ifNotNil: [ :objectId |
aBlock value: (transaction proxyForObjectId: objectId) ] ] ]
ifNil: [
newValues valuesDo: [ :each |
aBlock value: (each isObjectId
ifTrue: [ transaction proxyForObjectId: each ]
ifFalse: [ each ]) ] ]
newValues valuesDo: [ :each | aBlock value: each ] ]
]

{ #category : #accessing }
Expand Down Expand Up @@ -317,7 +314,8 @@ SoilIndexedDictionary >> removeKey: key ifAbsent: aBlock [
newValues removeKey: key ifAbsent: nil.
transaction markDirty: self.
iterator := self index newIterator.
v := iterator at: key ifAbsent: [ Error signal ].
v := iterator at: key ifAbsent: [^ aBlock value ].
v isRemoved ifTrue: [ ^ aBlock value ].
removedValues
at: key
put: v asSoilObjectId.
Expand Down
11 changes: 9 additions & 2 deletions src/Soil-Serializer/SoilPersistentDictionary.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,16 @@ SoilPersistentDictionary >> postCopy [
]

{ #category : #forwarded }
SoilPersistentDictionary >> removeKey: anObject [
SoilPersistentDictionary >> removeKey: key [
^ self
removeKey: key
ifAbsent: [ KeyNotFound signalFor: key in: self ]
]

{ #category : #forwarded }
SoilPersistentDictionary >> removeKey: anObject ifAbsent: aBlock [
| return |
return := dict removeKey: anObject.
return := dict removeKey: anObject ifAbsent: aBlock.
transaction markDirty: self.
^return
]
Expand Down
Loading