File tree Expand file tree Collapse file tree 3 files changed +41
-18
lines changed
Expand file tree Collapse file tree 3 files changed +41
-18
lines changed Original file line number Diff line number Diff line change 1+ Extension { #name : #ArrayedCollection }
2+
3+ { #category : #' *Math-Core' }
4+ ArrayedCollection >> addWithVector: aVector [
5+ " Answers the sum of the receiver with aVector."
6+ | answer n |
7+ answer := self class new : self size.
8+ n := 0 .
9+ self with: aVector do:
10+ [ :a :b |
11+ n := n + 1 .
12+ answer at: n put: ( a + b).
13+ ].
14+ ^ answer
15+ ]
Original file line number Diff line number Diff line change @@ -113,20 +113,6 @@ PMVector >> accumulateNegated: aVectorOrAnArray [
113113 1 to: self size do: [ :n | self at: n put: ((self at: n) - (aVectorOrAnArray at: n))].
114114]
115115
116- { #category : #operation }
117- PMVector >> addWithVector: aVector [
118- " Answers the sum of the receiver with aVector."
119- | answer n |
120- answer := self class new : self size.
121- n := 0 .
122- self with: aVector do:
123- [ :a :b |
124- n := n + 1 .
125- answer at: n put: ( a + b).
126- ].
127- ^ answer
128- ]
129-
130116{ #category : #converting }
131117PMVector >> asArray [
132118
Original file line number Diff line number Diff line change @@ -6,10 +6,32 @@ Class {
66
77{ #category : #tests }
88PMVectorTest >> testAddScalar [
9- | u |
10- u := #(1 2 3) asPMVector.
11- self assert: u + 2 equals: #(3 4 5) asPMVector.
12- self assert: 2 + u equals: #(3 4 5) asPMVector.
9+ " Can we add Number to PMVector?"
10+
11+ | vec num actual expected |
12+
13+ vec := #(1 2 3) asPMVector.
14+ num := 4 .
15+
16+ actual := vec + num.
17+ expected := #(5 6 7) asPMVector.
18+
19+ self assert: actual equals: expected.
20+ ]
21+
22+ { #category : #tests }
23+ PMVectorTest >> testAddToScalar [
24+ " Can we add PMVector to Number?"
25+
26+ | num vec actual expected |
27+
28+ num := 4 .
29+ vec := #(1 2 3) asPMVector.
30+
31+ actual := num + vec.
32+ expected := #(5 6 7) asPMVector.
33+
34+ self assert: actual equals: expected.
1335]
1436
1537{ #category : #tests }
You can’t perform that action at this time.
0 commit comments