Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#122] Fix PMVector comparison operators #123

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Math-Core/PMVector.class.st
Expand Up @@ -77,14 +77,14 @@ PMVector >> - aVectorOrNumber [

{ #category : #operation }
PMVector >> < aNumber [
"Apply < operator to every element of a vector"
1 to: self size do: [ :n | self at: n put: (self at: n) < aNumber].
"Apply < operator to every element of a vector and returns a new vector"
^ ((1 to: self size) collect: [ :n | (self at: n) < aNumber]) asPMVector.
]

{ #category : #operation }
PMVector >> > aNumber [
"Apply > function to every element of a vector"
1 to: self size do: [ :n | self at: n put: (self at: n) > aNumber].
"Apply > function to every element of a vector and return a new vector"
^ ((1 to: self size) collect: [ :n | (self at: n) > aNumber]) asPMVector.
]

{ #category : #transformation }
Expand Down
20 changes: 20 additions & 0 deletions src/Math-Tests-Core/PMVectorTest.class.st
Expand Up @@ -60,6 +60,26 @@ PMVectorTest >> testAsArray [
]

{ #category : #tests }
PMVectorTest >> testGreaterThan [
| vec vecCopy |
vec := #(1 2 3) asPMVector.
vecCopy := vec deepCopy.
self assert: (vec > 1.5) equals: #(false true true) asPMVector.
"Ensure that in-place modification does not take place"
self assert: vec equals: vecCopy asPMVector.
]

{ #category : #tests }
PMVectorTest >> testLessThan [
| vec vecCopy |
vec := #(1 2 3) asPMVector.
vecCopy := vec deepCopy.
self assert: (vec < 1.5) equals: #(true false false) asPMVector.
"Ensure that in-place modification does not take place"
self assert: vec equals: vecCopy asPMVector.
]

{ #category : #tests }
PMVectorTest >> testMatrixConversionWithBothDims [
| vect result expected |
vect := #(1 0.5 0.2 3 1 -1 7 3 2 12 13 3) asPMVector .
Expand Down