-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Farzan's TakeAway Challenge 3/4 user stories #2241
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
# Your name | ||
|
||
Please write your full name here to make it easier to find your pull request. | ||
# Farzan Imanzadeh | ||
|
||
# User stories | ||
|
||
Please list which user stories you've implemented (delete the ones that don't apply). | ||
|
||
- [ ] User story 1: "I would like to see a list of dishes with prices" | ||
- [ ] User story 2: "I would like to be able to select some number of several available dishes" | ||
- [ ] User story 3: "I would like to check that the total I have been given matches the sum of the various dishes in my order" | ||
- [X] User story 1: "I would like to see a list of dishes with prices" | ||
- [X] User story 2: "I would like to be able to select some number of several available dishes" | ||
- [X] User story 3: "I would like to check that the total I have been given matches the sum of the various dishes in my order" | ||
- [ ] User story 4: "I would like to receive a text such as "Thank you! Your order was placed and will be delivered before 18:52" after I have ordered" | ||
|
||
# README checklist | ||
|
||
Does your README contains instructions for | ||
|
||
- [ ] how to install, | ||
- [ ] how to run, | ||
- [ ] and how to test your code? | ||
- [X] how to install, | ||
- [X] how to run, | ||
- [X] and how to test your code? | ||
|
||
[Here is a pill](https://github.com/makersacademy/course/blob/main/pills/readmes.md) that can help you write a great README! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Menu | ||
attr_reader :dishes | ||
|
||
def initialize | ||
@dishes = { | ||
"meatball sub" => 5, | ||
"steak n cheese sub" => 6, | ||
"low cal turkey sub" => 4 | ||
} | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Order | ||
attr_reader :basket | ||
|
||
def initialize | ||
@total = 0 | ||
@menu = Menu.new.dishes | ||
@basket = [] | ||
end | ||
|
||
def choose_dish(dish) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might need to include a way ask for more than one of each dish. A hash for @Basket could help on that |
||
@basket << dish | ||
end | ||
|
||
def total | ||
@menu.each do |dish, price| | ||
@basket.each do |selected_dish| | ||
@total += price if selected_dish == dish | ||
end | ||
end | ||
"Your basket's total is £#{@total}." | ||
end | ||
|
||
def check_basket | ||
@basket | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ViewMenu | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might have been a method inside Menu class? |
||
|
||
def initialize | ||
@menu = Menu.new.dishes | ||
end | ||
|
||
def list_of_dishes | ||
@menu.each do |dish, price| | ||
puts "#{dish}: £#{price}" | ||
end | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'menu' | ||
|
||
describe Menu do | ||
describe "#dishes" do | ||
it "contains a list of the dishes with prices" do | ||
menu = { | ||
"meatball sub" => 5, | ||
"steak n cheese sub" => 6, | ||
"low cal turkey sub" => 4 | ||
} | ||
expect(subject.dishes).to eq menu | ||
end | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'order' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All features seem to be tested thoroughly |
||
|
||
describe Order do | ||
describe "#select_dish" do | ||
it "selects a dish from the menu" do | ||
expect(subject).to respond_to(:choose_dish).with(1).argument | ||
end | ||
|
||
it "initializes with an empty order list" do | ||
expect(subject.basket).to be_empty | ||
end | ||
|
||
it "adds a dish to the basket" do | ||
subject.choose_dish("meatball sub") | ||
expect(subject.basket).to include "meatball sub" | ||
end | ||
end | ||
|
||
describe "#total" do | ||
it "calculates total sum of order" do | ||
subject.choose_dish("meatball sub") | ||
expect(subject.total).to eq "Your basket's total is £5." | ||
end | ||
end | ||
|
||
describe "#check_basket" do | ||
it "shows what's in the basket" do | ||
expect(subject.check_basket).to eq ([]) | ||
end | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'view_menu' | ||
|
||
describe ViewMenu do | ||
|
||
describe "#list_of_dishes" do | ||
it "provides a menu containing dishes and their prices" do | ||
menu = double(:menu) | ||
allow(menu).to receive(:dishes).and_return({ | ||
"meatball sub" => 5, | ||
"steak n cheese sub" => 6, | ||
"low cal turkey sub" => 4 | ||
}) | ||
expect(subject.list_of_dishes).to eq menu.dishes | ||
end | ||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name of variables are quite adequate and easy to understand what the code is trying to do