Using pair test-driven development with RSpec, create the following classes:
- Has a title, list of artists (order doesn't matter), duration, and price
- Has a "set discount" method that reduces the price by a given percentage
- Has a "reset discount" method that restores the price to its original value
Note: The "set discount" method should not return a discounted price – it should actually change the price of the track. If I create a track with price 1.0
and I call track.set_discount(0.2)
, subsequent calls to track.price
should now return 0.8
. If I apply another discount, it should replace the previous discount rather than stacking onto it.
- Has a title and a list of
Track
objects (order matters) - Has a duration (combined duration of all tracks)
- Has a price (combined price of all tracks)
- Has a list of artists (combined artists of all tracks in alphabetical order – no duplicates)
- Can determine whether the album is a single (has exactly one track)
Still using test-driven development, add some data validation to these classes. For instance, I probably shouldn't be able to create an album with no tracks, or set a track's discount greater than 100%. Think of ways someone could abuse your code – what happens if I try to create a track with the "list of artists" set to 42
? Generally it's appropriate to raise ArgumentError
when your methods receive invalid data as an argument.