Section 5

We can now apply the same technique to the other test case. Here are our previous notes for CellClickOutsideRegionRotateTestCase.

Label Point Rotate
A 10@10 Clock Wise
B 30@10 Clock Wise
C 10@20 Clock Wise
D 30@20 Clock Wise
E 10@30 Counter Clock Wise
F 30@30 Counter Clock Wise
G 4@4 Clock Wise
H 36@4 Clock Wise
I 4@20 Clock Wise
J 36@20 Clock Wise
K 4@36 Counter Clock Wise
L 36@36 Counter Clock Wise
M 6@10 Clock Wise
N 32@18 Clock Wise
O 12@32 Counter Clock Wise

The existing method.

testClicksInRotateRegions
    | pt regionClass testTable cls rotateRegion |
    pt := 5@5.
    regionClass := CellClickRegion clickRegionForPoint: pt.
    self should: [regionClass = CellClickRegionOutside].
    testTable := {
        10@10->CellClickRegionRotateClockwise.
        30@10->CellClickRegionRotateClockwise.
        10@20->CellClickRegionRotateClockwise.
        30@20->CellClickRegionRotateClockwise.
        10@30->CellClickRegionRotateCounterClockwise.
        30@30->CellClickRegionRotateCounterClockwise.
        4@4->CellClickRegionRotateClockwise.
        36@4->CellClickRegionRotateClockwise.
        4@20->CellClickRegionRotateClockwise.
        36@20->CellClickRegionRotateClockwise.
        4@36->CellClickRegionRotateCounterClockwise.
        36@36->CellClickRegionRotateCounterClockwise.
        6@10->CellClickRegionRotateClockwise.
        32@18->CellClickRegionRotateClockwise.
        12@32->CellClickRegionRotateCounterClockwise.
        }.
    testTable do: [:assoc |
        pt := assoc key.
        cls := assoc value.
        rotateRegion := regionClass rotateRegionForPoint: pt.
        self should: [rotateRegion = cls]]

We'll do the same thing we did for the "inside" region. One big difference however is that we will need both the inside and outside region rectangles. I'll call them "outRect" and "inRect".

Label Point Rotate
A inRect topLeft Clock Wise
B inRect topRight Clock Wise
C inRect leftCenter Clock Wise
D inRect rightCenter Clock Wise
E inRect bottomLeft Counter Clock Wise
F inRect bottomRight Counter Clock Wise
G outRect topLeft Clock Wise
H outRect topRight Clock Wise
I outRect leftCenter Clock Wise
J outRect rightCenter Clock Wise
K outRect bottomCenter Counter Clock Wise
L outRect bottomRight Counter Clock Wise
M (outRect topLeft x + 2)@(inRect topLeft y) Clock Wise
N inRect rightCenter + (2@-2) Clock Wise
O inRect bottomLeft + (2@2) Counter Clock Wise

The "M" test point was the only tricky one in the table. Again, it's easy to understand the test when the points are described this way. Let's modify the method.

testClicksInRotateRegions
    | pt regionClass testTable cls rotateRegion inRect outRect |
    inRect := CellClickRegionInside regionRectangle.
    outRect := CellClickRegionOutside regionRectangle.
    pt := outRect topLeft + (1@1).
    regionClass := CellClickRegion clickRegionForPoint: pt.
    self should: [regionClass = CellClickRegionOutside].
    testTable := {
        inRect topLeft                              ->CellClickRegionRotateClockwise.
        inRect topRight                             ->CellClickRegionRotateClockwise.
        inRect leftCenter                           ->CellClickRegionRotateClockwise.
        inRect rightCenter                          ->CellClickRegionRotateClockwise.
        inRect bottomLeft                           ->CellClickRegionRotateCounterClockwise.
        inRect bottomRight                          ->CellClickRegionRotateCounterClockwise.
        outRect topLeft                             ->CellClickRegionRotateClockwise.
        outRect topRight                            ->CellClickRegionRotateClockwise.
        outRect leftCenter                          ->CellClickRegionRotateClockwise.
        outRect rightCenter                         ->CellClickRegionRotateClockwise.
        outRect bottomCenter                        ->CellClickRegionRotateCounterClockwise.
        outRect bottomRight                         ->CellClickRegionRotateCounterClockwise.
        (outRect topLeft x + 2)@(inRect topLeft y)  ->CellClickRegionRotateClockwise.
        inRect rightCenter + (2@-2)                 ->CellClickRegionRotateClockwise.
        inRect bottomLeft + (2@2)                   ->CellClickRegionRotateCounterClockwise.
        }.
    testTable do: [:assoc |
        pt := assoc key.
        cls := assoc value.
        rotateRegion := regionClass rotateRegionForPoint: pt.
        self should: [rotateRegion = cls]]

Once again when we run the unit tests they still pass. This change works fine.

Index Page Next Page

Copyright © 2007, 2008, 2009, 2010 Stephan B Wessels    stevewessels@me.com