Skip to content

Commit 8f2eea0

Browse files
committed
Implemented add:atKey: message for DataSeries
1 parent a50dddb commit 8f2eea0

File tree

7 files changed

+55
-16
lines changed

7 files changed

+55
-16
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
adding
2+
add: aValue atKey: aKey
3+
4+
contents add: aValue.
5+
keys := keys copyWith: aKey.
6+
self induceTypeWithNewElement: aValue.
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
accessing
2-
at: aNumber put: value
2+
at: aNumber put: aValue
33

4-
contents at: aNumber put: value.
5-
6-
self type isNil
7-
"In case we fill the empty series with elements (e.g. collect)"
8-
ifTrue: [ type := value class ]
9-
10-
"In case we add an element to the existing series"
11-
ifFalse: [
12-
| inductor |
13-
inductor := DataTypeInductor new.
14-
type := inductor
15-
leastCommonSuperclassOf: value class
16-
and: self type. ].
4+
contents at: aNumber put: aValue.
5+
self induceTypeWithNewElement: aValue.

DataFrame-Core.package/DataSeries.class/instance/atKey.put..st

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ atKey: aKey put: aValue
77
index = 0
88
"a key was not found - create a new element"
99
ifTrue: [
10-
keys := keys copyWith: aKey.
11-
contents add: aValue ]
10+
self add: aValue atKey: aKey ]
1211
"a key was found - update the value"
1312
ifFalse: [
1413
self at: index put: aValue ].
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
as yet unclassified
2+
induceTypeWithNewElement: aValue
3+
"Induces type of series given that the new element was added to it"
4+
5+
self type isNil
6+
"In case we fill the empty series with elements (e.g. collect)"
7+
ifTrue: [ type := aValue class ]
8+
9+
"In case we add an element to the existing series"
10+
ifFalse: [
11+
type := DataTypeInductor new
12+
leastCommonSuperclassOf: aValue class
13+
and: self type. ].
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests
2+
testAddAtKey
3+
4+
| expected |
5+
6+
series add: -2 atKey: #X.
7+
expected := #(10 20 30 40 50 60 70 80 90 100 -2) asDataSeries.
8+
expected keys: ((1 to: 10) copyWith: #X).
9+
expected name: series name.
10+
11+
self assert: series equals: expected.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests
2+
testAtKeyPut
3+
4+
| expected |
5+
6+
series atKey: 6 put: -2.
7+
expected := #(10 20 30 40 50 -2 70 80 90 100) asDataSeries.
8+
expected name: series name.
9+
10+
self assert: series equals: expected.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests
2+
testAtKeyPutNewElement
3+
4+
| expected |
5+
6+
series atKey: #X put: -2.
7+
expected := #(10 20 30 40 50 60 70 80 90 100 -2) asDataSeries.
8+
expected keys: ((1 to: 10) copyWith: #X).
9+
expected name: series name.
10+
11+
self assert: series equals: expected.

0 commit comments

Comments
 (0)