Collection>>sortedAs:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Collection>>sortedAs:

abergel
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
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.





_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
cbc
Reply | Threaded
Open this post in threaded view
|

Re: Collection>>sortedAs:

cbc
On Wed, Sep 28, 2011 at 6:32 AM, Alexandre Bergel
<[hidden email]> 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
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Collection>>sortedAs:

abergel
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 <[hidden email]> wrote:

> On Wed, Sep 28, 2011 at 6:32 AM, Alexandre Bergel
> <[hidden email]> 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
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev