Let's simulate a grocery store system! We want to be able to keep track of the orders that folks make, both online and physically in our grocery store.
This project will allow you to explore object-oriented design as well as a few other new topics. This is an individual, stage 1 project.
The project is due before class on Tuesday February 20th
You should demonstrate an ability to:
- Practice Test-Driven-Development
- Use instance variables and methods
- Reading from a CSV file
- Write DRY code by reusing methods
- Use inheritance to create a subclass
- Fork the project master.
- Clone the forked repo:
$ git clone [YOUR FORKED REPO URL]
cd
into the dir created$ cd grocery-store
- Run
git remote -v
to verify the folder you are in corresponds to the fork you have created.
If it is correct it will include your username If it is incorrect it will include "AdaGold" or "Ada-CX" - Run
gem install minitest-skip
to install an extra gem for testing (more on what this actually does later).
This is our first project with real tests! Following the instructions from the TDD lecture, there are three things in our project directory:
Rakefile
lib/
specs/
Each class you write (there will only be one until wave 3) should get its own file, lib/class_name.rb
. The specs for that class will be in specs/class_name_spec.rb
, and you can run all specs using the rake
command from your terminal.
- Create a class inside of a module
- Create methods inside the class to perform actions
- Learn how Ruby does error handling
- Verify code correctness by testing
For Wave 1, all tests have been provided for you. For each piece of functionality that you build, you should run the tests from the command line using the rake
command. To focus on only one test at a time, change all it
methods to xit
except for the one test you'd like to run. All tests provided should be passing at the end of your work on Wave 1.
Create a Grocery
module which will contain an Order
class and any future grocery store logic.
Create an Order
class which should have the following functionality:
- A new order should be created with:
- an ID, read-only
- a collection of products and their cost
- zero products is permitted
- you can assume that there is only one of each product
- A
total
method which will calculate the total cost of the order by:- summing up the products
- adding a 7.5% tax
- ensure the result is rounded to two decimal places
- An
add_product
method which will take in two parameters, product name and price, and add the data to the product collection- It should return
true
if the item was successfully added andfalse
if it was not
- It should return
Make sure to write tests for any optionals you implement!
- Add a
remove_product
method to theOrder
class which will take in one parameter, a product name, and remove the product from the collection- It should return
true
if the item was successfully remove andfalse
if it was not
- It should return
Check out the feedback template to see what instructors will be looking for.