Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This is why it is important to maintain the code and clean up after yourself (an


## What you need
- Java 17 or .Net 7 (will work just fine with .Net 6 too)
- Java 17, .Net 7 (will work just fine with .Net 6 too), or Python
- Git
- Intellij or Visual Studio Code
- Intellij, PyCharm, or Visual Studio Code


# The mission
Expand All @@ -28,7 +28,7 @@ We recommend working together in small groups of around 3 people. While there ar
isn't to actually implement them, but to get the code ready to implement them. Even though some details are missing,
Tina has lined up some upcoming features and real life constraints. Each group gets one feature and one restraint.

There are two implementations, one in Java and one in C#. They both have the same test suite and perform the exact same task.
There are three implementations, in Java, in C#, and in Python. They have the same test suite and perform the exact same task.
Pick the one you (and your team) feel most comfortable with.


Expand Down
Empty file added python/pub/__init__.py
Empty file.
56 changes: 56 additions & 0 deletions python/pub/pub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ONE_BEER = "hansa"
ONE_CIDER = "grans"
A_PROPER_CIDER = "strongbow"
GT = "gt"
BACARDI_SPECIAL = "bacardi_special"


def compute_cost(drink: str, is_student: bool, amount: int):
if amount > 2 and (drink == GT or drink == BACARDI_SPECIAL):
raise ValueError('Too many drinks, max 2.')
price = 0
if drink == ONE_BEER:
price = 74
elif drink == ONE_CIDER:
price = 103
elif drink == A_PROPER_CIDER:
price = 110
elif drink == GT:
price = ingredient6() + ingredient5() + ingredient4()
elif drink == BACARDI_SPECIAL:
price = ingredient6() / 2 + ingredient1() + ingredient2() + ingredient3()
else:
raise ValueError('No such drink exists')
if is_student and (drink == ONE_CIDER or drink == ONE_BEER or drink == A_PROPER_CIDER):
price = price - price / 10
return price * amount


# One unit of rum
def ingredient1():
return 65


# One unit of grenadine
def ingredient2():
return 10


# One unit of juice
def ingredient3():
return 10


# One unit of green stuff
def ingredient4():
return 10


# One unit of tonic water
def ingredient5():
return 20


# One unit of gin
def ingredient6():
return 85
57 changes: 57 additions & 0 deletions python/pub/test_pub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pytest as pytest

from python.pub import pub


def test_one_beer_costs_74():
price = pub.compute_cost(pub.ONE_BEER, False, 1)
assert price == 74


def test_one_cider_costs_103():
price = pub.compute_cost(pub.ONE_CIDER, False, 1)
assert price == 103


def test_one_proper_cider_costs_110():
price = pub.compute_cost(pub.A_PROPER_CIDER, False, 1)
assert price == 110


def test_gin_and_tonic_costs_115():
price = pub.compute_cost(pub.GT, False, 1)
assert price == 115


def test_bacardi_special_costs_127():
price = pub.compute_cost(pub.BACARDI_SPECIAL, False, 1)
assert price == 127.5


def test_one_beer_costs_students_67():
price = pub.compute_cost(pub.ONE_BEER, True, 1)
assert price == 66.6


def test_multiple_beers_gives_students_discounts():
price = pub.compute_cost(pub.ONE_BEER, True, 2)
assert price == 66.6 * 2


def test_students_do_not_get_discounts_on_cocktails():
price = pub.compute_cost(pub.GT, True, 1)
assert price == 115


def test_ordering_off_menu_throws_error():
with pytest.raises(ValueError):
pub.compute_cost('San Francisco Sling', False, 1)


def test_cannot_order_three_cocktails():
with pytest.raises(ValueError):
pub.compute_cost(pub.BACARDI_SPECIAL, False, 3)


def test_can_order_more_than_two_beers():
pub.compute_cost(pub.ONE_BEER, False, 5)
1 change: 1 addition & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest