From 920434646002044794ea7168a32827748f41ceab Mon Sep 17 00:00:00 2001 From: Marcus Denker Date: Thu, 12 Oct 2023 17:23:28 +0200 Subject: [PATCH] improve code coverage, especially partially covered methods --- src/Soil-Core-Tests/SoilBTreeTest.class.st | 5 +- .../SoilIndexedDictionaryTest.class.st | 120 +++++++++++++++++- src/Soil-Core-Tests/SoilSkipListTest.class.st | 11 ++ 3 files changed, 128 insertions(+), 8 deletions(-) diff --git a/src/Soil-Core-Tests/SoilBTreeTest.class.st b/src/Soil-Core-Tests/SoilBTreeTest.class.st index e8d40e8d..e4e8fd3e 100644 --- a/src/Soil-Core-Tests/SoilBTreeTest.class.st +++ b/src/Soil-Core-Tests/SoilBTreeTest.class.st @@ -322,9 +322,8 @@ SoilBTreeTest >> testRemoveKey [ self assert: (btree at: 1) equals: #[ 1 2 3 4 5 6 7 8 ]. self assert: (btree at: capacity) equals: #[ 1 2 3 4 5 6 7 8 ]. - self should: [ btree at: 20 ] raise: KeyNotFound. - btree at: 20 put: #[ 1 2 3 4 5 6 7 8 ]. - self assert: (btree at: 20) equals: #[ 1 2 3 4 5 6 7 8 ]. + self should: [ btree at: 20 ] raise: KeyNotFound. + self should: [ btree removeKey: 20 ] raise: KeyNotFound. ] { #category : #tests } diff --git a/src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st b/src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st index 85eb1c7a..2909d9cc 100644 --- a/src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st +++ b/src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st @@ -148,15 +148,41 @@ SoilIndexedDictionaryTest >> testAddToNewList [ ] { #category : #tests } -SoilIndexedDictionaryTest >> testFirst [ +SoilIndexedDictionaryTest >> testAt [ + dict at: #foo2 put: #bar2. + dict at: #foo put: #bar. + + self assert: (dict at: #foo2) equals: #bar2. + self should: [dict at: #ff] raise: KeyNotFound +] + +{ #category : #tests } +SoilIndexedDictionaryTest >> testAtIndex [ dict at: #foo2 put: #bar2. dict at: #foo put: #bar. + self assert: (dict atIndex: 1) equals: #bar2 +] +{ #category : #tests } +SoilIndexedDictionaryTest >> testFirst [ + dict at: #foo2 put: #bar2. + dict at: #foo put: #bar. + + "first in key order" self assert: dict first equals: #bar. self assert: (dict first: 1) first equals: #bar. ] +{ #category : #tests } +SoilIndexedDictionaryTest >> testFirstAssociation [ + dict at: #foo2 put: #bar2. + dict at: #foo put: #bar. + + "firstAssocation in key order" + self assert: dict firstAssociation equals: #foo->#bar. +] + { #category : #tests } SoilIndexedDictionaryTest >> testFirstAssociationWithSingleRemovedItem [ @@ -165,6 +191,22 @@ SoilIndexedDictionaryTest >> testFirstAssociationWithSingleRemovedItem [ self assert: dict firstAssociation equals: nil ] +{ #category : #tests } +SoilIndexedDictionaryTest >> testFirstAssociationWithTransaction [ + | tx tx2 | + 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. + "and test last" + self assert: tx2 root firstAssociation equals: 1->#one. + +] + { #category : #tests } SoilIndexedDictionaryTest >> testFirstWithSingleRemovedItem [ @@ -199,12 +241,22 @@ SoilIndexedDictionaryTest >> testIsEmpty [ { #category : #tests } SoilIndexedDictionaryTest >> testLast [ - dict at: #foo put: #bar. dict at: #foo2 put: #bar2. - + dict at: #foo put: #bar. + + "last in key order" self assert: dict last equals: #bar2 ] +{ #category : #tests } +SoilIndexedDictionaryTest >> testLastAssociation [ + dict at: #foo2 put: #bar2. + dict at: #foo put: #bar. + + "last association in key order" + self assert: dict lastAssociation equals: #foo2->#bar2 +] + { #category : #tests } SoilIndexedDictionaryTest >> testLastAssociationWithSingleRemovedItem [ dict at: #foo put: #bar. @@ -212,6 +264,22 @@ SoilIndexedDictionaryTest >> testLastAssociationWithSingleRemovedItem [ self assert: dict lastAssociation equals: nil ] +{ #category : #tests } +SoilIndexedDictionaryTest >> testLastAssociationWithTransaction [ + | tx tx2 | + tx := soil newTransaction. + tx root: dict. + dict at: 2 put: #two. + dict at: 1 put: #one. + + "self assert: dict last equals: #two." + tx commit. + "open a second transaction ..." + tx2 := soil newTransaction. + "and test last, not: key order" + self assert: tx2 root lastAssociation equals: 2->#two +] + { #category : #tests } SoilIndexedDictionaryTest >> testLastWithSingleRemovedItem [ dict at: #foo put: #bar. @@ -224,13 +292,14 @@ SoilIndexedDictionaryTest >> testLastWithTransaction [ | tx tx2 | tx := soil newTransaction. tx root: dict. - dict at: 1 put: #one. dict at: 2 put: #two. + dict at: 1 put: #one. + "self assert: dict last equals: #two." tx commit. "open a second transaction ..." tx2 := soil newTransaction. - "and test last" + "and test last, note: keyorder" self assert: tx2 root last equals: #two ] @@ -273,6 +342,17 @@ SoilIndexedDictionaryTest >> testNextAfterWithTransaction [ self assert: (tx2 root nextAfter: 1) value equals: #two ] +{ #category : #tests } +SoilIndexedDictionaryTest >> testRemoveKey [ + dict at: #foo put: #bar. + dict at: #foo2 put: #bar2. + + dict removeKey: #foo. + self assert: dict size equals: 1. + + self should: [ dict removeKey: #blah ] raise: KeyNotFound +] + { #category : #tests } SoilIndexedDictionaryTest >> testSecond [ dict at: #foo put: #bar. @@ -281,6 +361,21 @@ SoilIndexedDictionaryTest >> testSecond [ self assert: dict second equals: #bar2 ] +{ #category : #tests } +SoilIndexedDictionaryTest >> testSecondWithTransaction [ + | tx tx2 | + 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. + "and test last" + self assert: tx2 root second equals: #two +] + { #category : #tests } SoilIndexedDictionaryTest >> testSize [ dict at: #foo put: #bar. @@ -289,6 +384,21 @@ SoilIndexedDictionaryTest >> testSize [ self assert: dict size equals: 2 ] +{ #category : #tests } +SoilIndexedDictionaryTest >> testSizeWithTransaction [ + | tx tx2 | + 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. + "and test last" + self assert: tx2 root size equals: 2 +] + { #category : #tests } SoilIndexedDictionaryTest >> testValues [ dict at: #foo put: #bar. diff --git a/src/Soil-Core-Tests/SoilSkipListTest.class.st b/src/Soil-Core-Tests/SoilSkipListTest.class.st index 7832bb55..8622126d 100644 --- a/src/Soil-Core-Tests/SoilSkipListTest.class.st +++ b/src/Soil-Core-Tests/SoilSkipListTest.class.st @@ -225,6 +225,15 @@ SoilSkipListTest >> testFirst [ self assert: (skipList first: 2) second equals: #[ 1 2 3 4 5 6 7 8 ]. ] +{ #category : #tests } +SoilSkipListTest >> testFirstArgLargerThenSize [ + + 1 to: 4 do: [ :n | + skipList at: n put: #[ 1 2 3 4 5 6 7 8 ] ]. + self assert: skipList pages size equals: 1. + self assert: (skipList first: 5) size equals: 4 +] + { #category : #tests } SoilSkipListTest >> testIsEmpty [ self assert: skipList isEmpty. @@ -384,6 +393,8 @@ SoilSkipListTest >> testRemoveKey [ self should: [ skipList at: 20 ] raise: KeyNotFound. skipList at: 20 put: #[ 1 2 3 4 5 6 7 8 ]. self assert: (skipList at: 20) equals: #[ 1 2 3 4 5 6 7 8 ]. + + self should: [ skipList removeKey: capacity + 1 ] raise: KeyNotFound ] { #category : #tests }