|
require './app' |
|
|
|
def assert(expression,message) |
|
raise message unless expression |
|
end |
|
|
|
recipes = [] |
|
# write the code to parse 'recipes.csv' and populate the recipes array here |
|
|
|
cc_recipe = recipes[0] |
|
assert(cc_recipe[:name] == "chocolate chip", "cc_recipe name should be chocolate chip") |
|
|
|
pb_recipe = recipes[1] |
|
assert(pb_recipe[:bake_time].class == Fixnum, "bake time should be a number type") |
|
assert(pb_recipe[:bake_time] == 12, "pb_recipe bake time should be 12") |
|
|
|
snick_recipe = recipes[2] |
|
assert(snick_recipe[:bake_temp].class == Fixnum, "bake temp should be a number type") |
|
assert(snick_recipe[:bake_temp] == 350, "snick_recipe bake time should be 350") |
|
|
|
tg_recipe = recipes[3] |
|
assert(tg_recipe[:batch_yield].class == Fixnum, "batch yield should be a number type") |
|
assert(tg_recipe[:batch_yield] == 100, "tg_recipe batch yield should be 100") |
|
|
|
chocolate_chip = Cookie.new(cc_recipe) |
|
assert(chocolate_chip.class == Cookie, "chocolate_chip should be an instance of Cookie") |
|
assert(chocolate_chip.name == "chocolate chip", "cookie name should be 'chocolate chip'") |
|
assert(chocolate_chip.bake_time == 14, "cookie bake time should be 14") |
|
assert(chocolate_chip.bake_temp == 350, "cookie bake temp should be 350") |
|
assert(chocolate_chip.batch_yield == 15, "cookie batch yield should be 15") |
|
assert(chocolate_chip.time_in_oven == 0, "cookie should initialize with a time in oven at 0") |
|
assert(chocolate_chip.status == :doughy, "cookie status should initialize as :doughy") |
|
assert(chocolate_chip.food_category == :cookies, "chocolate chip cookies should have a food category of :cookies") |
|
|
|
bertha = Oven.new |
|
assert(bertha.class == Oven, "bertha should be an instance of Oven") |
|
assert(bertha.temp == 0, "oven should initialize with a temperature of 0") |
|
assert(bertha.contents == [], "oven contents should initialize as an empty collection") |
|
assert(bertha.baking_time == 0, "oven should initialize with baking time at 0") |
|
|
|
name = ["Thomas", "Ryan", "Alek", "Salar", "Taylor", "Cricket", "Brantley", "Marion", "Dan", "Brandon", "Kenneth", "Annie", "Carter", "Natalie", "Jonathan", "Laura", "Steven", "Jenny", "Paul", "Jeff", "Charles"].shuffle.pop |
|
baker = Baker.new(name) |
|
assert(baker.class == Baker, "baker should be an instance of Baker") |
|
assert(baker.name == name, "baker's name should be #{name}") |
|
assert(baker.batches == [], "baker should start with an empty collection of cookie batches") |
|
assert(baker.inventory == {}, "baker should start with an empty inventory") |
|
|
|
baker.make_batch(cc_recipe) |
|
assert(baker.batches.count == 1, "batches should contain 1 batch of cookies") |
|
assert(baker.batches.first.count == 15, "batches should contain 1 batch of 15 cookies") |
|
assert(baker.batches.first[0].name == "chocolate chip", "the cookies in the first batch should be chocolate chip") |
|
|
|
baker.put_food_in_oven(bertha, baker.batches[0]) |
|
assert(bertha.contents == [], "food should not be inserted into the oven unless the oven is set to the food's bake temp") |
|
|
|
baker.set_oven(bertha, baker.batches.first[0].bake_temp) |
|
assert(bertha.temp == 350, "oven temperature should be set to 350") |
|
|
|
baker.put_food_in_oven(bertha, baker.batches[0]) |
|
assert(bertha.contents.count == 1, "oven should contain first batch") |
|
assert(baker.batches == [], "baker should no longer have any batches after putting food in oven") |
|
|
|
bertha.bake! |
|
assert(bertha.baking_time == 1, "oven baking time should be 1") |
|
bertha.bake!(10) |
|
assert(bertha.baking_time == 11, "oven baking time should be 11") |
|
assert(bertha.contents[0][0].status == :almost_ready, "cookie status at 11 minutes should be :almost_ready") |
|
bertha.bake!(3) |
|
assert(bertha.food_ready? == true, "cookie status at #{bertha.contents[0][0].bake_time} should be :ready") |
|
|
|
baker.remove_food_from_oven(bertha, bertha.contents[0]) |
|
assert(bertha.contents == [], "oven should be empty after removing food") |
|
assert(bertha.baking_time == 0, "oven baking time should reset to 0 after removing food") |
|
assert(baker.inventory[:cookies]["chocolate chip"] == 15, "baker should now have 15 chocolate chip cookies") |
|
|
|
# ------- |
|
# STRETCH |
|
# ------- |
|
|
|
# PONDERINGS |
|
|
|
# why aren't there Batch and Recipe classes? when is a class really necessary? |
|
# nested hashes?! |
|
# apropos of nested hashes-- note the method Baker#put_food_in_oven, or Oven#food_ready?. What's the advantage of this method name over Baker#put_cookies_in_oven (or Oven#cookies_ready?)? |
|
|
|
# MOAR TESTS! uncomment to run. |
|
|
|
# baker.make_batch(tg_recipe) |
|
# baker.set_oven(bertha, baker.batches.first[0].bake_temp) |
|
# baker.put_food_in_oven(bertha, baker.batches[0]) |
|
# bertha.bake!(14) |
|
# assert(bertha.food_ready? == false, "teddy graham cookie status at 14 minutes should be :doughy") |
|
# bertha.bake!(16) |
|
# baker.remove_food_from_oven(bertha, bertha.contents[0]) |
|
# assert(baker.inventory[:cookies]["teddy grahams"] == 100, "baker should now have 100 teddy graham cookies") |
|
|
|
# baker.make_batch(pb_recipe) |
|
# baker.set_oven(bertha, baker.batches.first[0].bake_temp) |
|
# baker.put_food_in_oven(bertha, baker.batches[0]) |
|
# bertha.bake!(14) |
|
# baker.remove_food_from_oven(bertha, bertha.contents[0]) |
|
# assert(baker.inventory[:cookies]["peanut butter"] == nil, "inventory should only update if cookies have :ready status") |