[Cuis-dev] Testing morph collisions

Ezequiel Birman ebirman77 at gmail.com
Thu Mar 13 09:54:13 PDT 2025


After more tinkering, I can make the test pass without sending
*privateDisplayBounds:* It seems enough to write:

test02_BoundedUnopenedMorphCollides
>
> | m1 |
>
> m1 := Morph new.
>
> "Hack to avoid opening morphs in the world.`#collides:` relies on the
> morphs having a display bound, so we use `findFullBoundsInOwner` for its
> side-effects"
> "m1 setProperty: #fullBoundsInOwner toValue: m1 findFullBoundsInOwner."
> m1 findFullBoundsInOwner.
>
> self assert: (m1 collides: m1)


Any objections?

On Mon, 23 Dec 2024 at 22:08, Ezequiel Birman <ebirman77 at gmail.com> wrote:

> I've just realised that the code snippet I quoted in my previous message
> is missing the final part. Here it is in full:
>
> (UISupervisor animatedUIOf: Processor activeProcess)
>>  ifNotNil: [ :ui | ui doOneCycleNowOn: ui mainCanvas ]
>>   ifNil: [ | updated d |
>>     updated := false.
>>     d := Delay forMilliseconds: 10.
>>     UISupervisor whenUIinSafeState: [ UISupervisor whenUIinSafeState:
>> [updated := true ]].
>>     [updated] whileFalse: [
>>       d wait ]].
>
>
> To clarify comment/question (3) in my previous message, If I remove one of
> *whenUIinSafeState:* leaving the snippet as this:
>
>> (UISupervisor animatedUIOf: Processor activeProcess)
>>  ifNotNil: [ :ui | ui doOneCycleNowOn: ui mainCanvas ]
>>   ifNil: [ | updated d |
>>     updated := false.
>>     d := Delay forMilliseconds: 10.
>>     UISupervisor whenUIinSafeState: [updated := true ].
>>     [updated] whileFalse: [
>>       d wait ]].
>
> The LayoutMorph tests still pass.
>
> On Sat, 21 Dec 2024 at 22:32, Ezequiel Birman <ebirman77 at gmail.com> wrote:
>
>> Hi! I am revisiting the *Spacewar!* exercise from The Cuis Smalltalk
>> Book, and I am testing things that deal with morph collisions.
>>
>> The *LayoutMorphTest* tests in BaseImageTests insert clever code before
>> the assertions, to ensure things happen orderly:
>>
>>> (UISupervisor animatedUIOf: Processor activeProcess)
>>>   ifNotNil: [ :ui | ui doOneCycleNowOn: ui mainCanvas ]
>>>   ifNil: [ | updated d |
>>>     updated := false.
>>>     d := Delay forMilliseconds: 10.
>>>     UISupervisor whenUIinSafeState: [ UISupervisor whenUIinSafeState: [
>>> updated := true ]].
>>
>>
>> Since I don't need (or I can't see the need) for my tests to display
>> morphs on the screen, and since *Morph>>collides:* relies on the morphs
>> having a display bound, in my tests it was enough to insert
>>
>>> space privateDisplayBounds: space fullBoundsInOwner
>>
>> before the assertions, where *space* owns the colliding morphs in the
>> test; and since I don't display things on screen, test runs feel snappier.
>>
>> 1) The thing I'm doing with *privateDisplayBounds:* will it come back
>> to bite me?
>> 2) Is it better, for some definition of better, for morphic tests to
>> display morphs on screen while they run?
>> 3) I don't understand the need for the nesting in *UISupervisor
>> whenUIinSafeState: [ UISupervisor whenUIinSafeState: [ updated := true ]]*,
>> I removed the outer level and the LayoutMorph tests still pass. Maybe by
>> chance? Things are hard to debug when they behave differently when
>> debugging.
>> 4) Can you imagine another way of writing these kinds of tests?
>>
>> I attached a couple of simple examples so you don't have to type them.
>>
>> --
>> Eze
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250313/744be515/attachment-0001.htm>


More information about the Cuis-dev mailing list