Skip to content

Commit 70540b3

Browse files
authored
Merge pull request #28 from Duyi-Li/bathe-feature
Add bathe method to Cat class
2 parents a53fb85 + e199679 commit 70540b3

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/pyCatSim/__pycache__
33
/pyCatSim/api/__pycache__
44
**/__pycache__
5-
./docs/_build/**
5+
./docs/_build/**

pyCatSim/api/cat.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,32 @@ def play(self, mood_boost=1, hunger_boost=1, energy_boost=-1):
213213
self.mood += mood_boost
214214
self.hunger_level += hunger_boost
215215
self.energy += energy_boost
216+
217+
def bathe(self):
218+
"""
219+
Bathes the cat, decreasing mood and improving health.
220+
221+
Cats typically dislike baths, which lowers their mood,
222+
but it improves their cleanliness and boosts health.
223+
224+
Effects
225+
-------
226+
- mood: decreases by 1
227+
- health: increases by 1
228+
229+
Examples
230+
--------
231+
.. jupyter-execute::
232+
233+
import pyCatSim as cats
234+
mochi = cats.Cat(name='Mochi', mood=3, health=5)
235+
mochi.bathe()
236+
print(mochi.mood) # Output: 2
237+
print(mochi.health) # Output: 6
238+
"""
239+
self.mood -= 1
240+
self.health += 1
241+
216242

217243
def show(self):
218244
"""
@@ -231,11 +257,7 @@ def show(self):
231257
except:
232258
color = random.choice(possible_colors)
233259
display.show(color)
234-
235-
236-
237-
238-
260+
239261

240262
def groom(self):
241263

pyCatSim/tests/test_api_Cat.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ def test_play_t0(self):
9292
assert cat.hunger_level == 0
9393
assert cat.energy == 1
9494

95+
class TestcatCatBathe:
96+
''' Test for the bathe function '''
97+
98+
def test_bathe_t0(self):
99+
cat = Cat(name="Boots", mood=2, health=4)
100+
cat.bathe()
101+
assert cat.mood == 1
102+
assert cat.health == 5
103+
95104

96105
class TestcatCatShow:
97106
''' Tests for the Cat.show() method '''
@@ -192,4 +201,3 @@ def test_give_fact_t0(self):
192201
"The average house cat can run at speeds up to 30 mph.",
193202
"Cats meow only to communicate with humans."
194203
]
195-

0 commit comments

Comments
 (0)