Skip to content

Commit 6717c30

Browse files
committed
ejemplo en python
No me esforcé mucho en aplicar TDD. De hecho apliqué el método Obvious Implementation a full. A si que cabe aclarar que no le dediqué mucho tiempo al ejercicio, pero haré igual la PR por si a alguien le sirve el ejemplo en python Pero sí el ejercicio me sirvió para empezar, de partida a generar el setup para un proyecto con test en python y tambien a hacer mis primeros test en Python :raising_hands: Muchas gracias.
1 parent 3be68c0 commit 6717c30

File tree

8 files changed

+310
-0
lines changed

8 files changed

+310
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110+
.pdm.toml
111+
.pdm-python
112+
.pdm-build/
113+
114+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115+
__pypackages__/
116+
117+
# Celery stuff
118+
celerybeat-schedule
119+
celerybeat.pid
120+
121+
# SageMath parsed files
122+
*.sage.py
123+
124+
# Environments
125+
.env
126+
.venv
127+
env/
128+
venv/
129+
ENV/
130+
env.bak/
131+
venv.bak/
132+
133+
# Spyder project settings
134+
.spyderproject
135+
.spyproject
136+
137+
# Rope project settings
138+
.ropeproject
139+
140+
# mkdocs documentation
141+
/site
142+
143+
# mypy
144+
.mypy_cache/
145+
.dmypy.json
146+
dmypy.json
147+
148+
# Pyre type checker
149+
.pyre/
150+
151+
# pytype static type analyzer
152+
.pytype/
153+
154+
# Cython debug symbols
155+
cython_debug/
156+
157+
# PyCharm
158+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160+
# and can be added to the global gitignore or merged into this file. For a more nuclear
161+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162+
#.idea/

exercises/tiered_pricing/solutions/elwazy-python/README.md

Whitespace-only changes.

exercises/tiered_pricing/solutions/elwazy-python/elwazy_python/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class License:
6+
amount: int = 0
7+
8+
def total(self) -> int:
9+
price = self.amount * self._price_calculator()
10+
return price
11+
12+
def _price_calculator(self) -> int:
13+
match self.amount:
14+
case self.amount if self.amount <= 0:
15+
raise Exception("should be minimun 1 license!")
16+
case self.amount if self.amount <= 2:
17+
price = 299
18+
case self.amount if self.amount <= 10:
19+
price = 239
20+
case self.amount if self.amount <= 25:
21+
price = 219
22+
case self.amount if self.amount <= 50:
23+
price = 199
24+
case _:
25+
price = 149
26+
return price

exercises/tiered_pricing/solutions/elwazy-python/poetry.lock

+74
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[tool.poetry]
2+
name = "elwazy-python"
3+
version = "0.1.0"
4+
description = "Tiered Pricing Exercise with TDD"
5+
authors = ["ElWazy"]
6+
readme = "README.md"
7+
package-mode = false
8+
9+
[tool.poetry.dependencies]
10+
python = "^3.12"
11+
12+
[tool.poetry.group.test.dependencies]
13+
pytest = "^8.2.2"
14+
15+
[build-system]
16+
requires = ["poetry-core"]
17+
build-backend = "poetry.core.masonry.api"

exercises/tiered_pricing/solutions/elwazy-python/tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import reveal_type
2+
from elwazy_python.license import License
3+
4+
5+
def test_buy_one_license_price_calculation():
6+
license = License(amount=1)
7+
assert license.total() == 299
8+
9+
10+
def test_buy_two_license_price_calculation():
11+
license = License(amount=2)
12+
assert license._price_calculator() == 299
13+
assert license.total() == 598
14+
15+
16+
def test_should_work_well_license_price_calculation():
17+
amounts = [
18+
(1, 299),
19+
(2, 299),
20+
(3, 239),
21+
(5, 239),
22+
(10, 239),
23+
(12, 219),
24+
(24, 219),
25+
(25, 219),
26+
(50, 199),
27+
(78, 149),
28+
]
29+
for amount, price in amounts:
30+
license = License(amount)
31+
assert license._price_calculator() == price

0 commit comments

Comments
 (0)