582334 TDD-ohjelmointimenetelmä ja koodin suunnittelu (5 op), syksy 2009
582334 TDD programming technique and designing code (5 cr), autumn 2009

Kurssiesittely Luennot Harjoitukset

Exercise 3: Tetris #4-6 (own tests). Refactoring functions.

Tetris project work

See the instructions in the first exercise.

Homework

max 7 points

  1. Refactor the method filelocator.FileLocator#findFile(File,String) in this project so that its code will be self-documenting, its redability as good as possible and it won't anymore need comments. Print a couple of steps of your refactoring on paper so that the exercise would be easier to discuss at the exercise group.

    Instructions for refactoring methods you can get from the Clean Code book's chapters 3-5. Use good names and the Composed Method pattern:

    "Divide your program into methods that perform one identifiable task. Keep all of the operations in a method at the same level of abstraction. This will naturally result in programs with many small methods, each a few lines long."
    - Kent Beck, Smalltalk Best Practice Patterns
    http://codebetter.com/blogs/jeremy.miller/archive/2006/12/03/Composed-Method-Pattern.aspx
    http://www.ibm.com/developerworks/java/library/j-eaed4.html

    1 point: The variables have been named sensibly. All tests pass.
    2 points: The variables have been named sensibly and the methods have been split logically into smaller methods according to the Composed Method pattern. All tests pass.

  2. Tetris #4-6: Implement the test cases and code to pass FallingPiecesTest, MovingAFallingPieceTest and RotatingAFallingPieceTest using TDD. Continue your implementation from where you were left in the previous exercices. From now on, you have to write the necessary tests yourself. The test classes in this exercise have as TODO comments tips about what kinds of test cases are probably worth writing (decide for yourself, whether there is need for other kinds of tests).

    1 point: All previous tests pass and out of FallingPiecesTest's 5 tests 1 pass. This includes the necessary refactoring, so that the Board#drop method can take as parameters both Block and Tetrominoe objects.
    2 points: All previous tests pass and out of FallingPiecesTest's 5 tests 5 pass.
    3 points: All written tests pass and MovingAFallingPieceTest specifies the functionality: moving a piece in the game area left, right and down.
    4 points: All written tests pass and MovingAFallingPieceTest specifies the functionality: a piece can not be moved over the edges of the game area, nor through other pieces.
    5 points: All written tests pass and RotatingAFallingPieceTest specifies the functionality: (1) rotating a piece in the game area, (2) can not rotate if there is not enough space, (3) rotating a piece next to a wall/piece pushes the piece away from the wall if there is space on the other side ("wallkick").

In the exercise group we will discuss the Composed Method pattern, and pair program another piece rotation logic into Tetris. Replace the previous algorithmic rotation logic with a hard-coded rotation logic (the possible orientations of every tetris piece are hard-coded), which follows TGM's rotation rules. Remove all code which is not anymore needed because of this change. Compare the cleanliness of the code needed by the previous rotation logic and this new rotation logic: Was it worth it to make this change?


Viimeksi muokattu 01.12.2010 21:04 Copyright © 2009 Esko Luontola