Hi!
Mondrian has the method sortedAs:. Here is a test: testSortedAs
self assert: (#(5 4 3 2 1) sortedAs: #value) asArray = #(1 2 3 4 5). self assert: (#(5 4 3 2 1) sortedAs: #odd) asArray = #(5 1 3 4 2). self assert: (#(5 4 3 2 1) sortedAs: #even) asArray = #(2 4 3 5 1). self assert: (#(5 4 3 2 1) sortedAs: [:v1 :v2 | v1 < v2 ]) asArray = #(1 2 3 4 5).
self assert: (#(5 4 3 2 1) sortedAs: [:v | v * v ]) asArray = #(1 2 3 4 5). self assert: (#(5 4 3 2 1) sortedAs: #squared) asArray = #(1 2 3 4 5). self assert: (#(5 4 3 2 1) sortedAs: [:v | v negated ]) asArray = #(5 4 3 2 1).
sortedAs: takes as argument, one-arg block, two-arg block. I was wondering whether this method could not be part of Pharo.
Cheers, Alexandre
On Wed, Sep 28, 2011 at 6:32 AM, Alexandre Bergel alexandre.bergel@me.com wrote:
Hi!
Mondrian has the method sortedAs:. Here is a test:
self assert: (#(5 4 3 2 1) sortedAs: #odd) asArray = #(5 1 3 4 2).
That's an odd test. It obviously assumes a specific sorting mechanism behind the scenes to get the 5 3 1 resorted into 5 1 3 on the output. Is there a better to way test the results? Just that there isn't an odd before the even?
It just seems to me that if someone fiddles with the underlying sort mechanism, the ordering may turn out different - and still be right.
-Chris
It is true that there is an arbitrary sorting behind, but it hasn't bothered me so far.
Alexandre
On 28 Sep 2011, at 16:53, Chris Cunningham cunningham.cb@gmail.com wrote:
On Wed, Sep 28, 2011 at 6:32 AM, Alexandre Bergel alexandre.bergel@me.com wrote:
Hi!
Mondrian has the method sortedAs:. Here is a test:
self assert: (#(5 4 3 2 1) sortedAs: #odd) asArray = #(5 1 3 4 2).
That's an odd test. It obviously assumes a specific sorting mechanism behind the scenes to get the 5 3 1 resorted into 5 1 3 on the output. Is there a better to way test the results? Just that there isn't an odd before the even?
It just seems to me that if someone fiddles with the underlying sort mechanism, the ordering may turn out different - and still be right.
-Chris
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev