Fwd: [SeasideSt/Grease] GRIntervalTest >> #testSorted assumes new collection (#95)

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

Fwd: [SeasideSt/Grease] GRIntervalTest >> #testSorted assumes new collection (#95)

Tobias Pape


Begin forwarded message:

From: Philippe Marschall <[hidden email]>
Subject: [SeasideSt/Grease] GRIntervalTest >> #testSorted assumes new collection (#95)
Date: 27. August 2019 um 14:55:35 MESZ
To: SeasideSt/Grease <[hidden email]>
Cc: Subscribed <[hidden email]>
Reply-To: SeasideSt/Grease <[hidden email]>
Delivered-To: [hidden email]

GRIntervalTest >> #testSorted assumes new a collection is returned. This is no longer true with the latest Squeak.


I just looked, all #sorted return a copy, except Interval:

"
sorted
"an Interval is already sorted"
step < 0 ifTrue: [^self reversed].
^self
"

Shouldn't that rather be this?

"
sorted
"an Interval is already sorted"
step < 0 ifTrue: [^self reversed].
^self copy
"


Best regards
-Tobias


Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [SeasideSt/Grease] GRIntervalTest >> #testSorted assumes new collection (#95)

Nicolas Cellier
But would we want to mutate an Interval???
I would consider an Interval as read-only and would lock the inst-vars just after setting if it were me, likewise for Point and some other species...

IMO, the test is wrong in this regard.
We should not expect that #sorted always answer a copy, if we don't need one.
What we should expect is that #sorted do NEVER mutate the receiver, which is a different thing, contrarily to #sort which should.
The test should rather assert that original is not mutated by original sorted...

Of course, if what we really want is a #sortedCopy behavior, then we can add this innocuous copy...
But IMO it is not necessary.

Le mar. 27 août 2019 à 15:04, Tobias Pape <[hidden email]> a écrit :


Begin forwarded message:

From: Philippe Marschall <[hidden email]>
Subject: [SeasideSt/Grease] GRIntervalTest >> #testSorted assumes new collection (#95)
Date: 27. August 2019 um 14:55:35 MESZ
To: SeasideSt/Grease <[hidden email]>
Cc: Subscribed <[hidden email]>
Reply-To: SeasideSt/Grease <[hidden email]>
Delivered-To: [hidden email]

GRIntervalTest >> #testSorted assumes new a collection is returned. This is no longer true with the latest Squeak.


I just looked, all #sorted return a copy, except Interval:

"
sorted
"an Interval is already sorted"
step < 0 ifTrue: [^self reversed].
^self
"

Shouldn't that rather be this?

"
sorted
"an Interval is already sorted"
step < 0 ifTrue: [^self reversed].
^self copy
"


Best regards
-Tobias



Reply | Threaded
Open this post in threaded view
|

Re: [SeasideSt/Grease] GRIntervalTest >> #testSorted assumes new collection (#95)

Tobias Pape

> On 27.08.2019, at 16:42, Nicolas Cellier <[hidden email]> wrote:
>
> But would we want to mutate an Interval???
> I would consider an Interval as read-only and would lock the inst-vars just after setting if it were me, likewise for Point and some other species...
>
> IMO, the test is wrong in this regard.
> We should not expect that #sorted always answer a copy, if we don't need one.
> What we should expect is that #sorted do NEVER mutate the receiver, which is a different thing, contrarily to #sort which should.
> The test should rather assert that original is not mutated by original sorted...
>
> Of course, if what we really want is a #sortedCopy behavior, then we can add this innocuous copy...
> But IMO it is not necessary.

Makes sense. Thank you :)

>
> Le mar. 27 août 2019 à 15:04, Tobias Pape <[hidden email]> a écrit :
>
>
>> Begin forwarded message:
>>
>> From: Philippe Marschall <[hidden email]>
>> Subject: [SeasideSt/Grease] GRIntervalTest >> #testSorted assumes new collection (#95)
>> Date: 27. August 2019 um 14:55:35 MESZ
>> To: SeasideSt/Grease <[hidden email]>
>> Cc: Subscribed <[hidden email]>
>> Reply-To: SeasideSt/Grease <[hidden email]>
>> Delivered-To: [hidden email]
>>
>> GRIntervalTest >> #testSorted assumes new a collection is returned. This is no longer true with the latest Squeak.
>>
>
> I just looked, all #sorted return a copy, except Interval:
>
> "
> sorted
> "an Interval is already sorted"
> step < 0 ifTrue: [^self reversed].
> ^self
> "
>
> Shouldn't that rather be this?
>
> "
> sorted
> "an Interval is already sorted"
> step < 0 ifTrue: [^self reversed].
> ^self copy
> "
>
>
> Best regards
> -Tobias
>
>