Skip to content

Commit

Permalink
Added test cases for subtraction between scalars and vectors and sugg…
Browse files Browse the repository at this point in the history
…ested quickfix (PolyMathOrg#121)

* Added Basic Scalar subtraction test

* added test for subtract PMVector from a Number

* QuickFix of the scalar subtraction with PMVector Issue
  • Loading branch information
nikhilpinnaparaju authored and SergeStinckwich committed May 29, 2019
1 parent aaad4b2 commit 7d2ef9f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
16 changes: 4 additions & 12 deletions src/Math-Core/PMVector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Class {
#name : #PMVector,
#superclass : #Array,
#type : #variable,
#category : #'Math-Core'
#category : 'Math-Core'
}

{ #category : #'instance creation' }
Expand Down Expand Up @@ -70,17 +70,9 @@ PMVector >> + aVectorOrNumber [
]

{ #category : #operation }
PMVector >> - aVector [
"Answers the difference of the receiver with aVector."
| answer n |
answer := self class new: self size.
n := 0.
self with: aVector do:
[ :a :b |
n := n + 1.
answer at: n put: ( a - b).
].
^answer
PMVector >> - aVectorOrNumber [
"Answers the difference of the receiver with a vector or number."
^ -1*aVectorOrNumber addWithVector: self
]

{ #category : #operation }
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Core/PMWeightedPoint.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Class {
'weight',
'error'
],
#category : #'Math-Core'
#category : 'Math-Core'
}

{ #category : #creation }
Expand Down
30 changes: 30 additions & 0 deletions src/Math-Tests-Core/PMVectorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,36 @@ PMVectorTest >> testScalarProductIsCommutative [
self assert: (u scalarProduct: v) equals: (v scalarProduct: u)
]

{ #category : #tests }
PMVectorTest >> testSubFromScalar [
"Can we subtract PMVector from a Number?"

| num vec actual expected |

num := 4.
vec := #(1 2 3) asPMVector.

actual := num - vec.
expected := #(3 2 1) asPMVector.

self assert: actual equals: expected.
]

{ #category : #tests }
PMVectorTest >> testSubtractScalar [
"Can we subtract Number from PMVector?"

| vec num actual expected |

vec := #(5 6 7) asPMVector.
num := 4.

actual := vec - num.
expected := #(1 2 3) asPMVector.

self assert: actual equals: expected.
]

{ #category : #tests }
PMVectorTest >> testTensorProduct [
| a b c |
Expand Down

0 comments on commit 7d2ef9f

Please sign in to comment.