Section 5

We still have one failing unit test.

Here's the unit test method that is failing.

testCellOffsetCalculations
    | grid form cellLoc cell renderer offset |
    grid := GridFactory demoGrid.
    form := Form extent: (LaserGame boardExtentFor: grid) depth: Display depth.
    form fillColor: (Color r: 0.820 g: 0.820 b: 0.820).

    cellLoc := 1@1.
    cell := grid at: cellLoc.
    renderer := CellRenderer rendererFor: cell grid: grid form: form.
    offset := renderer offsetWithinGridForm.
    self should: [offset = (0@0)].

    cellLoc := 2@1.
    cell := grid at: cellLoc.
    renderer := CellRenderer rendererFor: cell grid: grid form: form.
    offset := renderer offsetWithinGridForm.
    self should: [offset = (30@0)].

    cellLoc := 1@2.
    cell := grid at: cellLoc.
    renderer := CellRenderer rendererFor: cell grid: grid form: form.
    offset := renderer offsetWithinGridForm.
    self should: [offset = (0@30)].

    cellLoc := 2@2.
    cell := grid at: cellLoc.
    renderer := CellRenderer rendererFor: cell grid: grid form: form.
    offset := renderer offsetWithinGridForm.
    self should: [offset = (30@30)].

We're failing for cell location 2@1, expecting the offset to be 30@0. Instead we are getting 40@0. The actual returned result is correct. We need to change the test.

There's also a second failure later in the test for cell location 1@2, expecting an offset to be 0@30. Again, we should be getting 0@40 now and that's what the code is actually answering. We need to change this part of the test too.

There's a third and final failure in the test at cell location 2@2. Again, the actual returned result of 40@40 is correct. Here's the revised test method accounting for all three of these changes.

testCellOffsetCalculations
     | grid form cellLoc cell renderer offset |
     grid := GridFactory demoGrid.
     form := Form extent: (LaserGame boardExtentFor: grid) depth: Display depth.
     form fillColor: (Color r: 0.820 g: 0.820 b: 0.820).

     cellLoc := 1@1.
     cell := grid at: cellLoc.
     renderer := CellRenderer rendererFor: cell grid: grid form: form.
     offset := renderer offsetWithinGridForm.
     self should: [offset = (0@0)].

     cellLoc := 2@1.
     cell := grid at: cellLoc.
     renderer := CellRenderer rendererFor: cell grid: grid form: form.
     offset := renderer offsetWithinGridForm.
     self should: [offset = (40@0)].

     cellLoc := 1@2.
     cell := grid at: cellLoc.
     renderer := CellRenderer rendererFor: cell grid: grid form: form.
     offset := renderer offsetWithinGridForm.
     self should: [offset = (0@40)].

     cellLoc := 2@2.
     cell := grid at: cellLoc.
     renderer := CellRenderer rendererFor: cell grid: grid form: form.
     offset := renderer offsetWithinGridForm.
     self should: [offset = (40@40)].

After making this final code change, all the unit tests pass once again. We found a combination of test errors and a bug in the logic that decides which rotation region to select.

Save the code as version 11.

Index Page Next Page

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