On Apr 1, 2010, at 8:50 AM, Hilaire Fernandes wrote:

> Stéphane Ducasse a écrit :
>> On Mar 31, 2010, at 5:38 PM, Hilaire Fernandes wrote:
>>> I wrote two tests on the ArrayTest collection to test #sorted and #sorted:
>>> #sorted broke, it is easy to fix.
>>> 
>>> I guess we need to write these tests for the whole CollectionTest 
>>> hierarchy.  I noted there is a CollectionRootTest using trait, however when 
>>> looking at the asSortedCollection tests, it is reapeatly written for almost 
>>> each classes of the hierarchy, and not in the CollectionRootTest using 
>>> inheritance mechanism.
>>> Any reason for that?
>> Hilaire you should read the paper on traits.
> 
> pointer on *one* good tutorial? I think I already read something. A small 
> memento on the syntax to define and to use trait will be enough to get 
> started comfortably. If there are such a things I suggest we add it in good 
> place in the pharo web site (along a paper on unit test); these features are 
> essential parts -- features -- of Pharo, so why not emphasis it.


this is on my todo for the next book but well other people could help...


> Btw, it would be a nice idea to convert an html version of the Pharo by 
> example book, so we can have direct pointer to chapter from the pharo web 
> site. It should be doable with latex2html. In the past I used hyperlatex to 
> produce both nice html and pdf version of DrGeo manual 
> (http://documentation.ofset.org/drgeo/fr/drgenius_51.html)

I do not have time for that.

> Probably sorted does not make sense on all collection so we define a trait 
> and apply it when needed.
> 
> Yes. What about writing like bellow? Is it acceptable or is it cumbersome?
> 
> 
> testSorted
>       self unsortedCollection ifNotNil: [self assert: ....]
> 
> 
> Matrix>>unosrtedCollection
> ^ nil
> 
> Arary>>unosrtedCollection
> ^ #(5 9 1 3 2)

Yes the idea is that you define a couple of methods in your testTraits

        testNilSorted
        testSorted
        testSortedWithDuplicates
        testAlreadySorted
        testSortedCollectionIsANewCollection

they will rely on different accessors

        testNilSorted
        
                self assert: self emptyCollection sorted isEmpty


ArrayTest
        uses: TSorted


and since emptyCollection is already defined you are done.

Now if you have 
        
testSorted
        
        self assert: self aNonEmptyCollection sorted = self sortedCollection

ArrayTest>>     aNonEmptyCollection
        ^ #(3 6 1 20 -3)

ArrayTest>>     sortedCollection
        ^ #(-3 1 3 6 20)
        
Stef



> 
> 
>> Traits are simple, just have a look. I did a presentation at esug about them.
> 
> 
> 
> _______________________________________________
> Pharo-project mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to