From 6f9b216b96f3a0d4e6a086f882371d8472d8c0fd Mon Sep 17 00:00:00 2001 From: Atharva Khare Date: Sun, 26 May 2019 11:33:27 +0530 Subject: [PATCH] [#122] Fix PMVector comparison operators - Also added relevant tests for the operators --- src/Math-Core/PMVector.class.st | 10 +++++----- src/Math-Core/PMWeightedPoint.class.st | 2 +- src/Math-Tests-Core/PMVectorTest.class.st | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Math-Core/PMVector.class.st b/src/Math-Core/PMVector.class.st index 9a015f0ee..d22466db4 100644 --- a/src/Math-Core/PMVector.class.st +++ b/src/Math-Core/PMVector.class.st @@ -20,7 +20,7 @@ Class { #name : #PMVector, #superclass : #Array, #type : #variable, - #category : #'Math-Core' + #category : 'Math-Core' } { #category : #'instance creation' } @@ -85,14 +85,14 @@ PMVector >> - aVector [ { #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 } diff --git a/src/Math-Core/PMWeightedPoint.class.st b/src/Math-Core/PMWeightedPoint.class.st index 68a6f6146..a7beea989 100644 --- a/src/Math-Core/PMWeightedPoint.class.st +++ b/src/Math-Core/PMWeightedPoint.class.st @@ -12,7 +12,7 @@ Class { 'weight', 'error' ], - #category : #'Math-Core' + #category : 'Math-Core' } { #category : #creation } diff --git a/src/Math-Tests-Core/PMVectorTest.class.st b/src/Math-Tests-Core/PMVectorTest.class.st index 082e82fe0..868d5f1b8 100644 --- a/src/Math-Tests-Core/PMVectorTest.class.st +++ b/src/Math-Tests-Core/PMVectorTest.class.st @@ -59,6 +59,26 @@ PMVectorTest >> testAsArray [ self assert: #(1 2 3 4) asPMVector asArray equals: #(1 2 3 4) ] +{ #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 >> testScalarProduct [ | u v |