General
Instructions
- Develop the following simple program using Test Driven Development
- Meaning, write the tests FIRST and then write the classes
- In other words, for example:
- Write a test that creates a new Rectangle without actually writing the Rectangle class
- That will fail, of course. Now, in a separate file, write the minimal amount to make that test pass. That would be a class called Rectangle, with no methods.
- Now in your test, create a Rectangle, and call a method on it, checking that it returns the right result.
- That will fail too. Go back to the class, and write the minimal code to make the test pass.
- Rinse and repeat.
- 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 Rectangle that represents a rectangle with two points
- Rectangle#area (in square meters)
- A class called Triangle 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.