Skip to content

Commit 12638a2

Browse files
authored
silly python function and test (#13)
2 parents b8065fb + a0b1b23 commit 12638a2

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from .ned import fizzbuzz as fizzbuzz
2+
3+
from .selina import get_interesting_fact as get_interesting_fact
24
from .harvir import silly_addition as silly_addition
3-
from .edwin import simple_subtraction as simple_subtraction
5+
from .edwin import simple_subtraction as simple_subtraction
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def get_interesting_fact(category):
2+
facts = {
3+
"science": "Honey never spoils. Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible.",
4+
"history": "The shortest war in history lasted only 38 minutes. It was between Britain and Zanzibar on August 27, 1896.",
5+
"animals": "Penguins only have one mate their entire life. They also propose to their lifemates with a pebble.",
6+
"technology": "The first computer virus was created in 1983 and was called the 'Elk Cloner'. It infected Apple II computers via floppy disks."
7+
}
8+
9+
category_lower = category.lower()
10+
if category_lower in facts:
11+
return facts[category_lower]
12+
else:
13+
return "Sorry, I don't have an interesting fact for that category."
14+
15+
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from selfie_lib import get_interesting_fact
2+
3+
def test_science_fact():
4+
fact = get_interesting_fact("science")
5+
assert fact == "Honey never spoils. Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible."
6+
7+
def test_history_fact():
8+
fact = get_interesting_fact("history")
9+
assert fact == "The shortest war in history lasted only 38 minutes. It was between Britain and Zanzibar on August 27, 1896."
10+
11+
def test_animals_fact():
12+
fact = get_interesting_fact("animals")
13+
assert fact == "Penguins only have one mate their entire life. They also propose to their lifemates with a pebble."
14+
15+
def test_technology_fact():
16+
fact = get_interesting_fact("technology")
17+
assert fact == "The first computer virus was created in 1983 and was called the 'Elk Cloner'. It infected Apple II computers via floppy disks."
18+
19+
def test_invalid_category():
20+
fact = get_interesting_fact("invalid")
21+
assert fact == "Sorry, I don't have an interesting fact for that category."

0 commit comments

Comments
 (0)