Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 1.33 KB

level-3.md

File metadata and controls

22 lines (16 loc) · 1.33 KB

Level 3: Rotating tetrominoes

Previously we figured out a way to rotate 3×3 and 5×5 block shapes. Now with the help of that, it should be easier to implement rotating tetrominoes.

Open the test/RotatingTetrominoes.test.mjs file and implement its tests one by one.

The Tetromino class is meant to be immutable.

There are tests only for the T, I and O tetrominoes, because that's enough to drive the implementation (4, 2 and 1 orientations). You may test the rest of the tetrominoes yourself if you want, but if you create a design where the different shapes are just declarative configuration and their tests would just duplicate what the configuration already says, then you can have fewer tests.

P.S. You might be tempted to make Tetromino inherit RotatingShape, but it's better to favor composition over inheritance, to avoid the tight coupling between a subclass and its superclass. There's also the Liskov Substitution Principle which every inheritor should follow to avoid breaking things.