Skip to content

Commit 1928b70

Browse files
committed
Update to panda/eagle/tiger
1 parent 74ff0be commit 1928b70

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

README.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@ Episode 1 - Lions, Pandas and Zookeepers
33

44
An accurate simulation of zookeepers feeding Lions and Pandas
55

6-
Your Assignment
6+
Panda Level
77
---------------
88

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

12-
Extra Credit
13-
------------
14-
15-
1. Extract `Food` into a class, rather than a symbol
16-
2. Create a FoodBarge that can be called like:
12+
Tiger Level
13+
---------------
14+
1. Create a FoodBarge that can be called like:
15+
2. Test that when the zookeepers gets food for the panda,
16+
the panda will eat it
1717

1818
```
19-
food = @foodbarge.food_for(panda)
19+
food = foodbarge.food_for(panda)
2020
panda.feed(food)
2121
```
2222

23+
Eagle Level
24+
----------
25+
26+
1. Extract `Food` into a class, rather than a symbol
27+
2. Create separate Tacos, Wildebeests, etc classes for each food
28+
2. Rather than comparing Tacos.new, implement the `==` method so you can do `Tacos.new == Tacos.new`
29+
2330
Copyright: Jesse Wolgamott, MIT License (See LICENSE)

zoo.rb

+17-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def eat(food)
1313
end
1414

1515
def likes?(food)
16-
acceptable_food.include?(food.to_sym)
16+
acceptable_food.include?(food)
1717
end
1818

1919
def acceptable_food
@@ -31,7 +31,7 @@ class Panda
3131
include Animal
3232

3333
def acceptable_food
34-
[:bamboo]
34+
[Bamboo.new]
3535
end
3636

3737
def full?
@@ -44,14 +44,28 @@ class Lion
4444
include Animal
4545

4646
def acceptable_food
47-
[:wildebeests, :zeebras]
47+
[Wildebeests.new, Zeebras.new]
4848
end
4949

5050
def full?
5151
@meals > 10
5252
end
5353
end
5454

55+
56+
class Food
57+
58+
def ==(other)
59+
other.is_a? self.class
60+
end
61+
62+
end
63+
64+
class Tacos < Food; end
65+
class Wildebeests < Food; end
66+
class Zeebras < Food; end
67+
class Bamboo < Food; end
68+
5569
class Zookeeper
5670
def feed(args={})
5771
food = args.fetch(:food)

zoo_spec.rb

+19-14
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,66 @@
22
require "./zoo"
33
require "rspec"
44

5-
describe Panda do
5+
class Grasshoppers < Food; end
6+
class Salad < Food; end
67

7-
it "should like bamboo" do
8-
Panda.new.likes?(:bamboo).should eq(true)
8+
describe Tacos do
9+
it "should know all tacos are equal" do
10+
(Tacos.new == Tacos.new).should be_true
911
end
12+
end
1013

11-
it "should like bamboo as a string" do
12-
Panda.new.likes?("bamboo").should eq(true)
14+
describe Panda do
15+
16+
it "should like bamboo" do
17+
Panda.new.likes?(Bamboo.new).should eq(true)
1318
end
1419

1520
it "should not like grasshoppers" do
16-
Panda.new.likes?(:grasshoppers).should eq(false)
21+
Panda.new.likes?(Grasshoppers.new).should eq(false)
1722
end
1823

1924
it "should be able to eat the food" do
20-
Panda.new.eat(:bamboo).should be_true
25+
Panda.new.eat(Bamboo.new).should be_true
2126
end
2227

2328
it "should be full after eating 30 bamboo" do
2429
panda = Panda.new
2530
31.times do
26-
panda.eat(:bamboo)
31+
panda.eat(Bamboo.new)
2732
end
2833
panda.should be_full
2934
end
3035

3136
it "should not be full after 1" do
3237
panda = Panda.new
33-
panda.eat(:bamboo)
38+
panda.eat(Bamboo.new)
3439
panda.should_not be_full
3540
end
3641
end
3742

3843
describe Lion do
3944
it "should like wildebeests" do
40-
Lion.new.likes?(:wildebeests).should eq(true)
45+
Lion.new.likes?(Wildebeests.new).should eq(true)
4146
end
4247

4348
it "should like zeebras" do
44-
Lion.new.likes?(:zeebras).should eq(true)
49+
Lion.new.likes?(Zeebras.new).should eq(true)
4550
end
4651

4752
it "should not like salad" do
48-
Lion.new.likes?(:salad).should eq(false)
53+
Lion.new.likes?(Salad.new).should eq(false)
4954
end
5055

5156
it "should take 11 meals to be full" do
5257
lion = Lion.new
53-
lion.eat(:zeebras)
58+
lion.eat(Zeebras.new)
5459
lion.should_not be_full
5560
end
5661
it "should take 11 meals to be full" do
5762
lion = Lion.new
5863
11.times do
59-
lion.eat(:zeebras)
64+
lion.eat(Zeebras.new)
6065
end
6166
lion.should be_full
6267
end

0 commit comments

Comments
 (0)