General
- Don’t use inheritance!
- Test ALL the methods (including initialize if applicable)
- Here’s an example that gives the whole thing away: TDD demo
- NB: The concepts are the same, but the syntax of minitest, minitest/spec and rspec are a little differenbt. I recommned minitest/spec
Instructions
- Develop the following simple program using Test Driven Development
- Meaning, write the tests FIRST and then write the classes
- You may use minitest, minitest/spec or rspec. I recommend minitest/spec.
Specifics - what you will need
- A class called Point to represent a point on a plane (i.e. x and y coordinates, floats, representing meters from the origin)
- A class called Rectangnle that represents a rectangle with two points
- Rectangle#area (in square meters)
- A class called Trangle that represents a triange with three points.
- Triangle#area (in square meters)
- A class called Circle that represents a circle by a point and a radius (float)
- Circle#area (in square meters)
- A class called Scene that represents a scene consisting of one or more rectangles, circles and triangles.
- Scene#shape_count (how many shapes there are)
- Scene#total_area (sum of all the areas even if they overlap; don’t worry about computing intersections.)
- Scene#add_shape (adds a shape to the scene)
- Scene#remove_shape (removes a shape from the scene)
If you want to go further
If you want to push yourself add some more methods by writing a test, and then implementing them. For example, Scene#copy_shape, Shape#resize_rectangle, Shape#is_square?, Line.new(point, point), Rectangle(point, point), Line#paralel(Line), are possible ways to go further.