Skip to content

Commit ee8345e

Browse files
committed
Moved addWithVector: from PMVector to ArrayedCollection
1 parent 2b52f11 commit ee8345e

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
]

src/Math-Core/PMVector.class.st

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff 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 }
131117
PMVector >> asArray [
132118

src/Math-Tests-DHB-Numerical/PMVectorTest.class.st

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,32 @@ Class {
66

77
{ #category : #tests }
88
PMVectorTest >> 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 }

0 commit comments

Comments
 (0)