[Cuis-dev] [Integrated] Re: Fix for SequentiableCollection>>combinations:atATimeDo:

Luciano Notarfrancesco luchiano at gmail.com
Sat May 25 11:19:03 PDT 2019


Hi Hernan,
Thanks for integrating! Next time I should provide tests...
Yes, it is expected behavior, it was made like that in order to enumerate
combinations as fast as possible without stressing the GC (I wonder how
much difference does it make nowadays, tho). I thought that the name
'atATimeDo' was a remainder that the array is being reused in each
iteration, but actually groupsOf:atATimeDo: doesn't reuse the array, and
permutationsDo: reuses the array. IMHO groupsOf:do: and combinationsOf:do:
would be nicer names, but not a big deal.


On Sat, May 25, 2019 at 1:06 PM Hernan Wilkinson <
hernan.wilkinson at 10pines.com> wrote:

> Hi Luciano,
>  thank you for the fix. It is integrated now and I added a couple of tests
> to SequenceableCollectionTest, one when k is cero and another for the
> normal case.
>
>  When I wrote the test for the normal case I notice that the collection
> passed as parameter to the block it is always the name and therefore the
> following test fails:
> testCombinationsAtATimeDoWorksAsExpected
>
> | combinations |
>
> combinations := OrderedCollection new.
> 'abc' combinations: 2 atATimeDo: [ :combination | combinations add:
> combination].
>
> self assert: 3 equals: combinations size.
> self assert: (combinations includes: #($a $b)).
> self assert: (combinations includes: #($a $c)).
> self assert: (combinations includes: #($b $c)).
>
> To make it pass I had to make a copy of combination.
> ...
> 'abc' combinations: 2 atATimeDo: [ :combination | combinations add:
> combination *copy*].
> ....
>
> Is that the expected behavior? It looks weird to me... I would expect
> combination to be different collections on each iteration...
>
> Cheers!
> Hernan.
>
> On Thu, May 23, 2019 at 1:13 PM Luciano Notarfrancesco via Cuis-dev <
> cuis-dev at lists.cuis.st> wrote:
>
>> The method was failing for the corner case of "combinations of 0
>> elements". Here's the fix.
>> --
>> Cuis-dev mailing list
>> Cuis-dev at lists.cuis.st
>> https://lists.cuis.st/mailman/listinfo/cuis-dev
>>
>
>
> --
>
> *HernĂ¡n WilkinsonAgile Software Development, Teaching & Coaching*
> *Phone: +54-011*-4893-2057
> *Twitter: @HernanWilkinson*
> *site: http://www.10Pines.com <http://www.10pines.com/>*
> Address: Alem 896, Floor 6, Buenos Aires, Argentina
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20190525/e9210865/attachment-0001.html>


More information about the Cuis-dev mailing list