Skip to content

Commit b314bd3

Browse files
authored
Merge pull request #32 from bosup/main
issue #9 enhancement - add give_fact attribute
2 parents 4f421cd + a5c764d commit b314bd3

6 files changed

Lines changed: 123 additions & 4 deletions

File tree

pyCatSim/api/cat.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
from ..utils import noises
9+
from ..utils import facts
910

1011
import difflib
1112

@@ -60,6 +61,24 @@ class Cat:
6061
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
6162
6263
"""
64+
65+
def give_fact(self):
66+
"""
67+
calls ..utils.random_facts() and return a random fact about cats
68+
69+
Returns
70+
-------
71+
str
72+
A fact randomly chosen from a pre-defined fact pool
73+
--------
74+
75+
.. jupyter-execute::
76+
77+
import pyCatSim as cats
78+
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
79+
nutmeg.give_fact()
80+
"""
81+
return facts.random_facts()
6382

6483
def __init__(self, name, age=None, color=None, mood=0, hunger_level=0,
6584
energy=0, health=0):
@@ -191,4 +210,4 @@ def play(self, mood_boost=1, hunger_boost=1, energy_boost=-1):
191210
self.mood += mood_boost
192211
self.hunger_level += hunger_boost
193212
self.energy += energy_boost
194-
213+

pyCatSim/api/human.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
from ..api.cat import Cat
8+
from ..utils import facts
89

910
class Owner:
1011
"""
@@ -48,6 +49,27 @@ class Owner:
4849
print([cat.name for cat in owner2.cats_owned])
4950
5051
"""
52+
53+
def give_fact(self):
54+
"""
55+
calls ..utils.random_facts() and return a random fact about cats
56+
57+
Returns
58+
-------
59+
str
60+
A fact randomly chosen from a pre-defined fact pool
61+
62+
Examples
63+
--------
64+
65+
.. jupyter-execute::
66+
67+
import pyCatSim as cats
68+
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
69+
nutmeg.give_fact()
70+
"""
71+
return facts.random_facts()
72+
5173
def __init__(self, name, cats_owned):
5274

5375
if isinstance(cats_owned, Cat):

pyCatSim/tests/test_api_Cat.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,31 @@ def test_play_t0(self):
8989

9090
assert cat.mood == 3
9191
assert cat.hunger_level == 0
92-
assert cat.energy == 1
92+
assert cat.energy == 1
93+
94+
95+
class TestcatCatFact:
96+
''' Test for the give_fact function'''
97+
98+
def test_give_fact_t0(self):
99+
cat=Cat(name="Boots", age=2, color="tabby", mood=2, hunger_level=-1,
100+
energy = 2, health = 3)
101+
102+
cat.give_fact()
103+
104+
assert cat.give_fact() in [
105+
"Cats sleep for 70% of their lives.",
106+
"A group of cats is called a clowder.",
107+
"Cats can rotate their ears 180 degrees.",
108+
"The world's oldest cat lived to be 38 years old.",
109+
"Cats have five toes on their front paws, but only four on the back.",
110+
"A cat can jump up to six times its length.",
111+
"Each cat's nose print is unique, like a human fingerprint.",
112+
"Cats use their whiskers to detect changes in their surroundings.",
113+
"The average house cat can run at speeds up to 30 mph.",
114+
"Cats meow only to communicate with humans."
115+
]
116+
117+
118+
119+

pyCatSim/tests/test_api_Owner.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ def test_init_t1(self):
4343
assert len(owner1.cats_owned) == 2
4444

4545

46+
class TesthumanOwnerFact:
47+
''' Test for the give_fact function'''
48+
49+
def test_give_fact_t0(self):
50+
cat1 = Cat(name="Whiskers")
51+
owner1 = Owner(name="Sasha", cats_owned=cat1)
52+
53+
owner1.give_fact()
54+
55+
4656
class TesthumanOwnerAdopt:
4757
def test_adopt_t0(self):
4858

@@ -73,4 +83,4 @@ def test_groom_t0(self):
7383
assert cat1.mood == 8
7484

7585

76-
86+

pyCatSim/utils/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
Contains all basic block functions for pyCatSim.
55
"""
66

7-
from .noises import *
7+
from .noises import *
8+
from .facts import *

pyCatSim/utils/facts.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# __all__=['random_facts']
3+
4+
import random
5+
6+
def random_facts():
7+
"""
8+
calls up random facts about cats
9+
10+
Returns
11+
-------
12+
str
13+
A fact randomly chosen from a pre-defined fact pool
14+
15+
Examples
16+
--------
17+
18+
.. jupyter-execute::
19+
20+
import pyCatSim as cats
21+
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
22+
nutmeg.give_fact()
23+
24+
"""
25+
26+
cat_facts = [
27+
"Cats sleep for 70% of their lives.",
28+
"A group of cats is called a clowder.",
29+
"Cats can rotate their ears 180 degrees.",
30+
"The world's oldest cat lived to be 38 years old.",
31+
"Cats have five toes on their front paws, but only four on the back.",
32+
"A cat can jump up to six times its length.",
33+
"Each cat's nose print is unique, like a human fingerprint.",
34+
"Cats use their whiskers to detect changes in their surroundings.",
35+
"The average house cat can run at speeds up to 30 mph.",
36+
"Cats meow only to communicate with humans."
37+
]
38+
return random.choice(cat_facts)
39+
40+

0 commit comments

Comments
 (0)