Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
silly python function and test (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Feb 23, 2024
2 parents b8065fb + a0b1b23 commit 12638a2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python/selfie-lib/selfie_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .ned import fizzbuzz as fizzbuzz

from .selina import get_interesting_fact as get_interesting_fact
from .harvir import silly_addition as silly_addition
from .edwin import simple_subtraction as simple_subtraction
from .edwin import simple_subtraction as simple_subtraction
15 changes: 15 additions & 0 deletions python/selfie-lib/selfie_lib/selina.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def get_interesting_fact(category):
facts = {
"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.",
"history": "The shortest war in history lasted only 38 minutes. It was between Britain and Zanzibar on August 27, 1896.",
"animals": "Penguins only have one mate their entire life. They also propose to their lifemates with a pebble.",
"technology": "The first computer virus was created in 1983 and was called the 'Elk Cloner'. It infected Apple II computers via floppy disks."
}

category_lower = category.lower()
if category_lower in facts:
return facts[category_lower]
else:
return "Sorry, I don't have an interesting fact for that category."


21 changes: 21 additions & 0 deletions python/selfie-lib/tests/selina_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from selfie_lib import get_interesting_fact

def test_science_fact():
fact = get_interesting_fact("science")
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."

def test_history_fact():
fact = get_interesting_fact("history")
assert fact == "The shortest war in history lasted only 38 minutes. It was between Britain and Zanzibar on August 27, 1896."

def test_animals_fact():
fact = get_interesting_fact("animals")
assert fact == "Penguins only have one mate their entire life. They also propose to their lifemates with a pebble."

def test_technology_fact():
fact = get_interesting_fact("technology")
assert fact == "The first computer virus was created in 1983 and was called the 'Elk Cloner'. It infected Apple II computers via floppy disks."

def test_invalid_category():
fact = get_interesting_fact("invalid")
assert fact == "Sorry, I don't have an interesting fact for that category."

0 comments on commit 12638a2

Please sign in to comment.