[Cuis-dev] Testing morph collisions

Ezequiel Birman ebirman77 at gmail.com
Sat Dec 21 14:32:23 PST 2024


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/20241221/7d088a3a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Collision-Test.st
Type: application/octet-stream
Size: 1145 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20241221/7d088a3a/attachment.obj>


More information about the Cuis-dev mailing list