Skip to content

Commit ad829a9

Browse files
authored
Merge pull request #27 from jsacerot/main
Adding the groom function and its respective test
2 parents 8ab0bb9 + 6e8d7c2 commit ad829a9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

pyCatSim/api/cat.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ def play(self, mood_boost=1, hunger_boost=1, energy_boost=-1):
211211
self.mood += mood_boost
212212
self.hunger_level += hunger_boost
213213
self.energy += energy_boost
214+
215+
def groom(self):
216+
217+
"""
218+
Grooms a cat, increasing its health and mood levels by one unit.
219+
220+
221+
Examples
222+
--------
223+
224+
.. jupyter-execute::
225+
226+
import pyCatSim as cats
227+
nutmeg = cats.Cat(name = 'Nutmeg', age = 3, color = 'tortoiseshell')
228+
nutmeg.groom()
229+
230+
231+
"""
232+
self.mood += 1
233+
self.health += 1
234+
print(f"{self.name} has been groomed. Health: {self.health}, Mood: {self.mood}")
214235

215236
def eat(self):
216237
"""
@@ -363,4 +384,4 @@ def remove_cat(self,cat):
363384
try:
364385
self.catlist.remove(cat)
365386
except ValueError:
366-
raise ValueError("Cat not found in Clowder")
387+
raise ValueError("Cat not found in Clowder")

pyCatSim/tests/test_api_Cat.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ def test_play_t0(self):
8989

9090
assert cat.mood == 3
9191
assert cat.hunger_level == 0
92+
assert cat.energy == 1
93+
94+
class TestcatCatGroom:
95+
''' Test for the groom function'''
96+
97+
def test_groom_t0(self):
98+
cat=Cat(name="Boots", age=2, color="tabby", mood=2, hunger_level=-1,
99+
energy = 2, health = 3)
100+
101+
cat.groom()
102+
103+
assert cat.health == 4
104+
assert cat.mood == 3
92105
assert cat.energy == 1
93106

94107
class TestcatCatEat:

0 commit comments

Comments
 (0)