Skip to content

Commit

Permalink
Update to panda/eagle/tiger
Browse files Browse the repository at this point in the history
  • Loading branch information
jwo committed May 6, 2012
1 parent 74ff0be commit 1928b70
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
21 changes: 14 additions & 7 deletions README.md
Expand Up @@ -3,21 +3,28 @@ Episode 1 - Lions, Pandas and Zookeepers

An accurate simulation of zookeepers feeding Lions and Pandas

Your Assignment
Panda Level
---------------

1. Create a human that likes bacon and tacos, but not bamboo
2. (Using TDD [write tests first])

Extra Credit
------------

1. Extract `Food` into a class, rather than a symbol
2. Create a FoodBarge that can be called like:
Tiger Level
---------------
1. Create a FoodBarge that can be called like:
2. Test that when the zookeepers gets food for the panda,
the panda will eat it

```
food = @foodbarge.food_for(panda)
food = foodbarge.food_for(panda)
panda.feed(food)
```

Eagle Level
----------

1. Extract `Food` into a class, rather than a symbol
2. Create separate Tacos, Wildebeests, etc classes for each food
2. Rather than comparing Tacos.new, implement the `==` method so you can do `Tacos.new == Tacos.new`

Copyright: Jesse Wolgamott, MIT License (See LICENSE)
20 changes: 17 additions & 3 deletions zoo.rb
Expand Up @@ -13,7 +13,7 @@ def eat(food)
end

def likes?(food)
acceptable_food.include?(food.to_sym)
acceptable_food.include?(food)
end

def acceptable_food
Expand All @@ -31,7 +31,7 @@ class Panda
include Animal

def acceptable_food
[:bamboo]
[Bamboo.new]
end

def full?
Expand All @@ -44,14 +44,28 @@ class Lion
include Animal

def acceptable_food
[:wildebeests, :zeebras]
[Wildebeests.new, Zeebras.new]
end

def full?
@meals > 10
end
end


class Food

def ==(other)
other.is_a? self.class
end

end

class Tacos < Food; end
class Wildebeests < Food; end
class Zeebras < Food; end
class Bamboo < Food; end

class Zookeeper
def feed(args={})
food = args.fetch(:food)
Expand Down
33 changes: 19 additions & 14 deletions zoo_spec.rb
Expand Up @@ -2,61 +2,66 @@
require "./zoo"
require "rspec"

describe Panda do
class Grasshoppers < Food; end
class Salad < Food; end

it "should like bamboo" do
Panda.new.likes?(:bamboo).should eq(true)
describe Tacos do
it "should know all tacos are equal" do
(Tacos.new == Tacos.new).should be_true
end
end

it "should like bamboo as a string" do
Panda.new.likes?("bamboo").should eq(true)
describe Panda do

it "should like bamboo" do
Panda.new.likes?(Bamboo.new).should eq(true)
end

it "should not like grasshoppers" do
Panda.new.likes?(:grasshoppers).should eq(false)
Panda.new.likes?(Grasshoppers.new).should eq(false)
end

it "should be able to eat the food" do
Panda.new.eat(:bamboo).should be_true
Panda.new.eat(Bamboo.new).should be_true
end

it "should be full after eating 30 bamboo" do
panda = Panda.new
31.times do
panda.eat(:bamboo)
panda.eat(Bamboo.new)
end
panda.should be_full
end

it "should not be full after 1" do
panda = Panda.new
panda.eat(:bamboo)
panda.eat(Bamboo.new)
panda.should_not be_full
end
end

describe Lion do
it "should like wildebeests" do
Lion.new.likes?(:wildebeests).should eq(true)
Lion.new.likes?(Wildebeests.new).should eq(true)
end

it "should like zeebras" do
Lion.new.likes?(:zeebras).should eq(true)
Lion.new.likes?(Zeebras.new).should eq(true)
end

it "should not like salad" do
Lion.new.likes?(:salad).should eq(false)
Lion.new.likes?(Salad.new).should eq(false)
end

it "should take 11 meals to be full" do
lion = Lion.new
lion.eat(:zeebras)
lion.eat(Zeebras.new)
lion.should_not be_full
end
it "should take 11 meals to be full" do
lion = Lion.new
11.times do
lion.eat(:zeebras)
lion.eat(Zeebras.new)
end
lion.should be_full
end
Expand Down

0 comments on commit 1928b70

Please sign in to comment.