[Cuis-dev] Testing morph collisions
Ezequiel Birman
ebirman77 at gmail.com
Mon Dec 23 14:08:51 PST 2024
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/20241223/68ddd70e/attachment.htm>
More information about the Cuis-dev
mailing list