Hilaire
have a look at CollectionsTest there are really simple example of
traits.
In 5 minutes you should get that:
You have a trait TRemoveTest
Trait named: #TRemoveTest
uses: {}
category: 'CollectionsTests-Abstract'
easy
TRemoveTest>>testRemoveElementFromEmpty
"self debug: #testRemoveElementFromEmpty"
self should: [self empty remove: self nonEmpty anyOne] raise: Error
Easy
self empty is undefined and it will return an empty collection
self nonEmpty and nonEmpty one
testRemoveElementThatExists
"self debug: #testRemoveElementThatExists"
| el res |
el := self nonEmpty anyOne.
self shouldnt: [res := self nonEmpty remove: el ] raise: Error.
self assert: res == el
testRemoveElementReallyRemovesElement
"self debug: #testRemoveElementReallyRemovesElement"
| size |
size := self nonEmpty size.
self nonEmpty remove: self nonEmpty anyOne.
self assert: (size -1) = self nonEmpty size
OK now you use the trait in a class
For example
Object subclass: #MySetTest
uses: TRemoveTest
instanceVariableNames: 'full empty
You define
setUp
full := Set new add: 5 ; add: 6 ;yourself
empty := Set new.
nonEmpty
^ full
empty
^ empty
This is it!!!!!
You can reuse your traits in another Test.
Now if you do not like a trait method you can remove it or redefine it
in your class
DONE!!!
Stef
_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project